Skip to content

Instantly share code, notes, and snippets.

@richwednesday
Created September 21, 2018 13:27
Show Gist options
  • Save richwednesday/df3b2b0795e8ba1be88839cb1db49198 to your computer and use it in GitHub Desktop.
Save richwednesday/df3b2b0795e8ba1be88839cb1db49198 to your computer and use it in GitHub Desktop.
redis magic
overwrite(id, obj) {
client.del(`${id}-creation`, () => {
client.HMSET(`${id}-creation`, obj)
})
},
update(id, obj) {
client.HMSET(`${id}-creation`, obj)
},
get(id, cb) {
client.hgetall(`${id}-creation`, (err, obj) => {
if (err) console.log(err)
cb(obj || {})
})
},
modify(id, toSet, value, cb) {
client.hgetall(`${id}-creation`, (err, obj) => {
if (obj) {
obj[toSet] = value
} else {
obj = {};
obj[toSet] = value
}
this.update(id, obj)
if (cb) cb(obj)
})
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment