Last active
September 30, 2016 21:37
-
-
Save knorwood/7cb4d136ebe196010d4de379d290c263 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- hmincrby for redis | |
-- | |
-- Usage: | |
-- redis-cli EVAL "$(cat hmincrby.lua)" 1 key field1 num1 field2 num2 ... fieldn numn | |
if 1 ~= table.getn(KEYS) then | |
error("Must have exactly 1 key") | |
end | |
if 0 ~= table.getn(ARGV) % 2 then | |
error("Must have an even number of arguments") | |
end | |
local results = {} | |
for i = 0, #ARGV / 2 - 1 do | |
local f = ARGV[(i * 2) + 1] | |
local n = ARGV[(i * 2) + 2] | |
-- pcall captures the exception so the error will be in the returned array | |
-- of results so the caller should be able to retry just the erroneous | |
-- field/num pairs without any double counting | |
table.insert(results, redis.pcall('HINCRBY', KEYS[1], f, n)) | |
end | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment