mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 19:27:48 +08:00
feat : common redis cache and common logger
This commit is contained in:
18
app/Cache/Redis/Script/rate_limit.lua
Normal file
18
app/Cache/Redis/Script/rate_limit.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
-- app/Cache/Redis/Script/rate_limit.lua
|
||||
local key = KEYS[1]
|
||||
local limit = tonumber(ARGV[1])
|
||||
local window = tonumber(ARGV[2])
|
||||
local current = redis.call('GET', key)
|
||||
local remaining = 0
|
||||
if current then
|
||||
remaining = tonumber(current) - 1
|
||||
if remaining >= 0 then
|
||||
redis.call('DECR', key)
|
||||
else
|
||||
remaining = -1
|
||||
end
|
||||
else
|
||||
remaining = limit - 1
|
||||
redis.call('SET', key, remaining, 'EX', window)
|
||||
end
|
||||
return {remaining >= 0, remaining}
|
||||
Reference in New Issue
Block a user