CodePark/ questions / TTL & eviction policies
START PRACTICINGPRACTICE
Backend question · Redis & caching › TTL & eviction policies

Redis is at maxmemory with maxmemory-policy volatile-lru, and none of the keys has a TTL. What happens when a client sends a SET that needs more memory?

Redis returns an OOM error, behaving like noeviction

Redis returns an OOM (out of memory) error, just like noeviction. The volatile-* policies only look at keys that have an expiry (a TTL). Here no key has a TTL, so Redis has no key it is allowed to evict. Writes that need more memory fail. Reads and deletes still work.

"Redis evicts the least recently used key anyway" is wrong:
volatile-lru never evicts keys without a TTL, and it does not fall back to allkeys-random or any other policy.