The DistributedLock.ZooKeeper package offers distributed locks based on Apache ZooKeeper. For example:
var @lock = new ZooKeeperDistributedLock("MyLockName", connectionString);
await using (await @lock.AcquireAsync())
{
// I have the lock
}- The
ZooKeeperDistributedLockclass implements theIDistributedLockinterface. - The
ZooKeeperDistributedReaderWriterLockclass implements theIDistributedReaderWriterLockinterface. - The
ZooKeeperDistributedSemaphoreclass implements theIDistributedSemaphoreinterface. - The
ZooKeeperDistributedSynchronizationProviderclass implements theIDistributedLockProvider,IDistributedReaderWriterLockProvider, andIDistributedSemaphoreProviderinterfaces.
ZooKeeper-based locks leverage ZooKeeper's recommended recipes for distributed synchronization.
By leveraging ZooKeeper watches under the hood, these recipes allow for very efficient event-driven waits when acquiring.
SessionTimeoutconfigures the underlying session timeout value for ZooKeeper connections. Because the underlying ZooKeeper client periodically renews the session, this value generally will not impact behavior. Lower values mean that locks will be released more quickly following a crash of the lock-holding process, but also increase the risk that transient connection issues will result in a dropped lock. Defaults to 20s.ConnectTimeoutconfigures how long to wait when establishing a connection to ZooKeeper. Defaults to 15s.AddAuthInfoallows you to specify additional auth information to be added to the ZooKeeper session. This option can be specified multiple times to add multiple auth schemes.AddAccessControlconfigures the ZooKeeper ACL for nodes created by the lock. This option can be specified multiple times to add multiple ACL entries. If left unspecified, the ACL used is (world, anyone).