18

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?

Peter Berg
  • 6,006
  • 8
  • 37
  • 51
  • @Javier I appreciate the sentiment, but LRU actually stands for "Least Recently Used", at least in the context of the LRU algorithm. http://en.wikipedia.org/wiki/Cache_algorithms – Peter Berg Oct 07 '14 at 22:19

2 Answers2

32

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().

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
4

Itamar Haber's answer is definitely the best, but I believe there is an other way.

You can use the DEBUG OBJECT command, although as its name indicates it is a debug command and should not (really) be used. Its output gives you the LRU.

Keep in mind that it should definitely not be used in production but rather as a tool to help you understand what is going on.

Arnaud Potier
  • 1,750
  • 16
  • 28