Created
January 26, 2016 14:43
-
-
Save ramonsnir/d6cba963241c821babde to your computer and use it in GitHub Desktop.
Simple Lua script for our test
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
--[[ | |
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