In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the redis cache avalanche, cache breakdown, cache penetration refers to what it means, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
What is redis caching?
Redis cache is an open source API that is written in ANSI C language, supports the network, can be memory-based and persistent, Key-Value database, and provides multiple languages.
What is the purpose of redis caching?
The use of Redis cache greatly improves the performance and efficiency of applications, especially in data query. But at the same time, it also brings some problems. Among them, the most crucial problem is the consistency of data. Strictly speaking, there is no solution to this problem. If there is a high requirement for data consistency, then caching cannot be used.
Other typical problems are cache penetration, cache avalanche, and cache breakdown. At present, there are more popular solutions in the industry. The purpose of this article is not to solve these three problems more perfectly, nor to subvert the popular solutions in the industry. Instead, from the actual code operation, to demonstrate these three problem phenomena. The reason for doing this is that just looking at the academic explanation of these issues, it is difficult to have a very vivid concept in mind, with the actual code demonstration, we can deepen the understanding and understanding of these problems.
Cache penetration
Cache traversal refers to querying data that must not exist in a database. The normal process of using caching is that data query is first cached. If key does not exist or key has expired, then query the database, and put the queried objects into the cache. If the database query object is empty, it is not cached.
Code flow
1. The parameter is passed into the object primary key ID
2. Get the object from the cache according to key
3. If the object is not empty, return it directly
4. If the object is empty, query the database
5. If the object queried from the database is not empty, put it in the cache (set the expiration time) and imagine this situation. What if the parameter passed in is-1? This-1 is an object that must not exist. The database is queried every time, and each query is empty and not cached each time. If there is a malicious attack, you can take advantage of this loophole to cause pressure on the database, or even crush the database. Even with UUID, it is easy to find a non-existent KEY to attack.
In the work, the editor will use the method of caching null values, that is, step 5 in [Code flow]. If the object queried from the database is empty, it will also be put into the cache, but the cache expiration time is set to be short, such as 60 seconds.
(learn video sharing: redis video tutorial)
Cache avalanche
Cache avalanche means that the cache set expires in a certain period of time.
One of the reasons for the avalanche, for example, at the time of writing, it will soon be double 12: 00, and there will soon be a wave of rush buying. This wave of product time is concentrated in the cache, assuming that it is cached for an hour. Then by 01:00 in the morning, the cache of these goods will have expired. And the access query for this batch of goods, all fall on the database, for the database, it will produce periodic pressure peaks.
When the editor is doing e-commerce projects, he usually takes different categories of goods and caches different cycles. Goods in the same category, plus a random factor. In this way, the cache expiration time can be dispersed as much as possible, and the cache time of popular categories is longer, while that of cold categories is shorter, and the resources of cache services can be saved.
In fact, centralized expiration is not very fatal, but the more deadly cache avalanche is the downtime or network outage of a node in the cache server. Because of the natural cache avalanche, the cache must be created in a certain period of time, so the database can withstand the pressure at that time. It's just a cyclical pressure on the database. The downtime of the cache service node, the pressure on the database server is unpredictable, and it is likely to crush the database instantly.
Cache breakdown
Cache breakdown means that a key is very hot, constantly carrying large concurrency and focusing on accessing this point. When the key fails, the persistent large concurrency breaks through the cache and requests the database directly, just like cutting a hole in a barrier.
When the editor is working on an e-commerce project, he makes it a "popular style".
In fact, in most cases, this popular style is difficult to cause crushing pressure on the database server. There are few companies that have reached this level. Therefore, the pragmatic editor is ready early for the main products, so that the cache will never expire. Even if some goods ferment into a popular style by themselves, it would be nice to set them to never expire.
From avenue to simplicity, mutex key mutexes are really useless.
Thank you for reading this article carefully. I hope the article "what is the meaning of cache avalanche, cache breakdown and cache penetration in redis" shared by the editor is helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.