zhou zhou
4 天以前 d2386afe5adb6bb6ed2ab04d4ce6417643e86220
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