I have thousands of related keys set with same ttl.
Once maxmemory is reached, does volatile-lru evict all the keys sharing the same ttl or just what it needs to make space for new data?
Related
I am experiencing a very strange case happen in production with redis, a large amount of redis keys are evicted unexpectedly even though memory not reach max configuration.
Current redis setting is max mem = 7GB, volatile-ttl.
Most of the keys are set a TTL when store to Redis.
Below graph showing a large drop in redis key eventhough memory at the time was only 3.5GB (<< 7GB)
According to my understanding, Redis would evict keys only when memory reach max-mem. And even when it does, it will only drop keys gradually according to the need for inserting new keys.
Thank you very much!
I have a question on Redis cache's behavior. Kindly clarify -
Say, for a key "xyz" if the TTL is set to 15 minutes.
And, if its eviction policy in server level is set to "allkeys-lru". Does expired items(cause of TTL) EXPIRE or WAIT until the memory is full?
The eviction policy only applies to what happens when you exceed the max memory. As long as you're within your memory limits, volatile keys will expire when they should be expired.
Once your memory is full, an LRU algorithm kicks in, evicting least recently used keys. In allkeys-lru, it doesn't matter whether a key is expired or not and what is the TTL - the least used items will be evicted. In volatile-lru only expiring keys will be evicted using this algorithm.
If I have several hashes on Redis, each with keys that expire in 24 hours, if memory runs out while using an eviction policy like allkeys-lru, will Redis remove an entire hash or single keys?
Redis only supports expiration at the key's level. Therefore, once set with a TTL, your key that contains a hashmap will be expired entirely (all child fields will be gone with it). The same goes for the other Redis data types (e.g. Sets and Lists).
If you use Hashes for storing key names that need to expire, simply set the TTL for each such key name individually instead of for the Hash's key.
Is there a way to make Redis choose a LRU (least recently used) eviction policy for only specific keys? I want a set of keys to be persistent and never be evicted if there's not enough memory. On the other hand, I want another set of keys to be freely evicted if there's low memory.
Redis has an eviction policy which might be good for your case.
You can set the maxmemory-policy to volatile-lru which causes Redis to:
remove the key with an expire set using an LRU algorithm
Which means that keys that are not set with TTL are not volatile, and therefor will not be evicted but keys that have TTL will be removed by Least-Recently-Used order.
Actually, volatile-lru is the default policy, so all you have to do is to make sure TTL is set for the keys you are willing to lose when memory is getting full.
Edit: Since version 3.0 the default eviction policy is "noeviction". (changelog)
While executing the info command in redis-cli, all the information related to that server is listed. What is the purpose of "evicted_keys"?
Redis can be configured to automatically purge keys as necessary. If so configured, redis will only use a maximum amount of memory, and if it nears the limit, remove keys per some criteria. See Redis as an LRU cache by antirez.
It can be configured to only remove keys that have an expiry time, or all keys. It can remove keys soon to be expired, last recently used keys, or random keys.
evicted_keys in the info is the number of keys that have been evicted (removed).