Skip to content

Commit e46ed29

Browse files
DOC-4380 tidied up slightly
1 parent 58a675a commit e46ed29

File tree

1 file changed

+24
-20
lines changed
  • content/develop/reference/eviction

1 file changed

+24
-20
lines changed

content/develop/reference/eviction/index.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ weight: 6
1717

1818
Redis is commonly used as a cache to speed up read accesses to a slower server
1919
or database. Since cache entries are copies of persistently-stored data, it
20-
is usually safe to evict them when the cache runs out of RAM (they can be
20+
is usually safe to evict them when the cache runs out of memory (they can be
2121
cached again in the future if necessary).
2222

2323
Redis lets you specify an eviction policy to evict keys automatically
2424
when the size of the cache exceeds a set memory limit. Whenever a client
2525
runs a new command that adds more data to the cache, Redis checks the memory usage.
2626
If it is greater than the limit, Redis evicts keys according to the chosen
27-
eviction policy until the used memory is back below the limit.
27+
eviction policy until the total memory used is back below the limit.
2828

2929
Note that when a command adds a lot of data to the cache (for example, a big set
3030
intersection stored into a new key), this might temporarily exceed the limit by
@@ -34,22 +34,27 @@ The sections below explain how to [configure the memory limit](#maxmem) for the
3434
and also describe the available [eviction policies](#eviction-policies) and when to
3535
use them.
3636

37-
## `Maxmemory` configuration directive {#maxmem}
37+
## Using the `maxmemory` configuration directive {#maxmem}
3838

3939
The `maxmemory` configuration directive specifies
4040
the maximum amount of memory to use for the cache data. You can
41-
set `maxmemory` with the `redis.conf` file at startup time, or
42-
with the [`CONFIG SET`]({{< relref "/commands/config-set" >}}) command at runtime.
43-
44-
For example, to configure a memory limit of 100 megabytes, you can use the
45-
following directive inside the `redis.conf` file:
41+
set `maxmemory` with the [`redis.conf`](https://github.com/redis/redis/blob/7.4.0/redis.conf)
42+
file at startup time. For example, to configure a memory limit of 100 megabytes,
43+
you can use the following directive inside `redis.conf`:
4644

4745
```
4846
maxmemory 100mb
4947
```
5048

49+
You can also use [`CONFIG SET`]({{< relref "/commands/config-set" >}}) to
50+
set `maxmemory` at runtime using [`redis-cli`]({{< relref "/develop/connect/cli" >}}):
51+
52+
```bash
53+
> CONFIG SET maxmemory 100mb
54+
```
55+
5156
Set `maxmemory` to zero to specify that you don't want to limit the memory
52-
for the dataset. This is the default behavior for 64 bit systems, while 32 bit
57+
for the dataset. This is the default behavior for 64-bit systems, while 32-bit
5358
systems use an implicit memory limit of 3GB.
5459

5560
When the size of your cache exceeds the limit set by `maxmemory`, Redis will
@@ -59,21 +64,21 @@ further growth of the cache.
5964
### Setting `maxmemory` for a replicated instance
6065

6166
If you are using replication for an instance, Redis will use some
62-
RAM as a buffer to store the set of updates that must be written to the replicas.
63-
The memory used by this buffer is not included in the used memory total that
67+
RAM as a buffer to store the set of updates waiting to be written to the replicas.
68+
The memory used by this buffer is not included in the total that
6469
is compared to `maxmemory` to see if eviction is required.
6570

6671
This is because the key evictions themselves generate updates that must be added
6772
to the buffer to send to the replicas. If the updates were counted among the used
6873
memory then in some circumstances, the memory saved by
69-
evicting keys would be immediately used up by the new data added to the buffer.
74+
evicting keys would be immediately used up by the update data added to the buffer.
7075
This, in turn, would trigger even more evictions and the resulting feedback loop
7176
could evict many items from the cache unnecessarily.
7277

7378
If you are using replication, we recommend that you set `maxmemory` to leave a
74-
little RAM free to store the replication buffers unless you are also using the
75-
`noeviction` policy (see [the section below](#eviction-policies) for more
76-
information about eviction policies).
79+
little RAM free to store the replication buffers. Note that this is not
80+
necessary for the `noeviction` policy (see [the section below](#eviction-policies)
81+
for more information about eviction policies).
7782

7883
## Eviction policies
7984

@@ -82,9 +87,9 @@ policy you want to use when the limit set by `maxmemory` is reached.
8287

8388
The following policies are available:
8489

85-
- `noeviction`: Keys are not evicted but the server won't execute any commands
86-
that add new data to the cache. If your database uses replication then this
87-
condition only applies to the primary database. Note that commands that only
90+
- `noeviction`: Keys are not evicted but the server will return an error
91+
when you try to execute commands that cache new data. If your database uses replication
92+
then this condition only applies to the primary database. Note that commands that only
8893
read data still work as normal.
8994
- `allkeys-lru`: Evict the [least recently used](#apx-lru) (LRU) keys.
9095
- `allkeys-lfu`: Evict the [least frequently used](#lfu-eviction) (LFU) keys.
@@ -99,8 +104,7 @@ The following policies are available:
99104
shortest remaining time-to-live (TTL) value.
100105

101106
The `volatile-xxx` policies behave like `noeviction` if no keys have the `expire`
102-
field set to true, or if no keys have a time-to-live value set in the case of
103-
`volatile-ttl`.
107+
field set to true, or for `volatile-ttl`, if no keys have a time-to-live value set.
104108

105109
You should choose an eviction policy that fits the way your app
106110
accesses keys. You may be able to predict the access pattern in advance

0 commit comments

Comments
 (0)