Created
March 15, 2013 15:03
-
-
Save klovadis/5170485 to your computer and use it in GitHub Desktop.
A Lua script for Redis that allows you to set hash values based on a dictionary table
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
-- sets all fields for a hash from a dictionary | |
local hmset = function (key, dict) | |
if next(dict) == nil then return nil end | |
local bulk = {} | |
for k, v in pairs(dict) do | |
table.insert(bulk, k) | |
table.insert(bulk, v) | |
end | |
return redis.call('HMSET', key, unpack(bulk)) | |
end | |
-- example will set foo and baz in myhash | |
local mytable = { foo='bar', baz='asdf' } | |
hmset('myhash', mytable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment