Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Redis, how do I get the expiration date of a key?

Tags:

database

redis

What's the command I use to see how many seconds are remaining?

like image 909
TIMEX Avatar asked Aug 04 '11 02:08

TIMEX


People also ask

How do I change the expiration date on Redis cache?

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.

How do I find my Redis key value?

To get the value stored in a key, you can use the GET command followed by the name of the key. The above command tells Redis to fetch the value stored in the specified key. We can use the GET command followed by the unique value as: GET username:3.

How do I query a Redis key?

To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.


1 Answers

TTL key 

See the documentation of the TTL command.

There is also a PTTL command since Redis 2.6 that returns the amount of time in milliseconds instead of seconds.

like image 87
dee-see Avatar answered Sep 23 '22 17:09

dee-see