What is complicated by competition 12.redis? how to solve this problem? Learn CAS redis affairs program do?

Author: Chinese Shi Shan

Interview questions

What is complicated by competition redis? how to solve this problem? Learn CAS redis affairs program do?

Interviewer psychological analysis

This line is also a very common problem is multi-client concurrent write a key, after probably should have first come to the data, leading to the wrong version of the data; or multiple clients at the same time get a key, and then modify the value after write back, as long as the order is wrong, wrong data.

Redis optimistic locking scheme and have their own natural solution to this problem CAS class.

Face questions analysis

At some point, multiple system instances to update a key. Distributed Lock can be achieved based zookeeper. Each system acquired by zookeeper distributed lock to ensure the same time, only one instance of the operating system a key, others are not allowed to read and write.

zookeeper-distributed-lock

You have to write cached data is found out from the mysql, mysql had to be written, the writing time mysql must be saved in a time stamp, check out the mysql time, also check out the time stamp.

Before each write, first determine what the current value of the timestamp is newer than the timestamp of the value of the cache. If so, you can write, otherwise, the old data can not be used to cover the new data.

Guess you like

Origin www.cnblogs.com/morganlin/p/11980483.html