In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to realize RedLock". In daily operation, I believe many people have doubts about how to realize RedLock. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to realize RedLock"! Next, please follow the small series to learn together!
Redlock implementation
Suppose there are N Redis masters. These nodes are completely independent of each other, and there is no master-slave replication or other cluster coordination mechanism. We ensure that locks will be acquired and released on N instances in the same way as under Redis single instance. Now let's assume there are 5 Redis masters and we need to run these Redis instances on 5 servers so they don't all go down at the same time.
To obtain the lock, the client should perform the following actions:
Gets the current Unix time in milliseconds.
Try to acquire locks from five instances in turn, using the same key and unique value (such as UUID). When requesting a lock from Redis, the client should set a network connection and response timeout that is less than the lock expiration time. For example, if your lock has an automatic expiration time of 10 seconds, the timeout should be between 5 and 50 milliseconds. This prevents the client from waiting for a response when the server Redis has been hung up. If the server does not respond within the specified time, the client should try to acquire the lock from another Redis instance as soon as possible.
The client uses the current time minus the time to start acquiring the lock (recorded in step 1) to get the time to acquire the lock. A lock is acquired if and only if it is acquired from most (N/2+1, here 3 nodes) of the Redis nodes, and the time used is less than the lock expiration time.
If the lock is acquired, the true valid time of the key is equal to the valid time minus the time it took to acquire the lock (calculated in step 3).
If the lock acquisition fails for some reason (no lock has been acquired in at least N/2+1 Redis instances or the lock acquisition time has exceeded the validity time), the client should unlock all Redis instances (even if some Redis instances have not been successfully locked at all, preventing some nodes from acquiring locks but the client has not received a response and cannot be re-acquired for a period of time).
At this point, the study of "how to realize RedLock" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.