Redis › Expiration & Eviction
What eviction policies are available in Redis for handling the situation when memory usage reaches its configured maximum limit?
IntermediateAnswer
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 2gbReal-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.