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
                    
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="Soenneker.Redis.Lock" Version="11.0.2980" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Redis.Lock" Version="11.0.2980" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Redis.Lock" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Redis.Lock --version 11.0.2980
                    
#r "nuget: Soenneker.Redis.Lock, 11.0.2980"
                    
#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.
#:package Soenneker.Redis.Lock@11.0.2980
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Redis.Lock&version=11.0.2980
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Redis.Lock&version=11.0.2980
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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

  • Check is a point-in-time existence check, not proof that the caller owns a lock.
  • Lock unconditionally writes the shared value 1, overwriting any existing value. Prefer TryLock for mutual exclusion.
  • Unlock(lockName) releases only a value written by Lock; Unlock(lockName, lockValue) performs a compare-and-delete.
  • ForceUnlock and ForceUnlockAll delete 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 Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed

Update dependency Soenneker.Redis.Util to 11.0.5559 (#3693)