开发者

How to know if key set to be expired or not in Redis?

开发者 https://www.devze.com 2022-12-31 21:25 出处:网络
As far as Redis do not allow to reSet expire date to key (because of nans with replication) I\'d like to know is there any method to check if key 开发者_开发问答set to be expired or not?

As far as Redis do not allow to reSet expire date to key (because of nans with replication) I'd like to know is there any method to check if key 开发者_开发问答set to be expired or not?

Thank you


Use the TTL command. If an expiration is set, it returns the number of seconds until the key expires; otherwise it returns -1.


I don't think checking for expiration date make much sense in Redis, though. I'd like to first suggest that you model it so you don't need to check for expiration date.

If you really need it, though, you can just use another key to store the expiration date for later retrieval via normal GET/SET.

Note that you can also check for EXPIRES manually in your client code, which might be a better solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消