Created
April 18, 2014 07:25
-
-
Save bcoe/11029265 to your computer and use it in GitHub Desktop.
Atomic update of JSON in Redis
This file contains 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
# atomic update of a key using LUA. | |
EVAL "local t1 = cjson.decode(redis.call('get', ARGV[1])); local t2 = cjson.decode(ARGV[2]); for k,v in pairs(t2) do t1[k] = v end; redis.call('set', ARGV[1], cjson.encode(t1))" 0 "foo" '{"bar": 3}' | |
local id = ARGV[1] | |
local t1 = cjson.decode(redis.call('get', id) | |
local t2 = cjson.decode(ARGV[2]) | |
# merge the new hash with the prior hash. | |
for k,v in pairs(t2) do t1[k] = v end | |
redis.call('set', id, cjson.encode(t1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment