test_async_log_success_event_increments_by_actual_tokens

This commit is contained in:
Ishaan Jaffer 2025-12-05 14:57:18 -08:00
parent 5b17fa2d82
commit 5620cfea6e

View file

@ -65,6 +65,13 @@ for i = 1, #KEYS, 2 do
table.insert(results, increment_value) -- counter
else
local counter = redis.call('INCR', counter_key)
-- FIX: Set TTL if counter key was just created (has no TTL)
-- This happens when window_key exists but counter_key doesn't (e.g., tokens key
-- created after requests key when both share the same window_key)
local current_ttl = redis.call('TTL', counter_key)
if current_ttl == -1 then
redis.call('EXPIRE', counter_key, window_size)
end
table.insert(results, window_start) -- window_start
table.insert(results, counter) -- counter
end