What if the memory required by Redis exceeds the available memory?
We know that redis sets the configuration fileMaxmemoryParameter to control the maximum available memory size (in bytes ).
When the required memory exceedsMaxmemoryWhat should I do?
In this configuration fileMaxmemory-policyNow.
The default value isNoeviction.
Below I will list the elimination rules for deleting the redis key when the available memory is insufficient.
| Rule name |
Rule Description |
| Volatile-lru |
Use the LRU algorithm to delete a key (only the key with a life time set) |
| Allkeys-lru |
Deletes a key using the LRU algorithm. |
| Volatile-random |
Delete a random key (only the key with a life time set) |
| Allkeys-random |
Randomly delete a key |
| Volatile-ttl |
Deletes the key closest to the life cycle. |
| Noeviction |
If the key is not deleted, only an error is returned. |
LRU Algorithm, Least Recently Used,Least recently used algorithms. That is to say, the least recently used keys are deleted by default.
HoweverBe sure to note that! Redis does not accurately Delete the least recently used keys among all keys, but randomly selectsThree keysDelete the least recently used keys among the three keys.
The number 3 can also be set. The corresponding location is in the configuration file.Maxmeory-samples.