Skip to content

Commit

Permalink
Set expiry on meta keys when touching them
Browse files Browse the repository at this point in the history
Even in the read command, we need to ensure that a TTL is set on the
meta key when we write to it.
  • Loading branch information
nickstenning committed Jul 18, 2024
1 parent 4ac4835 commit 6cbfa70
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions queue/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ func TestClientReadLegacyStreamIntegration(t *testing.T) {
msgs[msg.Values["idx"].(string)] = struct{}{}
}

ttl, err := rdb.TTL(ctx, "myqueue:meta").Result()
require.NoError(t, err)
assert.Greater(t, ttl, 23*time.Hour)

assert.Len(t, msgs, 50)
}

Expand Down
2 changes: 2 additions & 0 deletions queue/read.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ for idx = 0, streams do
local reply = checkstream(base)
if reply then
redis.call('HSET', key_meta, 'offset', (offset + idx + 1) % streams)
redis.call('EXPIRE', key_meta, ttl)
return reply
end
end

local reply = checkstream(base .. ':s' .. streamid)
if reply then
redis.call('HSET', key_meta, 'offset', (offset + idx + 1) % streams)
redis.call('EXPIRE', key_meta, ttl)
return reply
end
end
Expand Down
2 changes: 1 addition & 1 deletion queue/write.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ local id = redis.call('XADD', key_stream, '*', unpack(fields))
-- Add a notification to the notifications stream
redis.call('XADD', key_notifications, 'MAXLEN', '1', '*', 's', selected_sid)

-- Set expiry on all selected streams + meta key
-- Set expiry on selected stream + meta/notifications keys
redis.call('EXPIRE', key_stream, ttl)
redis.call('EXPIRE', key_meta, ttl)
redis.call('EXPIRE', key_notifications, ttl)
Expand Down

0 comments on commit 6cbfa70

Please sign in to comment.