We know that Redis sets the maxmemory parameter of the configuration file to control its maximum available memory size (bytes).
What if the required memory exceeds MaxMemory ?
This time the maxmemory-policy in the configuration file appeared.
Its default value is noeviction.
Below I will list the elimination rules that are available when the Redis key is removed when there is not enough free memory.
Rule name |
Rule description |
Volatile-lru |
Remove a key using the LRU algorithm (only for keys that have a time-to-live setting) |
Allkeys-lru |
Remove a key using the LRU algorithm |
Volatile-random |
Randomly delete a key (only for keys that have a time-to-live setting) |
Allkeys-random |
Randomly delete a key |
Volatile-ttl |
Delete one of the most recent keys to survival time |
Noeviction |
Do not delete keys, only return errors |
The LRU algorithm , least recently used, is the least recently used algorithm . This means that the least recently used key is deleted by default.
But be sure to pay attention to a little ! Instead of accurately deleting the least recently used keys in all keys, Redis randomly extracts 3 keys , removing the least recently used keys from the three keys.
Then 3 this number can also be set, the corresponding location is the maxmeory-samplesin the configuration file.
How does Redis require more memory than is available?