fix: classify upstream failures and prevent empty billed responses

This commit is contained in:
wlx committed 2026-09-28 04:55:00 +08:00
1 parent b455d8d79f
commit 9acc69d4c7
28 files changed
+1449 -131

No files matched your search

@@ -2,8 +2,18 @@ local time = redis.call('TIME')
local now = tonumber(time[1]) * 1000 + math.floor(tonumber(time[2]) / 1000)
redis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', now)
redis.call('ZREMRANGEBYSCORE', KEYS[2], '-inf', now)
if redis.call('ZCARD', KEYS[1]) >= tonumber(ARGV[1]) then return 0 end
if redis.call('ZCARD', KEYS[2]) >= tonumber(ARGV[2]) then return 2 end
redis.call('ZREMRANGEBYSCORE', KEYS[3], '-inf', now)
local busy = nil
if redis.call('ZCARD', KEYS[1]) >= tonumber(ARGV[1]) then busy = 0
elseif redis.call('ZCARD', KEYS[2]) >= tonumber(ARGV[2]) then busy = 2 end
if busy ~= nil then
if tonumber(ARGV[5]) > 0 then
redis.call('ZADD', KEYS[3], now + tonumber(ARGV[5]), ARGV[4])
redis.call('PEXPIRE', KEYS[3], ARGV[6])
end
return busy
end
redis.call('ZREM', KEYS[3], ARGV[4])
redis.call('ZADD', KEYS[1], now + tonumber(ARGV[3]), ARGV[4])
redis.call('ZADD', KEYS[2], now + tonumber(ARGV[3]), ARGV[4])
redis.call('PEXPIRE', KEYS[1], ARGV[3])