DKNet.AspCore.Idempotency.RedisStore
10.1.2
See the version list below for details.
dotnet add package DKNet.AspCore.Idempotency.RedisStore --version 10.1.2
NuGet\Install-Package DKNet.AspCore.Idempotency.RedisStore -Version 10.1.2
<PackageReference Include="DKNet.AspCore.Idempotency.RedisStore" Version="10.1.2" />
<PackageVersion Include="DKNet.AspCore.Idempotency.RedisStore" Version="10.1.2" />
<PackageReference Include="DKNet.AspCore.Idempotency.RedisStore" />
paket add DKNet.AspCore.Idempotency.RedisStore --version 10.1.2
#r "nuget: DKNet.AspCore.Idempotency.RedisStore, 10.1.2"
#:package DKNet.AspCore.Idempotency.RedisStore@10.1.2
#addin nuget:?package=DKNet.AspCore.Idempotency.RedisStore&version=10.1.2
#tool nuget:?package=DKNet.AspCore.Idempotency.RedisStore&version=10.1.2
DKNet.AspCore.Idempotency.RedisStore
Redis persistent storage implementation for DKNet.AspCore.Idempotency.
Overview
This library provides a Redis-backed storage implementation for idempotency keys, replacing the default distributed cache storage with an atomic store based on StackExchange.Redis.
Features
- ✅ Atomic Reservation:
SET NXguarantees only one caller reserves a key - ✅ Persistent Storage: Idempotency keys survive as long as configured in Redis
- ✅ Concurrent-Safe: No check-then-act race window
- ✅ Fast Lookups: In-memory speed for key existence checks
Installation
dotnet add package DKNet.AspCore.Idempotency.RedisStore
Quick Start
1. Configure in Program.cs
using DKNet.AspCore.Idempotency.RedisStore;
var builder = WebApplication.CreateBuilder(args);
// Register Redis idempotency storage
builder.Services.AddIdempotencyWithRedisStore(
builder.Configuration.GetConnectionString("Redis")!,
options =>
{
options.Expiration = TimeSpan.FromHours(24);
});
var app = builder.Build();
app.Run();
2. Configure Connection String
appsettings.json:
{
"ConnectionStrings": {
"Redis": "localhost:6379"
}
}
3. Use Idempotency in Endpoints
using DKNet.AspCore.Idempotency;
app.MapPost("/orders", CreateOrder)
.RequiredIdempotentKey();
Configuration Options
IdempotencyOptions
| Option | Type | Default | Description |
|---|---|---|---|
Expiration |
TimeSpan |
4 hours |
How long to keep completed idempotency keys in Redis |
InFlightReservationTimeout |
TimeSpan |
30 seconds |
How long an in-flight reservation placeholder is honoured |
JsonSerializerOptions |
JsonSerializerOptions |
Camel case | Customizes JSON serialization for cached responses |
Example Configuration
builder.Services.AddIdempotencyWithRedisStore(
connectionString,
options =>
{
options.Expiration = TimeSpan.FromHours(48);
options.InFlightReservationTimeout = TimeSpan.FromMinutes(1);
});
Using an Existing Connection Multiplexer
If your application already configures IConnectionMultiplexer, pass it directly:
builder.Services.AddIdempotencyRedisStore(existingMultiplexer);
builder.Services.AddIdempotentKey<IdempotencyRedisStore>();
Concurrency Handling
The library handles concurrent duplicate requests safely using Redis SET NX:
Request A: SET key NX → Success
Request B: SET key NX → Failure
Request B: GET key → Returns A's reservation or cached response
The atomic SET NX operation eliminates the check-then-act race window present in the default distributed-cache store.
Requirements
- .NET 10.0+
- Redis 5.0+ (or Redis-compatible cache such as Azure Cache for Redis)
- DKNet.AspCore.Idempotency (automatically included)
License
MIT License - see LICENSE file for details.
Support
For issues and questions, please open an issue on the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DKNet.AspCore.Idempotency (>= 10.1.2)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 10.0.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Options (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.