feat: migrate lua script to lua file (#4069)

This commit is contained in:
fearlessfei
2024-04-17 23:20:10 +08:00
committed by GitHub
parent 36088ea0d4
commit 62c88a84d1
10 changed files with 102 additions and 74 deletions

View File

@@ -0,0 +1,14 @@
-- to be compatible with aliyun redis, we cannot use `local key = KEYS[1]` to reuse the key
local limit = tonumber(ARGV[1])
local window = tonumber(ARGV[2])
local current = redis.call("INCRBY", KEYS[1], 1)
if current == 1 then
redis.call("expire", KEYS[1], window)
end
if current < limit then
return 1
elseif current == limit then
return 2
else
return 0
end