What's the command I use to see how many seconds are remaining?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With