Created
November 13, 2013 23:12
-
-
Save fritzy/7458225 to your computer and use it in GitHub Desktop.
Update a key and lookup for a specific root level JSON attribute.
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
--EVAL "this script" 2 key lookup jsonvalue attribute | |
local key, lookup = unpack(KEYS); | |
local jsonvalue, attribute = unpack(ARGV); | |
local value = cjson.decode(jsonvalue); | |
local oldvalue = redis.call('GET', key); | |
--if this key was set before, remove the old lookup | |
if type(oldvalue) == 'string' then | |
oldvalue = cjson.decode(oldvalue); | |
redis.call('HDEL', lookup, oldvalue[attribute]); | |
end | |
redis.call('HSET', lookup, value[attribute], key); | |
return redis.call('SET', key, jsonvalue); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment