Class RedbIdempotentRepository

Assembly: redb.Route.Core.dll

Idempotent repository backed by redb.Core props storage.
Works on any redb-supported database (PostgreSQL, SQL Server, SQLite) via
without raw DDL — the scheme is managed automatically
through .

Opens a fresh scope per operation, so it is safe for concurrent use from multiple route
threads: from an , or from any source of , such as a named
redb instance of the route context (context.CreateRedbScope(name)).


Identity strategy: each entry stores its composite identity
"{ProcessorName}:{MessageKey}" twice: in the indexed
column (readable, O(log n) lookups via IX__objects__name) and in
, which the core guards with the per-scheme UNIQUE
index UIX__objects__scheme_unique on every provider. A composite longer than
440 characters (client keys can be arbitrary) is normalized to a readable prefix plus a
SHA-256 tail so it fits both columns on every provider.


Cluster safety: concurrent calls for one key race to insert the
same ValueUnique; the database lets exactly one row through and the loser's typed
is treated as «already processed» — first wins,
nobody crashes, at-most-once holds across threads and cluster nodes. Entries created by
older versions carry no ValueUnique; the Name lookups still find them, so no
backfill is required.

public sealed class RedbIdempotentRepository : IIdempotentRepository

Inheritance

Object→RedbIdempotentRepository

Implements

Properties

JoinsAmbientTransaction

True: inside an ambient transaction redb writes on the transaction's connection (core AmbientConnectionRegistry,

public bool JoinsAmbientTransaction { get; }

Methods

Add(string, CancellationToken)

Attempts to add the key. Returns true if the key was new (not a duplicate).

public Task<bool> Add(string key, CancellationToken ct = default)

Claim(string, TimeSpan?, CancellationToken)

Claims the key as does, and when it is held already tells why: the message is still being

public Task<IdempotentClaim> Claim(string key, TimeSpan? abandonedAfter, CancellationToken ct = default)

Clear(CancellationToken)

Removes all keys from the repository.

public Task Clear(CancellationToken ct = default)

Confirm(string, CancellationToken)

Confirms the key after successful processing.

public Task Confirm(string key, CancellationToken ct = default)

Confirm(string, string?, CancellationToken)

Confirms the claim token names (from ) after successful processing. Returns

public Task<bool> Confirm(string key, string? token, CancellationToken ct = default)

Contains(string, CancellationToken)

Checks if the key already exists in the repository.

public Task<bool> Contains(string key, CancellationToken ct = default)

Lease(string, TimeSpan?, CancellationToken)

that also names the claim it took: identifies this claim of

public Task<IdempotentLease> Lease(string key, TimeSpan? abandonedAfter, CancellationToken ct = default)

Release(string, string?, CancellationToken)

Removes the claim token names (from ), so the message can be processed again.

public Task<bool> Release(string key, string? token, CancellationToken ct = default)

Remove(string, CancellationToken)

Removes the key, allowing it to be reprocessed.

public Task Remove(string key, CancellationToken ct = default)

Constructors

RedbIdempotentRepository(Func<RedbScope>, RedbIdempotentOptions)

Creates a repository over the redb scopes openScope opens, one per operation; the repository

RedbIdempotentRepository(IServiceScopeFactory, RedbIdempotentOptions)

Creates a repository over the of the scopes scopeFactory opens.