Reprint: MySQL and Redis data synchronization solution Finishing

Source: Internet
Author: User
Tags message queue

from:http://blog.csdn.net/langzi7758521/article/details/52611910

Recently in making a Redis box information data synchronization function to the database MySQL.

I think about it, there are probably plans.

1. Queue synchronization, change data to 2 copies, use Message Queuing, one for redis consumption, one for MySQL consumption.

2. Background timer task, periodically refresh the Redis in the box information to the database.

Online also looked for the next solution, found such a problem, incredibly is the world a big copy, but also copy the word is not bad, I also copied it.

Programme one:

READ: Read redis-> No, read mysql-> write MySQL data back to Redis

Write: Write mysql-> success, write Redis.

Just read, read Redis,redis no longer read the database, put the data in the database into Redis.

Write (add and revise), write the database first, and then write Redis.

This can be slightly optimized, such as requiring consistent data, reading from a database, such as finance, transaction data. Strong consistency is not required to read from the Reids.

Scenario Two:

Use Mysql_udf_redis based on Binlog to synchronize the data in the database to Redis.

Programme III:

Based on MQ, which is the top thought of the way 1.

Programme IV:

The official has a memcached UDF plugin, if not so strongly to Redis, you can also consider

If it is I choose 2, by the way recommended to send the big God ads: http://coolshell.cn/articles/17416.html

Programme V:

Replace Mysql +redis with PostgreSQL.

Disadvantages of various schemes

But the above plan has its own drawbacks.

Scenario one, obviously for the large amount of data, update frequent data write powerless. such as the E-stack terminal box, the number of boxes is huge, each box with the change of state and very frequent, so it is easy to write the database to hang.

Scenario two, which is using the MySQL user Defined function feature, Mysql_udf_redis is someone who realizes the ability to synchronize data to Redis, the drawback: the need for learning costs, and the third-party plugins are unstable.

Scenario three: How to guarantee the consistency of the state to the database and to the Redis. is to assume that a modified data is written from the queue to MySQL success, but the write to Redis fails, this is how. There is the need for a message queue, using third-party such as KAFKA,RABBITMQ, such as to achieve, management is not convenient, the overall stability of the system is not, and just such a relatively small box data synchronization. A little overkill.

Other options:

Subscribe to the change of key database update, write 2 copies, one to Redis write, one is the Redis Data key network update queue (also can be directly reids) write, and then write a timed program from the update queue to take the time, according to key to remove Redis data to MySQL.

This scheme, in fact, and other different, the disadvantage is that the memory is large, because the need to maintain an update queue.

Finally, my superiors are talking about using timed tasks to brush the bin state information in Redis to the database. 2W terminal, a terminal 100 boxes, 200W boxes, the first is to make a state-to-state, inconsistent status of put into the collection, batch update database.

In fact, there will be small problems, such as in the comparison of the time:

1.Redis in the case of the state has changed, how to do? It is impossible to lock the redis,200w cycle in the right time, and it is possible that the state will be changed.

2. In the comparison, someone updated the database, what to do? Because some operations can update the database directly. such as updating the box Layoutrow information.

From: http://3gods.com/2016/06/23/Redis-Sync-DB.html

Reference: http://coolshell.cn/articles/17416.html

Http://www.cnblogs.com/linjiqin/p/3569011.html

Reprint: MySQL and Redis data synchronization solution Finishing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.