local current = redis.call('get', KEYS[1])
|
local initial = tonumber(ARGV[1])
|
local reserve = tonumber(ARGV[2])
|
local ttl = tonumber(ARGV[3])
|
|
if current == false then
|
current = initial
|
else
|
current = tonumber(current)
|
end
|
|
if current < reserve then
|
return 0
|
end
|
|
local nextValue = current - reserve
|
redis.call('psetex', KEYS[1], ttl, tostring(nextValue))
|
redis.call('incrbyfloat', KEYS[2], reserve)
|
redis.call('pexpire', KEYS[2], ttl)
|
return 1
|