Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

redis

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

like image 467
Kirzilla Avatar asked May 22 '10 13:05

Kirzilla


People also ask

Do Redis keys expire?

Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command.

How do I set Redis to expire?

To create a Redis with an expiration time, use the SET command and the EX option to set the expiration time. The EX option takes a number in seconds and sets the number of seconds the key is valid until expiration. You can also use PX to specify the expiration time in Milliseconds.


1 Answers

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

like image 111
rpetrich Avatar answered Oct 13 '22 13:10

rpetrich