Original: The LRU mechanism of Redis
In Redis, if you set the MaxMemory, it is necessary to configure the key recycle mechanism parameter maxmemory-policy, default VOLATILE-LRU, see the original blog of the Redis Author: Antirez Weblog >> Redis As an LRU cache
The original text is clearly written:
Another-use Redis as a cache is the maxmemory directive, a feature that allows specifying a maximum amount of memory to use. When 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, that's, a key with an EXPIRE (a timeout) set, even if the key was still far from expiring AUT Omatically.
When the Redis server consumes memory up to MaxMemory, when you want to increase the memory footprint, the old data is deleted by the maxmemory-policy mechanism. Here's a quick Volatile-lru,redis. The LRU algorithm removes the key that set the expiration time but has not expired, and the Key,redis that has not set the expiration time is always preserved. Of course, if you don't want to delete a key that doesn't expire, you can use the noeviction mechanism
# maxmemory Policy:how Redis would 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 an 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
The LRU mechanism of Redis (GO)