Skip to content

Commit fbabe67

Browse files
[fix] conj keys always have -1 as expiration in redis 7
1 parent 0c8cdda commit fbabe67

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

cacheops/lua/cache_thing.lua

+10-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,19 @@ for db_table, disj in pairs(dnfs) do
4747
redis.call('sadd', conj_key, key)
4848
-- NOTE: an invalidator should live longer than any key it references.
4949
-- So we update its ttl on every key if needed.
50+
local conj_ttl = redis.call('ttl', conj_key)
5051
-- REDIS_7
51-
redis.call('expire', conj_key, timeout, 'gt')
52+
-- Removing `redis.call('expire', conj_key, timeout, 'gt')` as ttl is not setting up when its value is -1
53+
-- Refer - https://redis.io/docs/latest/commands/expire/
54+
if conj_ttl == -1 then
55+
-- Use NX when no expiry is present i.e. ttl = -1
56+
redis.call('expire', conj_key, timeout, 'nx')
57+
elseif conj_ttl < timeout then
58+
-- Use XX when current expiration time is less than timeout
59+
redis.call('expire', conj_key, timeout, 'xx')
60+
end
5261
-- /REDIS_7
5362
-- REDIS_4
54-
local conj_ttl = redis.call('ttl', conj_key)
5563
if conj_ttl < timeout then
5664
-- We set conj_key life with a margin over key life to call expire rarer
5765
-- And add few extra seconds to be extra safe

cacheops/lua/cache_thing_insideout.lua

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@ for _, conj_key in ipairs(conj_keys) do
2828
table.insert(stamps, stamp)
2929
-- NOTE: an invalidator should live longer than any key it references.
3030
-- So we update its ttl on every key if needed.
31+
local conj_ttl = redis.call('ttl', conj_key)
3132
-- REDIS_7
32-
redis.call('expire', conj_key, timeout, 'gt')
33+
-- Removing `redis.call('expire', conj_key, timeout, 'gt')` as ttl is not setting up when its value is -1
34+
-- Refer - https://redis.io/docs/latest/commands/expire/
35+
if conj_ttl == -1 then
36+
-- Use NX when no expiry is present i.e. ttl = -1
37+
redis.call('expire', conj_key, timeout, 'nx')
38+
elseif conj_ttl < timeout then
39+
-- Use XX when current expiration time is less than timeout
40+
redis.call('expire', conj_key, timeout, 'xx')
41+
end
3342
-- /REDIS_7
3443
-- REDIS_4
35-
local conj_ttl = redis.call('ttl', conj_key)
3644
if conj_ttl < timeout then
3745
-- We set conj_key life with a margin over key life to call expire rarer
3846
-- And add few extra seconds to be extra safe

0 commit comments

Comments
 (0)