#
zhou zhou
22 小时以前 c1c045cad0f39a38409de117e9ddf470804b0d81
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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