In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares to you is about the two ways to implement caching in redis. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.
There are roughly two measures to implement caching in redis:
1. Script synchronization:
1. Write your own script to write database data to redis/memcached.
2. This involves the problem of real-time data change (real-time analysis of mysql row binlog), the canal of binlog incremental subscription to Alibaba, and the problem of data synchronization recovery after cache layer data loss / failure.
2. Implementation of the business layer:
1. Read the nosql cache layer first, then read the mysql layer without data, and write the data to nosql.
2, nosql layer to do many nodes distributed (consistent hash), and node failure alternative (multi-tier hash looking for neighboring alternative nodes), and data concussion recovered.
Analysis of database caching implemented by redis:
For the data that changes very quickly, if you still choose the traditional static cache mode (Memocached, File System, etc.) to display the data, there may be a lot of overhead in accessing the cache, which can not meet the needs very well, and the memory-based NoSQL database such as Redis is very suitable to serve as a container for real-time data.
However, there are often requirements for data reliability. Using MySQL as data storage will not cause data loss because of memory problems. At the same time, many functions can be realized by using the characteristics of relational database. So it's natural to think about whether MySQL can be used as the data storage engine and Redis as the Cache.
Data replication solutions from MySQL to Redis, whether MySQL or Redis, have their own data synchronization mechanism. The commonly used Master/Slave mode of MySQL is realized by the binlog of Master analyzed by Slave. This kind of data replication is actually an asynchronous process, but when the servers are all in the same private network, the asynchronous delay can be ignored.
Then in theory, you can use the same way to analyze the binlog file of MySQL and insert the data into Redis.
So here we choose a cheaper way to develop, borrow the mature MySQL UDF, put the MySQL data into Gearman first, and then synchronize the data to Redis through a PHP Gearman Worker written by yourself. It adds a lot of processes than the way of analyzing binlog, but it is cheaper to implement and easier to operate.
These are two ways for redis to implement caching, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.