DistributedLock
DistributedLock copied to clipboard
Composite locks
This pull request introduces new composite lock methods for various lock types via code generation.
Auto Generated Codes
src/DistributedLock.Core/DistributedLockProviderExtensions.cssrc/DistributedLock.Core/DistributedReaderWriterLockProviderExtensions.cssrc/DistributedLock.Core/DistributedSemaphoreProviderExtensions.cssrc/DistributedLock.Core/DistributedUpgradeableReaderWriterLockProviderExtensions.cs
Is there a better alternative to this PR?
@madelson
Hi! Sorry for the delay - I was busy and totally forgot about this. I've now resolved all the comments and added the tests as discussed. The PR should be ready for another review. Thanks for your patience!
Sample use with the Redis Provider:
var connection = await ConnectionMultiplexer.ConnectAsync("localhost:6379");
var provider = new RedisDistributedSynchronizationProvider(connection.GetDatabase());
const string FromAccount = "account:alice";
const string ToAccount = "account:bob";
const decimal Amount = 100m;
var accounts = new[] { FromAccount, ToAccount };
await using (var handle = await provider.TryAcquireAllLocksAsync(accounts, TimeSpan.FromSeconds(30)))
{
if (handle != null)
{
Console.WriteLine($"Transferring ${Amount} from {FromAccount} to {ToAccount}");
await Task.Delay(1000);
Console.WriteLine("Transfer completed successfully");
}
else
{
Console.WriteLine("Failed to acquire locks - transfer aborted");
}
}
await connection.CloseAsync();
@moeen Dear Boss, could you please merge the code and provide the nget feature? I really need this functionality—thank you very much!