Skip to content

Instantly share code, notes, and snippets.

@nishant-jain
Last active November 2, 2019 19:47
Show Gist options
  • Save nishant-jain/7daf15cf6daa435bff764cefa05802f2 to your computer and use it in GitHub Desktop.
Save nishant-jain/7daf15cf6daa435bff764cefa05802f2 to your computer and use it in GitHub Desktop.
Lua script to book items
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