In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How to deal with the expiration policy of redis? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
You can set the expiration time of the data through the EXPIRE key seconds command. A return of 1 indicates that the setting is successful, and a return of 0 indicates that key does not exist or the expiration time cannot be set successfully. When the expiration time is set on the key, the key is automatically deleted after the specified number of seconds. Key with an expiration time specified is said to be unstable in Redis.
There are three ways for Redis key to expire:
Lazy deletion
Delete periodically
Memory elimination mechanism
Timed expiration: each key that sets the expiration time needs to create a timer that will be cleared immediately when it expires. This strategy can clean up expired data immediately and is memory-friendly, but it takes up a lot of CPU resources to process expired data, thus affecting the response time and throughput of the cache.
Lazy expiration: it is only when a key is accessed that it is determined whether the key has expired or is cleared when it expires. This strategy maximizes the savings in CPU resources, but is very memory-friendly. In extreme cases, there may be a large number of expired key that are not accessed again, so that they are not cleared and take up a lot of memory.
Periodic expiration: at regular intervals, a certain number of expires dictionaries in a certain number of databases are scanned for a certain number of key, and the expired key is cleared. This strategy is a compromise between the first two. By adjusting the time interval of timing scanning and the limited time of each scan, the optimal balance between CPU and memory resources can be achieved under different conditions.
(the expires dictionary holds expiration time data for all key with an expiration time set, where key is a pointer to a key in the key space, and value is the expiration time represented by that key's millisecond precision UNIX timestamp. Key space refers to all keys saved in the Redis cluster.)
Both lazy expiration and periodic expiration are used in Redis.
After reading the above, have you mastered the method of dealing with the expiration policy of redis? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.