Skip to content

Instantly share code, notes, and snippets.

@fritzy
Last active April 19, 2017 20:55
Show Gist options
  • Save fritzy/7376653 to your computer and use it in GitHub Desktop.
Save fritzy/7376653 to your computer and use it in GitHub Desktop.
Collate a Hash in Redis
--EVAL "this script" 1 some-hash-key
local key = KEYS[1];
local keyvalues = redis.call('HGETALL', key);
local result = {};
--every other value is a key
for idx = 1, #keyvalues, 2 do
result[keyvalues[idx]] = keyvalues[idx + 1]
end
return cjson.encode(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment