Class SqlIdempotentRepository

Assembly: redb.Route.Sql.dll

Idempotent repository backed by a raw ADO.NET table.
For autonomous use of redb.Route without redb.Core dependency.
Supports auto-create table and TTL-based cleanup.

Schema bootstrap: when is true (default),
the table is created on first operation with dialect-aware DDL: SQLite/PostgreSQL/MySQL/MariaDB use
CREATE TABLE IF NOT EXISTS with VARCHAR key columns (128 for the processor name, 255 for
the message key — MySQL refuses TEXT in a key); SQL Server (which has no such syntax) is detected
from the live connection and gets a guarded IF OBJECT_ID(...) IS NULL CREATE TABLE with
NVARCHAR/INT columns of the same sizes, inside the 900-byte clustered key limit. Set
= false to manage the schema yourself.


Cleanup: when is set, every
runs a best-effort DELETE WHERE created_at < cutoff. This adds latency to the hot
path; for high-throughput scenarios prefer running cleanup out-of-band on a schedule.

public sealed class SqlIdempotentRepository : IIdempotentRepository

Inheritance

Object→SqlIdempotentRepository

Implements

Properties

JoinsAmbientTransaction

True when the repository's connections enlist in an ambient transaction, so that inside a

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

SqlIdempotentRepository(ISqlConnectionFactory, SqlIdempotentOptions)

Creates an idempotent repository with the given connection factory and options.