Eviction Policies Interview Questions
How does Redis eviction policy work? — spoken sample answer for Indian interviews.
- 5Questions with answers
- 3Difficulty levels
Questions (5)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
How does Redis eviction policy work?
When Redis hits maxmemory it has to evict or reject writes. The policy is maxmemory-policy. allkeys-lru evicts the least recently used key anywhere. volatile-lru only evicts keys that have a TTL. LFU uses frequency. noeviction means writes start failing. For a pure cache I set allkeys-lru and a maxmemory. For sessions I might use noeviction or I accept that a restart rebuilds from the DB. I always set maxmemory in production. I still put TTLs on cache keys. Eviction is not a substitute for forgetting to expire a key. I would watch evicted_keys on the dashboard.
noeviction versus allkeys-lru for a cache?
A cache should evict. noeviction makes writes fail when full — right for a store, wrong for a cache. Set maxmemory. Unlimited Redis OOMs the host.
volatile-lru versus allkeys-lru?
volatile only evicts keys with TTL. Mix durable keys without TTL and cache keys with TTL, volatile protects durable. Prefer not to mix in one instance.
How do you choose maxmemory?
Leave RAM for OS, overhead, peak. Watch used_memory and evicted_keys. I would rather evict than OOM-kill Redis. Not a blog number.
What happens to a huge sorted set on eviction?
The whole key goes, not one member. Huge zsets are dangerous. Cap, shard, or trim. Evicting a big key also spikes latency.
Practice with AI mock interviews
Run Redis mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required