redisdistributed-computingspring-data-redisredis-clusterdistributed-lock

Lock on redis cluster


I have a Redis cluster of 3 master nodes and each master has corresponding slave nodes. I would like to acquire a lock on the cluster to perform some write operations and then release the lock.

From what I've read is - To connect to a cluster we generally connect to one node in the cluster and perform all operations on that node which in-turn handles re-directing to other nodes in the cluster.

Is it possible to acquire lock on a Redis cluster? [P.S I am using Redisson client] From the examples in Redisson client under Multilock and redlock (https://github.com/redisson/redisson/wiki/8.-Distributed-locks-and-synchronizers), they are acquiring a lock on individual nodes.

Jedis also seems to have support for locking on the cluster (https://github.com/kaidul/jedis-lock).

P.S: I've read extensively on this, but I've not been able to find clear answers on locking on a cluster. Would really appreciate some help.


Solution

  • I found a solution to my question above.

    As far as we are using the same key to acquire a lock across all client nodes, all the attempts to acquire the lock will go to the same node on the Redis cluster. So you can just use simple Rlock from Redisson.

    See comments to this question: https://github.com/leandromoreira/redlock-rb/issues/63