EasilyNET.MongoDistributedLock.AspNetCore
1.8.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package EasilyNET.MongoDistributedLock.AspNetCore --version 1.8.4
NuGet\Install-Package EasilyNET.MongoDistributedLock.AspNetCore -Version 1.8.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasilyNET.MongoDistributedLock.AspNetCore" Version="1.8.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.MongoDistributedLock.AspNetCore --version 1.8.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EasilyNET.MongoDistributedLock.AspNetCore, 1.8.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EasilyNET.MongoDistributedLock.AspNetCore as a Cake Addin
#addin nuget:?package=EasilyNET.MongoDistributedLock.AspNetCore&version=1.8.4
// Install EasilyNET.MongoDistributedLock.AspNetCore as a Cake Tool
#tool nuget:?package=EasilyNET.MongoDistributedLock.AspNetCore&version=1.8.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EasilyNET.MongoDistributedLock.AspNetCore
EasilyNET.MongoDistributedLock.AspNetCore 让基于 EasilyNET.MongoDistributedLock 的使用更简单.
注册分布式锁服务,用来配置一些基本信息
// 使用默认配置
builder.Services.AddMongoDistributedLock();
// 自定义一些配置
builder.Services.AddMongoDistributedLock(op =>
{
op.DatabaseName = "test_locks";
op.MaxDocument = 100;
...
});
- 使用 IMongoLockFactory 来注入工厂服务
public class DistributedLockTest(IMongoLockFactory lockFactory)
{
public async Task<dynamic> AcquireLock()
{
// 这里使用一个随机的ID作为锁ID,相当于其他锁中的Key.用来区分不同的业务的锁,也可以将不同的业务类型放到MongoDB中存起来,然后再使用的时候再取获取这个id
const string lockId = "64d44afde4473b85a177084c";
var mongoLock = lockFactory.GenerateNewLock(ObjectId.Parse(lockId));
var acq = await mongoLock.AcquireAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(0));
try
{
if (acq.Acquired)
{
// 关键部分,它不能一次由任何服务器上的多个线程执行
// ...
// ...
}
else
{
// 超时!也许另一个线程没有释放锁...我们可以再试一次或抛出例外
}
}
finally
{
// 如果(acq.Acquired)无需手动操作
await mongoLock.ReleaseAsync(acq);
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- EasilyNET.MongoDistributedLock (>= 1.8.4)
-
net7.0
- EasilyNET.MongoDistributedLock (>= 1.8.4)
-
net8.0
- EasilyNET.MongoDistributedLock (>= 1.8.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.24.627.145 | 0 | 6/27/2024 |
3.24.620.160 | 61 | 6/20/2024 |
3.24.613.115 | 71 | 6/13/2024 |
3.24.612.95 | 65 | 6/12/2024 |
3.24.528.90 | 71 | 5/28/2024 |
3.24.522.84 | 83 | 5/22/2024 |
3.24.512.213 | 66 | 5/12/2024 |
3.24.508.112 | 88 | 5/8/2024 |
2.2024.428.71 | 79 | 4/28/2024 |
2.2024.427.1128 | 90 | 4/27/2024 |
2.2.72 | 93 | 4/14/2024 |
2.2.71 | 82 | 4/12/2024 |
2.2.8 | 78 | 4/26/2024 |
2.2.6 | 75 | 4/10/2024 |
2.2.5 | 95 | 3/26/2024 |
2.2.4 | 88 | 3/25/2024 |
2.2.3 | 86 | 3/24/2024 |
2.2.2 | 93 | 3/21/2024 |
2.2.1 | 98 | 3/20/2024 |
2.2.0 | 93 | 3/13/2024 |
2.1.9 | 90 | 2/21/2024 |
2.1.8 | 93 | 2/18/2024 |
2.1.7 | 86 | 2/16/2024 |
2.1.6 | 88 | 2/14/2024 |
2.1.5 | 95 | 2/14/2024 |
2.1.4 | 99 | 2/9/2024 |
2.1.3 | 113 | 2/8/2024 |
2.1.2 | 79 | 2/5/2024 |
2.1.1.2 | 158 | 12/26/2023 |
2.1.1.1 | 95 | 12/26/2023 |
2.1.1 | 108 | 12/25/2023 |
2.1.0 | 107 | 12/17/2023 |
2.0.11 | 122 | 12/6/2023 |
2.0.1 | 132 | 11/15/2023 |
2.0.0 | 106 | 11/14/2023 |
1.9.1 | 112 | 11/1/2023 |
1.9.0 | 106 | 10/19/2023 |
1.9.0-preview2 | 87 | 10/12/2023 |
1.9.0-preview1 | 87 | 10/12/2023 |
1.8.9 | 114 | 10/11/2023 |
1.8.8 | 107 | 10/11/2023 |
1.8.7-rc2 | 84 | 9/21/2023 |
1.8.7-rc1 | 92 | 9/12/2023 |
1.8.6 | 138 | 8/31/2023 |
1.8.5 | 118 | 8/25/2023 |
1.8.4 | 131 | 8/24/2023 |
1.8.3 | 134 | 8/23/2023 |
1.8.2 | 131 | 8/22/2023 |
1.8.1 | 137 | 8/18/2023 |
1.8.0 | 145 | 8/15/2023 |
1.7.9 | 162 | 8/11/2023 |
1.7.8 | 144 | 8/11/2023 |
1.7.7 | 147 | 8/10/2023 |
1.7.6 | 157 | 8/9/2023 |
1.7.5 | 133 | 8/9/2023 |
1.7.4 | 144 | 8/3/2023 |
1.7.3 | 150 | 8/1/2023 |
1.7.2 | 136 | 7/31/2023 |
1.7.1 | 136 | 7/27/2023 |
1.7.0 | 148 | 7/27/2023 |