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.
Previous
What is Lua scripting in Redis and when should you use it?
Next
What is HyperLogLog in Redis?
More Redis Questions
View all →- Intermediate What is Redis Cluster and how does it shard data?
- Intermediate What is the difference between Redis Sentinel and Redis Cluster?
- Intermediate How do MULTI and EXEC work in Redis transactions?
- Intermediate What is WATCH and optimistic locking in Redis?
- Intermediate What is Lua scripting in Redis and when should you use it?