Skip to content

Instantly share code, notes, and snippets.

View nishant-jain's full-sized avatar

Nishant Jain nishant-jain

  • New Delhi
View GitHub Profile
@nishant-jain
nishant-jain / productQuantityCheck.lua
Last active November 2, 2019 19:47
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