Suppose I do this in redis at 13:30 20 Feb 2020
,
> set foo "bar spam" OK
I want to get time of creation of foo
. Is there something like
> gettime foo 13:30 20 Feb 2020
?
Redis TTL command is used to get the remaining time of key expiry in seconds. Returns the remaining time to live of a key that has a timeout. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset.
The TIME command returns the current server time as a two items lists: a Unix timestamp and the amount of microseconds already elapsed in the current second. Basically the interface is very similar to the one of the gettimeofday system call.
Time to live (TTL) is an integer value that specifies the number of seconds until the key expires. Redis can specify seconds or milliseconds for this value. When an application attempts to read an expired key, it is treated as though the key is not found. The database is queried for the key and the cache is updated.
The maximum allowed key size is 512 MB.
Redis doesn't store this information.
You could use a separate key:
MULTI SET foo "bar spam" SET foo:time "13:30 20 Feb 2020" EXEC GET foo:time
There is another, similar option to solve this, for the use case when you need timer to detect expired value without deleting the value itself:
MULTI SET foo "bar" SET foo:alive 1 EX 30 EXEC
Here 30
- is a desired timeout. You can then determine whether value is still "alive" with:
EXISTS foo:alive
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