🔴 Redis Intermediate

What are Redis eviction policies?

Answer

When Redis reaches its maxmemory limit, it must evict keys to free space. The eviction policy is set via maxmemory-policy in redis.conf. Key policies: noeviction (default) — returns an error on writes instead of evicting, safe but breaks your app when full. allkeys-lru — evicts the least recently used key across all keys, best for general caching. volatile-lru — LRU eviction only among keys with a TTL set, preserving keys without expiry. allkeys-lfu — evicts the least frequently used key (Redis 4+), better than LRU for skewed access patterns. volatile-ttl — evicts keys with the shortest remaining TTL first. allkeys-random/volatile-random — random eviction. For a pure cache where all data is re-fetchable, allkeys-lru or allkeys-lfu is recommended.