|
| 1 | +--- |
| 2 | +myst: |
| 3 | + html_meta: |
| 4 | + description: Changing the Redis eviction policy on Hypernode with hypernode-systemctl. |
| 5 | + Learn which policies are available and how to verify the active Redis maxmemory-policy. |
| 6 | + title: Changing the Redis eviction policy on Hypernode |
| 7 | +--- |
| 8 | + |
| 9 | +# Changing the Redis eviction policy |
| 10 | + |
| 11 | +You can change the Redis `maxmemory-policy` with `hypernode-systemctl settings redis_eviction_policy`. This policy determines which keys Redis can evict when memory is full. |
| 12 | + |
| 13 | +## Available policies |
| 14 | + |
| 15 | +The following values are supported for `redis_eviction_policy`: |
| 16 | + |
| 17 | +- `noeviction` |
| 18 | +- `allkeys-lru` |
| 19 | +- `allkeys-lfu` |
| 20 | +- `allkeys-random` |
| 21 | +- `volatile-lru` |
| 22 | +- `volatile-lfu` |
| 23 | +- `volatile-ttl` |
| 24 | +- `volatile-random` |
| 25 | + |
| 26 | +```{infomation} |
| 27 | +By default, Redis on Hypernode uses the `volatile-lru` eviction policy. |
| 28 | +``` |
| 29 | + |
| 30 | +## Check the current policy |
| 31 | + |
| 32 | +To view the current Redis eviction policy: |
| 33 | + |
| 34 | +```bash |
| 35 | +hypernode-systemctl settings redis_eviction_policy |
| 36 | +``` |
| 37 | + |
| 38 | +## Change the policy |
| 39 | + |
| 40 | +Use the following command to change the Redis eviction policy: |
| 41 | + |
| 42 | +```bash |
| 43 | +hypernode-systemctl settings redis_eviction_policy <policy> |
| 44 | +``` |
| 45 | + |
| 46 | +For example: |
| 47 | + |
| 48 | +```bash |
| 49 | +hypernode-systemctl settings redis_eviction_policy allkeys-lru |
| 50 | +``` |
| 51 | + |
| 52 | +## Policy explanation |
| 53 | + |
| 54 | +### `noeviction` |
| 55 | + |
| 56 | +Redis will not evict any keys when memory is full. New write operations |
| 57 | +that require memory will fail. |
| 58 | + |
| 59 | +### `allkeys-lru` |
| 60 | + |
| 61 | +Redis can evict any key and removes the least recently used keys first. |
| 62 | + |
| 63 | +### `allkeys-lfu` |
| 64 | + |
| 65 | +Redis can evict any key and removes the least frequently used keys first. |
| 66 | + |
| 67 | +### `allkeys-random` |
| 68 | + |
| 69 | +Redis can evict any key and removes keys at random. |
| 70 | + |
| 71 | +### `volatile-lru` |
| 72 | + |
| 73 | +Redis only evicts keys with an expiration time and removes the least |
| 74 | +recently used keys first. |
| 75 | + |
| 76 | +This is the default policy on Hypernode. |
| 77 | + |
| 78 | +### `volatile-lfu` |
| 79 | + |
| 80 | +Redis only evicts keys with an expiration time and removes the least |
| 81 | +frequently used keys first. |
| 82 | + |
| 83 | +### `volatile-ttl` |
| 84 | + |
| 85 | +Redis only evicts keys with an expiration time and prefers keys that will |
| 86 | +expire soonest. |
| 87 | + |
| 88 | +### `volatile-random` |
| 89 | + |
| 90 | +Redis only evicts keys with an expiration time and removes those keys at |
| 91 | +random. |
| 92 | + |
| 93 | +## Important considerations |
| 94 | + |
| 95 | +- Eviction only takes place when Redis reaches its memory limit. |
| 96 | +- Policies starting with `allkeys-` can evict any key, including keys without a TTL. |
| 97 | +- Even with an `allkeys-` policy, Redis can still run into memory pressure if keys cannot be evicted fast enough to keep up with writes. |
| 98 | +- Setting a TTL on cache keys is still recommended, even when using an `allkeys-` policy. |
| 99 | +- Policies starting with `volatile-` only apply to keys with a TTL. |
| 100 | +- If not enough keys have a TTL, Redis may not be able to evict enough data with a `volatile-` policy, and write operations may fail. |
| 101 | +- Changing the policy does not remove existing keys immediately. |
0 commit comments