Created
September 21, 2018 13:27
-
-
Save richwednesday/df3b2b0795e8ba1be88839cb1db49198 to your computer and use it in GitHub Desktop.
redis magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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