local current = redis.call("GET", KEYS[1])
local now_ms = tonumber(ARGV[1])
local interval_ms = tonumber(ARGV[2])
local consume = tonumber(ARGV[3]) == 1
if current == false then
if consume then
redis.call("SET", KEYS[1], now_ms + interval_ms)
end
return {1, 0}
end
local next_allowed_ms = tonumber(current)
if now_ms >= next_allowed_ms then
if consume then
redis.call("SET", KEYS[1], now_ms + interval_ms)
end
return {1, 0}
end
return {0, next_allowed_ms - now_ms}