Skip to content

Commit b7d0605

Browse files
flooeytaylorhakes
authored andcommitted
fix(lua): Fix time parsing in limit cache
1 parent 9cae0a2 commit b7d0605

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

redis_cache/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def get_cache_lua_fn(client):
6464
local limit = tonumber(ARGV[3])
6565
if limit > 0 then
6666
local time_parts = redis.call('TIME')
67-
local time = tonumber(time_parts[1] .. '.' .. time_parts[2])
67+
-- TIME returns [seconds, microseconds] (as strings), so parse each
68+
-- and add together to get the full timestamp
69+
local time = tonumber(time_parts[1]) + (tonumber(time_parts[2]) / 1000000)
6870
redis.call('ZADD', KEYS[2], time, KEYS[1])
6971
local count = tonumber(redis.call('ZCOUNT', KEYS[2], '-inf', '+inf'))
7072
local over = count - limit

0 commit comments

Comments
 (0)