You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/develop/reference/eviction/index.md
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,10 +102,13 @@ The following policies are available:
102
102
then this condition only applies to the primary database. Note that commands that only
103
103
read existing data still work as normal.
104
104
-`allkeys-lru`: Evict the [least recently used](#apx-lru) (LRU) keys.
105
+
-`allkeys-lrm`: Evict the [least recently modified](#lrm-eviction) (LRM) keys.
105
106
-`allkeys-lfu`: Evict the [least frequently used](#lfu-eviction) (LFU) keys.
106
107
-`allkeys-random`: Evict keys at random.
107
108
-`volatile-lru`: Evict the least recently used keys that have the `expire` field
108
109
set to `true`.
110
+
-`volatile-lrm`: Evict the least recently modified keys that have the `expire` field
111
+
set to `true`.
109
112
-`volatile-lfu`: Evict the least frequently used keys that have the `expire` field
110
113
set to `true`.
111
114
-`volatile-random`: Evict keys at random only if they have the `expire` field set
@@ -128,14 +131,18 @@ As a rule of thumb:
128
131
more often than the rest. This is a very common case according to the
129
132
[Pareto principle](https://en.wikipedia.org/wiki/Pareto_principle), so
130
133
`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.
131
138
- Use `allkeys-random` when you expect all keys to be accessed with roughly equal
132
139
frequency. An example of this is when your app reads data items in a repeating cycle.
133
140
- Use `volatile-ttl` if your code can estimate which keys are good candidates for eviction
134
141
and assign short TTLs to them. Note also that if you make good use of
135
142
key expiration, then you are less likely to run into the cache memory limit because keys
136
143
will often expire before they need to be evicted.
137
144
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
139
146
a single Redis instance for both caching and for a set of persistent keys. However,
140
147
you should consider running two separate Redis instances in a case like this, if possible.
141
148
@@ -292,3 +299,25 @@ The counter *logarithm factor* changes how many hits are needed to saturate the
292
299
```
293
300
294
301
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