Skip to content

Instantly share code, notes, and snippets.

@mrkvm
Created October 21, 2012 22:49
Show Gist options
  • Save mrkvm/3928815 to your computer and use it in GitHub Desktop.
Save mrkvm/3928815 to your computer and use it in GitHub Desktop.
-- Set a key containing JSON in Redis
local key = KEYS[1];
local name = ARGV[1];
local value = ARGV[2];
local data = redis.call('GET', key);
local json;
if not data then
json = {};
else
json = cjson.decode(data);
end
json[name] = value;
redis.call('SET', key, cjson.encode(json));
return cjson.encode(json);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment