2

Since the Redis expires keys in passive and active way,

Is there any way to get a key even if its expire time has passed(but still exists in Redis)?

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
Amin Shojaei
  • 5,451
  • 2
  • 38
  • 46
  • Do you mean just the key? Or also the value? See https://stackoverflow.com/questions/18328058/redis-2-8-notifications-get-value-instead-of-key-on-expire# – LeoMurillo Dec 25 '19 at 14:03
  • Key and value. I checked it, it's interesting but isn't what i meaned. – Amin Shojaei Dec 26 '19 at 05:30

2 Answers2

2

DEBUG OBJECT myKey will return info about the key even when it is expired timewise - if it has not been garbage-collected (actively-expired) or passively-expired (accessed) yet.

To test this, you can disable the background (active) expiring with DEBUG SET-ACTIVE-EXPIRE 0. Use carefully. Restore with DEBUG SET-ACTIVE-EXPIRE 1

Note the DEBUG OBJECT myKey returns the memory address, so if you really need to see the value, you'll have to explore the RAM contents.

> DEBUG OBJECT myKey
Value at:0x7fff70629920 refcount:1 encoding:embstr serializedlength:4 ...

DEBUG OBJECT myKey returns (error) ERR no such key if it has been expired already, actively or passively, or if it doesn't exist of course.

LeoMurillo
  • 6,048
  • 1
  • 19
  • 34
1

No, there isn't. The key (and its value) will be expired automatically eventually, or upon trying to access it (i.e. passively or actively).

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