Skip to content

Commit 30bd32e

Browse files
committed
DEV: add info about new eviction policies (allkeys-lrm & volatile-lrm)
1 parent 7825f38 commit 30bd32e

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

  • content/develop/reference/eviction

content/develop/reference/eviction/index.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ The following policies are available:
102102
then this condition only applies to the primary database. Note that commands that only
103103
read existing data still work as normal.
104104
- `allkeys-lru`: Evict the [least recently used](#apx-lru) (LRU) keys.
105+
- `allkeys-lrm`: Evict the [least recently modified](#lrm-eviction) (LRM) keys.
105106
- `allkeys-lfu`: Evict the [least frequently used](#lfu-eviction) (LFU) keys.
106107
- `allkeys-random`: Evict keys at random.
107108
- `volatile-lru`: Evict the least recently used keys that have the `expire` field
108109
set to `true`.
110+
- `volatile-lrm`: Evict the least recently modified keys that have the `expire` field
111+
set to `true`.
109112
- `volatile-lfu`: Evict the least frequently used keys that have the `expire` field
110113
set to `true`.
111114
- `volatile-random`: Evict keys at random only if they have the `expire` field set
@@ -128,14 +131,18 @@ As a rule of thumb:
128131
more often than the rest. This is a very common case according to the
129132
[Pareto principle](https://en.wikipedia.org/wiki/Pareto_principle), so
130133
`allkeys-lru` is a good default option if you have no reason to prefer any others.
134+
- Use `allkeys-lrm` when you want to preserve frequently read data but evict data
135+
that hasn't been modified recently. This is useful for read-heavy workloads where
136+
you want to distinguish between data that's actively being updated versus data
137+
that's only being read.
131138
- Use `allkeys-random` when you expect all keys to be accessed with roughly equal
132139
frequency. An example of this is when your app reads data items in a repeating cycle.
133140
- Use `volatile-ttl` if your code can estimate which keys are good candidates for eviction
134141
and assign short TTLs to them. Note also that if you make good use of
135142
key expiration, then you are less likely to run into the cache memory limit because keys
136143
will often expire before they need to be evicted.
137144

138-
The `volatile-lru` and `volatile-random` policies are mainly useful when you want to use
145+
The `volatile-lru`, `volatile-lrm`, and `volatile-random` policies are mainly useful when you want to use
139146
a single Redis instance for both caching and for a set of persistent keys. However,
140147
you should consider running two separate Redis instances in a case like this, if possible.
141148

@@ -292,3 +299,25 @@ The counter *logarithm factor* changes how many hits are needed to saturate the
292299
```
293300

294301
So basically the factor is a trade off between better distinguishing items with low accesses VS distinguishing items with high accesses. More information is available in the example `redis.conf` file.
302+
303+
## LRM eviction {#lrm-eviction}
304+
305+
Starting with Redis 8.6, the Least Recently Modified (LRM) eviction mode is available. LRM is similar to LRU but only updates the timestamp on write operations, not read operations. This makes it useful for evicting keys that haven't been modified recently, regardless of how frequently they are read.
306+
307+
The key difference between LRU and LRM is:
308+
309+
- **LRU (Least Recently Used)**: Updates the access timestamp on both read and write operations
310+
- **LRM (Least Recently Modified)**: Updates the access timestamp only on write operations
311+
312+
This distinction makes LRM particularly useful in scenarios where:
313+
314+
- You want to preserve frequently read data, even if it's not being modified
315+
- Your application has a clear distinction between read-heavy and write-heavy workloads
316+
- You want to evict stale data that hasn't been updated, regardless of read activity
317+
318+
To configure the LRM mode, the following policies are available:
319+
320+
* `volatile-lrm` Evict using LRM among the keys with an expire set.
321+
* `allkeys-lrm` Evict any key using LRM.
322+
323+
Like LRU, LRM uses an approximation algorithm that samples a small number of keys at random and evicts the ones with the longest time since last modification. The same `maxmemory-samples` configuration directive that affects LRU performance also applies to LRM.

0 commit comments

Comments
 (0)