Reputation: 3689
Is Redisson's getLock()
method good for a distributed use case, and how does it compare to getRedLock()
?
Redisson (3.11.x) has several methods to instantiate locks:
getReadWriteLock()
, getFairLock()
, etc.What algorithm does getLock()
use, and is it safe for distributed usage? The documentation says:
Implements a non-fair locking so doesn't guarantees an acquire order by threads.
I am looking to compare getLock()
to getRedLock()
, which appears to use Redlock and is documented at the top-level of Redis' distlock
page: https://redis.io/topics/distlock:
This page is an attempt to provide a more canonical algorithm to implement distributed locks with Redis. We propose an algorithm, called Redlock, which implements a DLM which we believe to be safer than the vanilla single instance approach.
Upvotes: 1
Views: 4727
Reputation: 10793
Is Redisson's getLock() method good for a distributed use case, and how does it compare to getRedLock()?
All Redisson locks fit for distributed use case. RedLock algorithm assumes that you have lock per master node in cluster. RedLock algorithm is proposition and unfortunately there are no feedbacks of its practice usage. Except of its analisys https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html
What algorithm does getLock() use, and is it safe for distributed usage?
RLock
object stored as single object in Redis. Other threads are notified through pubsub listeners if lock released. There is also lockWatchdogTimeout setting allows to define time after which lock will be forced to release if current thread is not alive.
UPDATE Since 3.12.5 version getLock() method returns Lock with improved reliability during failover. getRedLock() has been deprecated.
Upvotes: 2