In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the methods of synchronizing the database with redis cache. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
The consistency of cached data and persistent data is summed up (see a good blog post), which is actually reading and writing, and paying attention to the question of who comes first and who comes later.
In theory, setting an expiration time for the cache is the solution to ensure ultimate consistency. Under this scheme, we can set the expiration time for the data stored in the cache. All write operations are based on the database, and we just try our best to cache the data.
That is, if the database is successfully written and the cache update fails, as long as the expiration time is reached, the subsequent read request will naturally read the new value from the database and backfill the cache.
Redis is a high-performance key-value database. The emergence of redis makes up for the deficiency of key-value storage such as memcached to a great extent, and can play a good complementary role to relational database in partial situations. It provides a python,Ruby,Erlang,PHP client and is easy to use.
According to our general scenario of using Redis, it should look like this:
In other words, we will first go to redis to determine whether the data exists, and if so, we will directly return the cached data. If it does not exist, it will go to the database, read the data, and cache the data in Redis.
Applicable situation: if the amount of data is large, but not updated frequently (such as user ranking)
The use of the second Redis is different from that of the first. For more information, please see:
Here, we will first go to redis to determine whether the data exists, and if so, directly update the corresponding data (this step will record the updated key, for example, save it to redis, such as: key: save_update_keys [record with lpush list]), and return the updated data to the page. If it does not exist, it will update the contents of the database first, and then save a copy of the data to Redis.
NO10 this step: the following work: there will be a relevant mechanism in the background to read out the key stored in save_update_keys in Redis, find the corresponding data, and update it to DB.
Pros: the main purpose of this process is to use Redis as a database and update data faster than DB. Ideal for frequent changes in a large amount of data (such as Weibo).
Disadvantages: it depends heavily on Redis, so it is necessary to save the data in case of downtime. (however, you can use redis's snapshot AOF, and fast recovery should not have much impact, because even if the Redis does not work, it will not affect the processing of subsequent data.)
Difficulty: when planning the format of the key, the storage type is important because it affects whether the data can be synchronized to the DB.
On the redis cache synchronization database method to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.