Database / REDIS
Define eviction policies in Redis?
When Redis is used as a cache with a fixed maxmemory limit, an eviction policy determines which keys get removed once that limit is reached and new writes still need room — without a policy that allows eviction, Redis would instead simply reject new writes with an out-of-memory error once the limit is hit.
| Policy | Behavior |
| noeviction | Reject writes once memory limit is reached; default setting. |
| allkeys-lru | Evict the least recently used key, across all keys. |
| allkeys-lfu | Evict the least frequently used key, across all keys. |
| volatile-lru | Evict least recently used, but only among keys with a TTL set. |
| volatile-ttl | Evict the key with the shortest remaining TTL first. |
| allkeys-random | Evict a random key, across all keys. |
The right choice depends on how Redis is being used: a pure cache where any key can reasonably be recomputed typically uses allkeys-lru or allkeys-lfu, while a mixed deployment storing some permanent data alongside expiring cache entries uses one of the volatile-* policies to ensure only the expiring, cache-like keys are ever candidates for eviction.
More Related questions...
