2
votes

I have a database with TTL on the keys.
I also have a script which runs periodically to reset the TTL of all the keys to its default value (here 20 secs):

local matches = redis.call('KEYS', '*') for _,key in ipairs(matches) do redis.call('SETEX', key, 20, -1) end

My question - is it possible that a key will expire WHILE the above script is running.
I know the Lua scripts are atomic (http://redis.io/commands/EVAL, "Atomicity of scripts") but im not sure this also applies to expiration events.

Thanks

1
Interesting question. I think it boils down to whether or not the expiration process uses the same thread that's used to service requests. My guess is that it does.Kevin Christopher Henry

1 Answers

0
votes

Yes, it is possible because Redis checks the TTL when accessing the key.

Also, the use of the KEYS command in general and specifically from a Lua script, is strongly discouraged.