Redis-backed reservations and TTL-based response retention for .NET developers using DKNet idempotency.
- Share a key ledger across hosts connected to the same Redis database.
- Reserve keys atomically without relational schema migrations.
- Expire reservations and completed values through Redis TTLs.
Use a .NET 10 ASP.NET Core project.
dotnet new web -f net10.0 -n PackageDemo
cd PackageDemo
dotnet add package DKNet.AspCore.Idempotency.RedisStoreReplace Program.cs with the example, then run dotnet run.
Set ConnectionStrings__Redis to a reachable Redis connection string. The Redis server must support the atomic SET NX GET operation used by StackExchange.Redis.
using DKNet.AspCore.Idempotency;
using DKNet.AspCore.Idempotency.RedisStore;
var builder = WebApplication.CreateBuilder(args);
var connection = builder.Configuration.GetConnectionString("Redis")
?? throw new InvalidOperationException("Set ConnectionStrings__Redis.");
builder.Services.AddIdempotencyWithRedisStore(connection);
var app = builder.Build();
app.MapPost("/orders", () => Results.Ok(new { Accepted = true }))
.RequiredIdempotentKey();
await app.RunAsync();POST twice with X-Idempotency-Key: order-1. The first returns 200 and the retry 409. Instances sharing this Redis database and prefix share the ledger.
The app supplies reachable Redis infrastructure. Existing multiplexer and distributed-cache registrations are retained independently; the store uses the multiplexer directly. No relational base, context or migration service participates.
The core filter decides 409 versus replay. Reservations expire separately from completed entries. Redis loss or eviction and handlers exceeding the reservation lifetime can permit another execution.
- Register Redis connections and select the store — Reuse Redis connections and select the internal store.
- Reserve Redis keys and retain response values — Trace atomic set-and-get reservation, logical expiry, and TTL writes.
- Idempotency — configure declaration, validation and replay.
- MsSqlStore — choose a SQL Server ledger.
- NpgsqlStore — choose PostgreSQL.
- Relational — read the shared SQL implementation, which Redis does not use.