1代表通过,0代表不通过
-
lua脚本一
local key = KEYS[1]
local limit = tonumber(ARGV[1])
local timeout = tonumber(ARGV[2])
local current = redis.call('get', key)
if not current or tonumber(current) < limit then
current = redis.call('incr', key)
if tonumber(current) == 1 then
redis.call('expire', key, timeout)
end
return 1
end
return 0
-
lua脚本二
local key = KEYS[1]
local limit = tonumber(ARGV[1])
local timeout = tonumber(ARGV[2])
local current = redis.call('incr', key)
if tonumber(current) == 1 then
redis.call('expire', key, timeout)
end
if tonumber(current) > limit then
return 0
end
return 1