Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] conj keys always have -1 as expiration in redis 7 #477

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cacheops/lua/cache_thing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@ for db_table, disj in pairs(dnfs) do
redis.call('sadd', conj_key, key)
-- NOTE: an invalidator should live longer than any key it references.
-- So we update its ttl on every key if needed.
local conj_ttl = redis.call('ttl', conj_key)
-- REDIS_7
redis.call('expire', conj_key, timeout, 'gt')
-- Removing `redis.call('expire', conj_key, timeout, 'gt')` as ttl is not setting up when its value is -1
-- Refer - https://redis.io/docs/latest/commands/expire/
if conj_ttl == -1 then
-- Use NX when no expiry is present i.e. ttl = -1
redis.call('expire', conj_key, timeout, 'nx')
elseif conj_ttl < timeout then
-- Use XX when current expiration time is less than timeout
redis.call('expire', conj_key, timeout, 'xx')
end
-- /REDIS_7
-- REDIS_4
local conj_ttl = redis.call('ttl', conj_key)
if conj_ttl < timeout then
-- We set conj_key life with a margin over key life to call expire rarer
-- And add few extra seconds to be extra safe
Expand Down
12 changes: 10 additions & 2 deletions cacheops/lua/cache_thing_insideout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ for _, conj_key in ipairs(conj_keys) do
table.insert(stamps, stamp)
-- NOTE: an invalidator should live longer than any key it references.
-- So we update its ttl on every key if needed.
local conj_ttl = redis.call('ttl', conj_key)
-- REDIS_7
redis.call('expire', conj_key, timeout, 'gt')
-- Removing `redis.call('expire', conj_key, timeout, 'gt')` as ttl is not setting up when its value is -1
-- Refer - https://redis.io/docs/latest/commands/expire/
if conj_ttl == -1 then
-- Use NX when no expiry is present i.e. ttl = -1
redis.call('expire', conj_key, timeout, 'nx')
elseif conj_ttl < timeout then
-- Use XX when current expiration time is less than timeout
redis.call('expire', conj_key, timeout, 'xx')
end
-- /REDIS_7
-- REDIS_4
local conj_ttl = redis.call('ttl', conj_key)
if conj_ttl < timeout then
-- We set conj_key life with a margin over key life to call expire rarer
-- And add few extra seconds to be extra safe
Expand Down
Loading