Prompt
Why is my Redis cache getting evicted so fast?
Latest observation
“Evicted so fast” in Redis usually means Redis is running out of memory and is actively removing keys according to its eviction policy, or your keys are expiring sooner than you expect. The most common causes are:
1) Memory limit is too low
If maxmemory is set too small, Redis will start evicting keys once it reaches that limit.
Check:
redis-cli INFO memory
redis-cli CONFIG GET maxmemory
2) Eviction policy is aggressive
Redis evicts keys based on maxmemory-policy when memory is full. Common policies:
allkeys-lru: evicts least recently used keysvolatile-lru: evicts only keys with TTLallkeys-random: evicts random keysvolatile-ttl: evicts keys with nearest expiry
Check:
redis-cli CONFIG GET maxmemory-policy
3) Your keys have TTLs and are expiring normally
Sometimes what looks like eviction is just expiration.
Check stats:
redis-cli INFO stats
Look at:
expired_keysevicted_keys
If expired_keys is rising, the keys are timing out.
If evicted_keys is rising, Redis is removing them due to memory pressure.
4) Memory usage is higher than expected
Possible reasons:
- Large values
- Too many keys
- Inefficient data structures
- Overhead from lots of small keys
- Replication/AOF/RDB memory overhead
Inspect:
redis-cli MEMORY STATS
redis-cli DBSIZE
redis-cli --bigkeys
5) Some client is overwriting or deleting keys
Application bugs, cleanup jobs, or cache invalidation logic can make it seem like Redis is evicting keys.
Check key access and deletions in app logs, or temporarily monitor:
redis-cli MONITOR
6) Container / VM memory pressure
If Redis is in Docker/Kubernetes/limited VM memory, the host may be under pressure, causing instability or forced evictions depending on setup.
Check:
- container memory limit
- host RAM usage
- Redis
used_memory_rss
Fastest way to diagnose
Run these commands:
redis-cli INFO stats
redis-cli INFO memory
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy
Then compare:
evicted_keysexpired_keysused_memorymaxmemory
If you want, paste the output of:
redis-cli INFO stats
redis-cli INFO memory
redis-cli CONFIG GET maxmemory
redis-cli CONFIG GET maxmemory-policy
and I can tell you exactly why it’s happening.
Brands