diff --git a/docs/en/Distributed-Lock.md b/docs/en/Distributed-Lock.md index ff337b75eb..8593560b3d 100644 --- a/docs/en/Distributed-Lock.md +++ b/docs/en/Distributed-Lock.md @@ -1,16 +1,20 @@ # Distributed Lock Distributed locks are very useful to manage many processes that request the same object. -They are used to handle conflict between these requests. Once obtaining anyone it, the others need to wait till give up free. +In a normal case, accessing the same object from different threads or services can corrupt the value of objects. +In terms of accuracy, we may need to protect the value that's why a lock will be necessary. +On another hand, it will protect from more times triggered hence you will provide more efficiency. +To summarize, It's used to handle conflict between these requests. Once obtaining anyone it, the others need to wait till give up free. # Providers -`MedallionAbpDistributedLock` Distributed locks system provides an abstraction that can be implemented by any vendor/provider. + + * `MedallionAbpDistributedLock` ABP depends on [DistributedLock.Core](https://www.nuget.org/packages/DistributedLock.Core) library which provides a distributed locking system for concurrency control in a distributed environment. There are [many distributed lock providers](https://github.com/madelson/DistributedLock#implementations) including Redis, SqlServer and ZooKeeper. You may use the one you want. Here, I will show the Redis provider. This provider contains a method named TryAcquireAsync and this method returns null if the lock could not be handled. > Name is a mandatory field. It keeps the locked provider name. > Timeout is set as default. If it fells deadlock and doesn't work properly you can use define the time to kill it. ->CancellationToken is set as default. It enables cooperative cancellation between threads, thread pool work items, or Task objects +> CancellationToken is set as default. It enables cooperative cancellation between threads, thread pool work items, or Task objects Also, you should add [DistributedLock.Redis](https://www.nuget.org/packages/DistributedLock.Redis) NuGet package to your project, then add the following code into the ConfigureService method of your ABP module class. @@ -44,10 +48,10 @@ Also, you should add your Redis configuration in appsetting.json } ```` -> To use in APB, you should download the below NuGet package. +> To use in ABP, you should download the below NuGet package. It already contains DistributedLocking.Abstractions and no need to download as well. ````powershell -Install-Package Volo.Abp.DistributedLocking -Version 5.1.4 +abp add-package Volo.Abp.DistributedLocking ```` ````csharp @@ -61,12 +65,17 @@ namespace AbpDemo { _distributedLock = distributedLock; } - - await using (var handle = await _distributedLock.TryAcquireAsync("NameOfLock")) + + public async Task MyMethodAsync() { - if (handle != null) + await using (var handle = await _distributedLock.TryAcquireAsync("NameOfLock")) { - //your code - } + if (handle != null) + { + //your code + } + } } + } +} ```` \ No newline at end of file