Databases and servers
Redis maxmemory-policy: Eviction Choices and Their Side Effects
In short
Your redis maxmemory-policy decides what a full Redis does: delete data or refuse writes. The shipped default, noeviction, keeps every key and errors on commands that need memory. The volatile policies only remove keys that carry a TTL and give the same errors when none do. For a plain cache, the Redis docs point to allkeys-lru.
When does the eviction policy actually run?
Nothing is evicted until maxmemory is set. A value of zero means no limit, which is the default on 64-bit builds; 32-bit builds carry an implicit 3 GB cap. Without a limit, the policy setting does nothing.
With a limit in place, Redis checks memory each time a client runs a command that adds data. If usage is over the limit, it removes keys under the chosen policy until it is back below. A single large write, such as a big set intersection stored to a new key, can push usage well past the limit for a while.
Eviction is approximate. Redis samples a few keys (maxmemory-samples, default 5) and drops the best candidate among them, keeping a pool of good candidates since Redis 3.0. Raising the sample count to 10 brings it closer to true LRU at some CPU cost.
Which keys can each redis maxmemory-policy value remove?
Current docs list ten values. The two LRM ones arrived in Redis 8.6; check your version before using them.
| Policy | Keys it may remove | How it picks |
|---|---|---|
| noeviction | None | Rejects writes that need memory |
| allkeys-lru | Any key | Least recently read or written |
| allkeys-lfu | Any key | Least frequently used (Redis 4.0+) |
| allkeys-lrm | Any key | Least recently modified; reads do not count (8.6+) |
| allkeys-random | Any key | Random |
| volatile-lru | Only keys with a TTL | Least recently used |
| volatile-lfu | Only keys with a TTL | Least frequently used |
| volatile-lrm | Only keys with a TTL | Least recently modified (8.6+) |
| volatile-random | Only keys with a TTL | Random |
| volatile-ttl | Only keys with a TTL | Shortest remaining TTL |
What does a full instance under noeviction do to the app?
Reads keep working. Commands that create keys, add data or modify existing keys fail; the shipped config names SET, INCR, HSET, LPUSH, SUNIONSTORE, SORT with STORE, and an EXEC whose transaction contains any of them. With replication, the condition applies on the primary. The usual client-side symptom is covered on the OOM command not allowed fix page.
The same errors can appear under a volatile policy. If no key has a TTL, a volatile-* policy has nothing to remove and behaves like noeviction. That catches instances where the application stores cache entries without ever setting an expiry.
To see which commands are being refused, the eviction page points to the commandstats section of INFO, which counts rejected calls per command.
How do TTLs and eviction interact?
A TTL is not free. The EXPIRE docs say an expiry costs extra memory per key, and the eviction page notes that allkeys-lru is more memory efficient because it needs no TTL to work.
TTLs also disappear more easily than many people expect. Any command that deletes or overwrites the value, such as SET, GETSET or a *STORE command, clears the timeout, while INCR, LPUSH and HSET keep it. Code that refreshes a cache entry with a plain SET and no expiry option quietly removes that key from the pool a volatile policy can evict.
Expired keys are not all removed at the second they expire. Redis deletes them when a client touches them, and a background task tests random keys with a TTL, so some expired keys sit in memory for a while.
Why leave RAM free above maxmemory?
With replication or AOF persistence, Redis keeps buffers of updates waiting to go to replicas or the AOF file, and that memory is not counted against maxmemory. The reason is a feedback loop: every eviction produces a DEL that enters those buffers, and counting it would trigger yet more evictions. So set maxmemory below the RAM you have, and use mem_not_counted_for_evict from INFO memory to size the gap. The docs say noeviction does not need this headroom.
Replicas ignore maxmemory by default and simply apply the primary's DEL commands, for evictions and expiries alike. A replica can therefore use more memory than its own setting, and the replication docs ask you to monitor it. Changing replica-ignore-maxmemory is advised only if all writes to the replica are idempotent.
Evicted keys are freed on the main thread unless lazyfree-lazy-eviction is set to yes, which moves the freeing to the background.
Which policy fits which workload?
The docs give rules of thumb, and the ones below follow them; the final line is my own reading.
- Cache where a small set of keys gets most hits:
allkeys-lru. The docs call it a good default when there is no reason to prefer another, and the configuration page showsmaxmemoryplusallkeys-lruas a memcached-like setup that needs no TTLs. - Cache where long-term popularity beats recent use:
allkeys-lfu, tuned withlfu-log-factorandlfu-decay-time. - Read-heavy data you want dropped once writers stop updating it:
allkeys-lrmon 8.6 or newer. - Keys read in a repeating cycle with roughly equal frequency:
allkeys-random. - Code that knows which entries are disposable: give those short TTLs and use
volatile-ttl. - Cache and must-keep data on one instance: a
volatile-*policy works, but the docs suggest two instances instead. - Queues, sessions or any key whose loss is a lost job: I would keep
noeviction, size memory for the peak and alert on rejected writes, since an error is easier to notice than a silently deleted key. - Whatever you choose, watch
keyspace_hits,keyspace_misses,evicted_keysandexpired_keysinINFO stats. Many evictions with a poor hit rate suggest the wrong policy; many expirations suggest TTLs that are too short.
What else do people ask?
Can I change the policy without restarting Redis?
Yes, with <code>CONFIG SET maxmemory-policy</code>. That change is lost at restart unless you also edit the config file or run <code>CONFIG REWRITE</code>.
Is the LRU in Redis exact?
No. It samples keys rather than tracking a full ordering, because exact LRU costs more memory. The docs say the approximation is close for typical access patterns.
Sources
- Redis docs, key eviction, fetched 2026-11-20
- Redis 8.10 self-documented redis.conf (memory management section), linked from the Redis configuration docs, fetched 2026-11-20
- Redis docs, EXPIRE command, fetched 2026-11-20
- Redis docs, replication, fetched 2026-11-20
- Redis docs, Redis configuration, fetched 2026-11-20
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. This page draws on redis.io documentation and the Redis 8.10 redis.conf, both read on 20 Nov 2026, and reflects no Redis instance of mine. It leaves out Redis Cluster, Redis Software, Redis Cloud, Valkey and the defaults that managed cloud caches apply. Found a mistake? Tell me.