Skip to content

Instantly share code, notes, and snippets.

@knorwood
Last active September 30, 2016 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knorwood/7cb4d136ebe196010d4de379d290c263 to your computer and use it in GitHub Desktop.
Save knorwood/7cb4d136ebe196010d4de379d290c263 to your computer and use it in GitHub Desktop.
-- 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