Eviction policy
The eviction policy determines what happens when a database reaches its memory limit.
| Redis Software | Redis Enterprise for Kubernetes |
|---|
The eviction policy determines what happens when a database reaches its memory limit.
To make room for new data, older data is evicted (removed) according to the selected policy. To prevent this from happening, make sure your database is large enough to hold all keys.
In clustered databases, each shard tracks its own memory usage and triggers eviction when it reaches its memory limit. If data is distributed unevenly across shards, some shards can fill up and start evicting keys while the overall database memory utilization is still below the configured limit.
| Eviction Policy | Description |
|---|---|
| noeviction | New values aren't saved when memory limit is reached When a database uses replication, this applies to the primary database |
| allkeys-lru | Keeps most recently used keys; removes least recently used (LRU) keys |
| allkeys-lrm | Keeps most recently modifed keys; removes least recently modified (LRM) keys |
| allkeys-lfu | Keeps frequently used keys; removes least frequently used (LFU) keys |
| allkeys-random | Randomly removes keys |
| volatile-lru | Removes least recently used keys with expire field set to true |
| volatile-lrm | Removes least recently modified keys with expire field set to true |
| volatile-lfu | Removes least frequently used keys with expire field set to true |
| volatile-random | Randomly removes keys with expire field set to true |
| volatile-ttl | Removes keys with expire field set to true and the shortest remaining time-to-live (TTL) value |
Eviction policy defaults
volatile-lru is the default eviction policy for most databases.
The default policy for Active-Active databases is noeviction policy.
Active-Active database eviction
The eviction policy mechanism for Active-Active databases starts earlier than for standalone databases because it requires propagation to all participating clusters. The eviction policy starts to evict keys when a shard in one of the Active-Active instances reaches 80% of its memory limit.
-
The 80% threshold applies to each shard's memory limit, not to the overall database limit.
-
If memory usage continues to rise while keys are being evicted, the eviction rate increases to avoid out-of-memory errors.
-
To avoid over eviction, internal heuristics might prevent keys from being evicted when the shard reaches the 80% memory limit. In such cases, keys will be evicted only when shard memory reaches 100%.
-
Redis Software sometimes allocates a higher
maxmemoryvalue to individual shards to accommodate uneven key distribution and avoid out-of-memory errors.
In case of network issues between Active-Active instances, memory can be freed only when all instances are in sync. If there is no communication between participating clusters, it can result in eviction of all keys and the instance reaching an out-of-memory state.
Avoid data eviction
To avoid data eviction, make sure your database is large enough to hold required values.
For larger databases, consider using Redis Flex or Auto Tiering .
Auto Tiering stores actively-used data (also known as hot data) in RAM and the remaining data in flash memory (SSD). This lets you retain more data while ensuring the fastest access to the most critical data.