Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Lua script for our test
--[[
ARGUMENTS
KEYS:
1 - key
ARGV:
1 - sub-key to increment
--]]
-- unpack data, or empty data
local data = redis.call("get", KEYS[1])
if data == false then
data = {}
else
data = cmsgpack.unpack(data)
end
-- initialize
if type(data[ARGV[1]]) == "nil" then
data[ARGV[1]] = 0
end
-- increment
data[ARGV[1]] = data[ARGV[1]] + 1
-- write data
redis.call("set", KEYS[1], cmsgpack.pack(data))
-- return, for consistency
return cmsgpack.pack(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment