Skip to content

Instantly share code, notes, and snippets.

@jorgeuriarte
Last active August 29, 2015 14:19
Show Gist options
  • Save jorgeuriarte/a4d941172d00c5064e2f to your computer and use it in GitHub Desktop.
Save jorgeuriarte/a4d941172d00c5064e2f to your computer and use it in GitHub Desktop.
La primera versión (la existente) hace que si un valor se queda "colgado", nunca se borre. ¿Qué problema tiene la segunda?
def updateSetContent(hashkey, userKey, hashvalue, user){
def options = this.questions[hashkey].options
def valuesArray = hashvalue.split(',')
options.each{ option ->
def existia = jedis.sismember(userKey, option.value)
def existe = valuesArray.find{ it == option.value }
//si el usuario la marco como respuesta, y no existia
if( existe && !existia ) {
jedis.sadd(userKey, option.value)
}
else if(!existe && existia) {
jedis.srem(userKey, option.value)
}
}
}
def updateSetContent(hashkey, userKey, hashvalue, user){
def options = this.questions[hashkey].options
def valuesArray = hashvalue.split(',')
jedis.del userKey
options.each{ option ->
def existe = valuesArray.find{ it == option.value }
if( existe )
jedis.sadd(userKey, option.value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment