In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the common problems in Redis". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the common problems in Redis.
With the increase of system access volume and complexity, response performance has become a key concern. The use of caching has become a focus. As a leader of caching middleware, redis has become a required interview project.
In this article, we share some common interview questions for Redis:
Cache Avalanche 1.1 what is a cache avalanche?
If our cache is down, it means that all our requests have gone to the database.
We all know that Redis cannot cache all the data (memory is expensive and limited), so Redis needs to set an expiration time for the data and use the lazy delete + periodic delete strategy to delete expired keys.
If the expiration time of the cached data setting is the same, and Redis happens to delete all of the data. This will cause these caches to expire at the same time, and all requests will be made to the database.
This is the cache avalanche: Redis is dead, request all to go to the database.
If the cache avalanche happens, it is likely to bring down our database and paralyze the entire service!
1.2 how to solve the cache avalanche?
Add a random value to the expiration time when caching, which will greatly reduce the cache expiration at the same time.
For the case that "Redis is dead, request all to go to the database", we can have the following ideas:
Before the incident: achieve the high availability of Redis (master-slave architecture + Sentinel or Redis Cluster) and try to avoid the occurrence of Redis hanging.
Incident: in case Redis really fails, we can set local cache (ehcache) + current limit (hystrix) to prevent our database from being killed (at least to ensure that our service can work properly).
After the incident: redis persists, automatically loads data from disk after restart, and quickly recovers cached data.
Cache Penetration 2.1 what is cache traversal
Cache traversal refers to querying a data that must not exist. Because the cache misses, and for the sake of fault tolerance, if the data cannot be found from the database, the cache will not be written, which will cause the non-existent data to query to the database every time, which loses the meaning of the cache.
This is cache penetration:
A large number of requested data misses in the cache, causing the request to go to the database.
If cache penetration occurs, it may also bring down our database and paralyze the entire service!
2.2 how to solve cache penetration?
There are also two solutions to cache traversal:
Since the requested parameter is illegal (a parameter that does not exist is requested every time), we can use a Bloom filter (BloomFilter) or compressed filter to intercept in advance. If it is illegal, we will not allow the request to go to the database layer!
When we can't find it from the database, we also set this empty object to the cache. The next time you request it, you can get it from the cache.
In this case, we usually set empty objects for a short expiration time.
Cache and database double write consistency 3.1 for read operations, the process is like this
If our data is in the cache, then take the cache directly.
If there is no data we want in the cache, we will first query the database, and then write the data found in the database to the cache. Finally, the data is returned to the request.
3.2 what is the problem of double write consistency between cache and database?
If you only query, the cached data and database data will be fine. But when we want to update? Various situations are likely to cause inconsistencies between the database and the cached data.
The inconsistency here means that the data in the database is inconsistent with the cached data.
In theory, as long as we set the expiration time of the key, we can ensure that the data of the cache and the database are ultimately consistent. Because as long as the cached data expires, it will be deleted. When reading later, because it is not in the cache, you can check the data in the database, and then write the data found in the database to the cache.
In addition to setting the expiration time, we need to do more to avoid database inconsistencies with the cache as much as possible.
At this point, I believe you have a deeper understanding of "what are the common problems in Redis?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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.