peng
7 天以前 75f9783d5a70a5f037e3b34dc0e479069e63c0e9
1
2
3
4
5
6
7
8
9
10
11
12
13
local c
c = redis.call('get',KEYS[1])
-- 调用不超过最大值,则直接返回
if c and tonumber(c) > tonumber(ARGV[1]) then
    return c;
end
-- 执行计算器自加
c = redis.call('incr',KEYS[1])
if tonumber(c) == 1 then
-- 从第一次调用开始限流,设置对应键值的过期
    redis.call('expire',KEYS[1],ARGV[2])
end
return c;