Last active
November 2, 2019 19:47
-
-
Save nishant-jain/7daf15cf6daa435bff764cefa05802f2 to your computer and use it in GitHub Desktop.
Lua script to book items
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
if redis.call("EXISTS", KEYS[1]) == 1 then -- See if key for quantity exists | |
if redis.call("INCRBY", KEYS[1], ARGV[1]) >= 0 then -- "Increment" the key by -quantity | |
-- and check the new value | |
redis.call("EXPIRE", KEYS[1], ARGV[2]) -- set an expiry time on this booking | |
return true | |
else | |
return false | |
end | |
else | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment