Soenneker.Redis.Lock
11.0.2980
Prefix Reserved
dotnet add package Soenneker.Redis.Lock --version 11.0.2980
NuGet\Install-Package Soenneker.Redis.Lock -Version 11.0.2980
<PackageReference Include="Soenneker.Redis.Lock" Version="11.0.2980" />
<PackageVersion Include="Soenneker.Redis.Lock" Version="11.0.2980" />
<PackageReference Include="Soenneker.Redis.Lock" />
paket add Soenneker.Redis.Lock --version 11.0.2980
#r "nuget: Soenneker.Redis.Lock, 11.0.2980"
#:package Soenneker.Redis.Lock@11.0.2980
#addin nuget:?package=Soenneker.Redis.Lock&version=11.0.2980
#tool nuget:?package=Soenneker.Redis.Lock&version=11.0.2980
Soenneker.Redis.Lock
Provides expiring Redis locks with ownership-safe acquisition and release.
Installation
dotnet add package Soenneker.Redis.Lock
Registration
using Soenneker.Redis.Lock.Registrars;
services.AddRedisLockUtilAsScoped();
Registration includes Soenneker.Redis.Util; configure its Redis connection before resolving IRedisLockUtil.
Acquire a lock
using Soenneker.Redis.Lock;
using Soenneker.Redis.Lock.Abstract;
RedisLockHandle? handle = await redisLocks.TryLock(
"orders:42:fulfill",
TimeSpan.FromSeconds(30),
cancellationToken);
if (handle is null)
return; // another owner holds the lock
await using (handle)
{
await FulfillOrder(cancellationToken);
}
TryLock writes a unique ownership token only when the key does not exist. Disposing the handle removes the key only if that token still matches, so an expired lock acquired by another process is not released accidentally.
Choose an expiration longer than the protected operation. This package does not renew leases and does not issue fencing tokens; if an operation can outlive its lease, an old owner can continue running after a new owner acquires the key. For correctness-critical writes, add a fencing/version check in the protected resource.
Lower-level operations
Checkis a point-in-time existence check, not proof that the caller owns a lock.Lockunconditionally writes the shared value1, overwriting any existing value. PreferTryLockfor mutual exclusion.Unlock(lockName)releases only a value written byLock;Unlock(lockName, lockValue)performs a compare-and-delete.ForceUnlockandForceUnlockAlldelete without checking ownership and should be reserved for recovery/administration.
Cancellation can stop a pending call, but it does not undo a lock command Redis already accepted.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Soenneker.Redis.Util (>= 11.0.5559)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Soenneker.Redis.Lock:
| Package | Downloads |
|---|---|
|
Soenneker.Redis.Suite
A concoction of Redis utilities and libraries |
|
|
Soenneker.Runners.Redis.Locks
A task runner that uses IRedisLockUtil to release a set of distributed Redis locks, typically when the application starts |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.2980 | 0 | 11/15/2026 |
| 11.0.2979 | 0 | 11/15/2026 |
| 11.0.2978 | 92 | 11/12/2026 |
| 11.0.2976 | 138 | 11/11/2026 |
| 11.0.2973 | 129 | 11/11/2026 |
| 11.0.2972 | 92 | 11/11/2026 |
| 11.0.2970 | 124 | 11/11/2026 |
| 11.0.2969 | 254 | 11/3/2026 |
| 11.0.2968 | 103 | 11/3/2026 |
| 11.0.2967 | 134 | 11/3/2026 |
| 11.0.2966 | 107 | 11/3/2026 |
| 11.0.2965 | 119 | 11/3/2026 |
| 11.0.2964 | 113 | 11/3/2026 |
| 11.0.2963 | 104 | 11/3/2026 |
| 11.0.2962 | 138 | 11/3/2026 |
| 11.0.2961 | 130 | 11/2/2026 |
| 11.0.2960 | 152 | 10/30/2026 |
| 11.0.2959 | 139 | 10/29/2026 |
| 11.0.2958 | 167 | 10/27/2026 |
| 11.0.2957 | 98 | 10/27/2026 |
Update dependency Soenneker.Redis.Util to 11.0.5559 (#3693)