简体   繁体   中英

Is there a way to increase ttl in redis?

我知道有几种方法可以为键设置特定的 ttl,但是有没有办法为具有倒计时 ttl 的键添加一些额外的时间?

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
  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM