feat : common redis cache and common logger

This commit is contained in:
2025-09-14 15:58:45 +08:00
parent 48ad2ebd1b
commit 0db9995c19
15 changed files with 640 additions and 14 deletions

View 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}