redis Advantages and disadvantages of distributed lock

shortcoming :

* The way to acquire locks is simple and rough , If you can't get the lock, try to get the lock continuously , Compare consumption performance ;
* redis Its design positioning determines that its data is not strongly consistent , In some extreme cases , There may be problems . The lock model is not robust enough ;
* use redlock Algorithm , In some complex scenes , There is no guarantee of its realization 100% no problem , about redlock You can see the discussion of How to do
distributed locking;
* redis Distributed lock , In fact, you need to keep trying to get the lock yourself , Compare consumption performance .
zookeeper Advantages and disadvantages of distributed lock


* zookeeper Natural design positioning is distributed coordination , Strong consistency . The model of lock is robust , Easy to use , Suitable for distributed locks ;
* If the lock cannot be obtained , Just add a listener , Don't poll all the time , Low performance consumption .

* Many clients frequently apply for locking , Release lock , about zookeeper The pressure of clusters will be relatively high .

        By comparing the advantages and disadvantages of the above two distributed locks , How should we choose the model ?

        Personally speaking , Quite respected zookeeper Distributed lock , because redis There may be hidden dangers , Conditions that may cause incorrect data . however , How to choose depends on the specific company scenario .

  If the company has zookeeper Cluster conditions , Preferred zookeeper realization . If the company only has redis colony , No conditions to build zookeeper colony , Then use redis To achieve it .