Back to results for “Architecture”
Redis › Expiration & Eviction

What eviction policies are available in Redis for handling the situation when memory usage reaches its configured maximum limit?

Intermediate

Answer

Redis offers several eviction policies including noeviction, which rejects new writes once memory is full, allkeys-lru and volatile-lru, which remove the least recently used keys, allkeys-lfu and volatile-lfu, which remove the least frequently used keys, and random based policies, letting you choose the behavior that best fits whether your data is primarily used as a cache or as a persistent store.
CONFIG SET maxmemory-policy allkeys-lru
CONFIG SET maxmemory 2gb
Real-world example A caching layer for a busy website configures the allkeys-lru eviction policy, ensuring that when memory fills up, Redis automatically removes the least recently accessed cached items to make room for new ones.

Common follow-ups: What is the difference between the allkeys and volatile variants of these eviction policies?;What happens if you use noeviction and memory becomes completely full?