Rystem.Concurrency.Redis 6.0.7

dotnet add package Rystem.Concurrency.Redis --version 6.0.7
NuGet\Install-Package Rystem.Concurrency.Redis -Version 6.0.7
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="Rystem.Concurrency.Redis" Version="6.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rystem.Concurrency.Redis --version 6.0.7
#r "nuget: Rystem.Concurrency.Redis, 6.0.7"
#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 Rystem.Concurrency.Redis as a Cake Addin
#addin nuget:?package=Rystem.Concurrency.Redis&version=6.0.7

// Install Rystem.Concurrency.Redis as a Cake Tool
#tool nuget:?package=Rystem.Concurrency.Redis&version=6.0.7

What is Rystem?

Concurrency

Async Lock

A lock keyword is used in C# to lock a memory address to have a sort of execution queue. But, unfortunately, you cannot use async methods in the lock statement. With async lock you also may have the lock behavior for your async methods. In DI you have to add the lock service

services.AddRedisLock(x =>
            {
                x.ConnectionString = configuration["ConnectionString:Redis"]!;
            });

Inject ILock and use it

ILock locking = _serviceProvider.CreateScope().ServiceProvider.GetService<ILock>();
await locking!.ExecuteAsync(() => CountAsync(2), "SampleKey");

You have the method to execute, a key for more than one concurrent lock.

Race condition

First of all, you have to understand the race condition here In DI you have to add the lock service

services.AddRaceConditionWithRedis(x =>
            {
                x.ConnectionString = configuration["ConnectionString:Redis"]!;
            });

Inject IRaceCodition and use it

 var raceCondition = _serviceProvider.CreateScope().ServiceProvider.GetService<IRaceCodition>();
 raceCondition!.ExecuteAsync(() => CountAsync(2), (i % 2).ToString(), TimeSpan.FromSeconds(2));

You have the method to execute, a key for more than one concurrent race, and a time span for time window, if you put 2 seconds, you block the execution of further methods for 2 seconds from when first method started.

Product Compatible and additional computed target framework versions.
.NET 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.

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
6.0.7 0 5/18/2024
6.0.6 55 5/10/2024
6.0.5 61 5/10/2024
6.0.4 99 4/3/2024
6.0.3 286 3/25/2024