skip to Main Content

I know there are several ways to set a specific ttl for a key, but is there a way to add some extra time for a key which has a counting down ttl?

2

Answers


  1. There’s no built-in way to extend TTL. You need to get the current TTL, and then add some more TTL to it.

    Wrap these two steps into a Lua script:

    -- extend 300 seconds
    eval 'local ttl = redis.call("TTL", "key") + 300; redis.call("EXPIRE", "key", ttl)' 0
    
    Login or Signup to reply.
    1. Good question
    2. there is no such command
    3. I think it is a bad idea to have a command like that, you have to be careful when you use it.
    4. Probably end up adding more time to the ttl than we expect. If you set it like 5 mins, the actual expire time will be close to 5 mins even if setting it multiple times in that request. But if you add multiple 5 mins to it, then we can`t be sure of the actual expire time
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search