I am using RedLock.net library for resource locking. To lock a resoruce I am using RedLockFactory.CreateLockAsync.
public async Task<IRedLock> RedLockFactory.CreateLockAsync(string resource,
TimeSpan expiryTime,
TimeSpan waitTime,
TimeSpan retryTime,
CancellationToken? cancellationToken = null)
I understand that this method will attempt to acquire a lock for waitTime
by keep retrying every retryTime
. However I do not understand what would be the right value for expiryTime
.
Once a lock has been acquired it will be kept until the lock is Dispose
d and that is irrespective of the expiryTime
. In other words even if expirtyTime
is set to 5 seconds if the lock is only diposed after 10 seconds then the lock will be kept for 10 seconds.
In many examples the value of 30 is used without explanation.
I have tested with a value of 0. A lock is not acquired at all.
I have tested with a value of 5 milliseconds. A lock is acquired and kept until disposed.
So how to choose the right value for the expiryTime
parameter? It seems to me that this parameter is unnecessary and any non zero positive value is ok.