6

I've a redis server set with a maxmemory-policy set to volatile-lru. The documentation indicate this will evict from the set of entries with expires set when memory limit has reached.

In this case, does redis only evict items past their expiration? If everything in memory has an expire set, but nothing is past the expiration time, will anything get evicted when max memory is reached?

Ray
  • 40,256
  • 21
  • 101
  • 138

1 Answers1

8

If your eviction policy is set to any of the volatile-* policies, when running out of memory and having no volatile keys to evict, Redis will return an OOM error.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • 1
    Thanks. Just to clarify: If all volatile keys have expires that are in the future, does that mean there are no evictable volatile keys? i.e. Can only a key past it's expire be considered for eviction? – Ray Feb 19 '15 at 14:56
  • 1
    No - once a key is set with a TTL, it is considered volatile (and will be a candidate for eviction under the volatile-* policies). When a volatile key expires it can no longer be evicted as it no longer exists. – Itamar Haber Feb 19 '15 at 14:59
  • Ok, so if all my keys have expires in the future (are volitile), when memory max is reached it should still start evicting the oldest ones if volitile LRU is set. – Ray Feb 19 '15 at 15:19
  • Please state what happens if a TTL is explicitly set to -1? In my experience, keys set like this are not eligible for volatile-* evictions. – keithl8041 Dec 14 '17 at 12:29
  • @keithl8041I'm not aware of a way to directly set a key's TTL to any value, it is controlled indirectly by the `EXPIRE`/`PEXPIRE`/`SET .. EX` commands and providing a negative value causes immediate expiration. – Itamar Haber Dec 15 '17 at 00:23
  • @Farhad yes, setting `maxmemory-policy` to `allkeys-lru` will evict keys regardless their TTL – Itamar Haber Jan 22 '18 at 16:50