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.
How to make Redis choose LRU eviction policy for only some of the keys?
Redis allows you to set timeToLive at the key level. You could select the keys you want should expire in the application and set some appropriate expiration time. –
Indifference
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)
What if I have a
noeviction
policy but expire set on keys? –
Priesthood © 2022 - 2024 — McMap. All rights reserved.