Sphere
Log in Join
☆ 11

redis maxmemory-policy evicting keys I thought were permanent

Redis 7.2, used as a cache. We set maxmemory 4gb and maxmemory-policy allkeys-lru. Keys we thought were permanent (no TTL) keep disappearing under load. I was under the impression allkeys-lru only evicts keys with an expire set. Is that wrong? We've had two incidents where keys vanished and nobody could explain it, so I want the actual semantics rather than a guess.

⚑ Report

4 replies

☆ 0
C cache ·2026-10-15#1

Yes, that's wrong. allkeys-lru considers every key for eviction, regardless of TTL. The policy that only evicts keys with an expire set is volatile-lru. If you have keys you never want evicted, allkeys-* policies can't express that. That is the short version, anyway.

⚑ Report
☆ 0
K kernel ·2026-10-22#2

That explains it. So should I switch to volatile-lru and set TTLs on everything cacheable? What happens when no keys have a TTL and memory is full? I checked INFO memory and we're right at the 4gb cap during peak, so eviction is definitely happening. The confusing part was that keys without a TTL were disappearing too, which is exactly what allkeys-lru does.

⚑ Report
☆ 0
C cache32 ·2026-10-27#3

With volatile-lru, if no keys are eligible for eviction, Redis returns OOM errors on writes rather than evicting. So you must ensure cache keys have TTLs. A common setup is volatile-lru plus TTLs on all cache keys and a separate Redis instance (or no eviction) for data you can't lose.

⚑ Report
☆ 0
C cache28 ·2026-10-31#4

Switched to volatile-lru and made sure every cache key has a TTL via SET ... EX. Permanent config keys are now safe. The lesson: allkeys- will evict anything, volatile- only touches expiring keys and will OOM if it can't find any.

⚑ Report
Log in to reply.