In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what redis caching strategies are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
When using Redis as a cache, old data is automatically expelled if the memory space is full. This is the way memcached works by default, and most developers are familiar with it. LRU is the only recycling algorithm supported by Redis.
Expulsion strategy
When the maximum memory limit (maxmemory) is reached, Redis determines the specific behavior according to the policy configured by maxmemory-policy.
In the current version, the strategies supported by Redis 3.0 include:
Noeviction: do not delete the policy. If more memory is needed when the maximum memory limit is reached, an error message will be returned directly. Most write commands result in more memory consumption (with few exceptions, such as DEL).
Allkeys-lru: all key are common; priority is to delete the key that is least used recently (less recently used, LRU).
Volatile-lru: only those parts where expire is set; priority is given to deleting the key that has been least used recently (less recently used, LRU).
Allkeys-random: all key are common; randomly delete part of the key.
Volatile-random: only those parts where expire is set; randomly delete a portion of key.
Volatile-ttl: only those parts where expire is set; priority is given to deleting key with short remaining time (time to live,TTL).
If the key for expire is not set, the prerequisites (prerequisites) are not met; then the behavior of the volatile-lru, volatile-random, and volatile-ttl policies is basically the same as that of noeviction (do not delete).
You need to choose the appropriate expulsion strategy according to the characteristics of the system. Of course, during the run, you can also set the expulsion policy dynamically with the command, and monitor the cached miss and hit through the INFO command to tune.
Generally speaking:
If it is divided into hot data and cold data, allkeys-lru strategy is recommended. That is, some of the key are often read and written. If you are not sure about the specific business characteristics, then allkeys-lru is a good choice.
If you need to read and write all key in a loop, or if the access frequency of each key is about the same, you can use the allkeys-random policy, that is, the probability of reading and writing all elements is about the same.
If you want Redis to filter the key that needs to be deleted based on TTL, use the volatile-ttl policy.
Volatile-lru and volatile-random policies are mainly used in instances with both cache and persistent key. In general, in scenarios like this, two separate Redis instances should be used.
It's worth mentioning that setting expire consumes extra memory, so you can use memory more efficiently with the allkeys-lru policy, because you can no longer set the expiration time.
These are all the contents of the redis caching strategy. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.