Get the last time a given Redis key was accessed

Peter Berg picture Peter Berg · Oct 7, 2014 · Viewed 11.1k times · Source

I'd like to view the time of most recent access for a specific key on my redis server.

I know that this information is stored for each key because it is used in redis's LRU algorithm for eliminating old keys.

Is there an easy way to see this information for a given key?

Answer

Itamar Haber picture Itamar Haber · Oct 8, 2014

You can use the OBJECT IDLETIME command for this purpose. It returns the number of seconds since the key was accessed, but If you need the time just subtract the reply from now().