Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time of creation of key in redis

Tags:

time

redis

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 

?

like image 271
Pratik Deoghare Avatar asked Mar 28 '12 23:03

Pratik Deoghare


People also ask

How will you find the time to live for a key A in Redis?

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.

Does Redis have timestamp?

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.

What is time to live in Redis?

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.

How long is Redis key?

The maximum allowed key size is 512 MB.


2 Answers

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 
like image 94
Donald Miner Avatar answered Oct 15 '22 14:10

Donald Miner


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 
like image 31
Damaged Organic Avatar answered Oct 15 '22 13:10

Damaged Organic