In Redis, if set maxmemory, it is necessary to configure the key recovery mechanism parameters Maxmemory-policy, default VOLATILE-LRU, see Redis author's original blog: Antirez weblog >> Redis As an LRU cache
It is clearly written in the original text:
Copy Code code as follows:
Another way to use Redis as a cache are the MaxMemory directive, a feature that allows specifying a maximum amount of memor Y to use. When the new data are added to the server, and the memory limit was already reached, the server would remove some old data delet ing a volatile key, which, a key with a EXPIRE (a timeout) set, even if the key is still far from expiring Automaticall Y.
When the Redis server takes up memory to MaxMemory, when you want to increase the memory footprint, the old data will be deleted by the maxmemory-policy mechanism. Here's a brief volatile-lru,redis will press the LRU algorithm to delete the set expiration time but has not expired key, and for the Key,redis that have not set expiration time is reserved forever. Of course, if you don't want to delete a key that doesn't expire, you can use the noeviction mechanism
Copy Code code as follows:
# maxmemory Policy:how Redis'll select what to remove when maxmemory
# is reached? You can select among five behavior:
#
# VOLATILE-LRU-> Remove the key with a expire set using an LRU algorithm
# ALLKEYS-LRU-> Remove any key accordingly to the LRU algorithm
# volatile-random-> Remove a random key with a expire set
# allkeys-random-> Remove a random key, any key
# Volatile-ttl-> Remove the key with the nearest Expire time (minor TTL)
# noeviction-> don ' t expire at all, just return a error on write operations