Skip to content

Instantly share code, notes, and snippets.

@fritzy
Created November 6, 2013 17:35
Show Gist options
  • Save fritzy/7340641 to your computer and use it in GitHub Desktop.
Save fritzy/7340641 to your computer and use it in GitHub Desktop.
Redis scripts to set JSON in, store as MSGPack, and get JSON out.
--EVAL 'this script' 1 some-key
local key = KEYS[1];
local value = redis.call('GET', key);
local jvalue = cjson.encode(cmsgpack.unpack(value));
return jvalue;
--EVAL 'this script' 1 some-key '{"some": "json"}'
local key = KEYS[1];
local value = ARGV[1];
local mvalue = cmsgpack.pack(cjson.decode(value));
return redis.call('SET', key, mvalue);
@dcb9
Copy link

dcb9 commented Oct 10, 2020

SET

redis-cli --eval setjsonasmsgpack.lua some-key , '{"some": "json"}'

GET

redis-cli --eval getmsgpackasjson.lua some-key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment