Skip to content

Announce the library name without demanding IDatabase - #542

Merged
mgravell merged 2 commits into
masterfrom
marc/async-setinfo
Aug 3, 2026
Merged

mgravell merged 2 commits into
masterfrom
marc/async-setinfo

Conversation

@mgravell

@mgravell mgravell commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

(specifically: support WithRetry)

Note: takes SE.Redis 3.1.3

Auxiliary.ExecuteAsync unconditionally cast its IDatabaseAsync to IDatabase in order to send the one-time CLIENT SETINFO lib-name/lib-ver pair. A retry-wrapped database (SE.Redis 3.1.0 WithRetry) is async-only - RetryDatabase implements IDatabaseAsync but not IDatabase - so every async module command issued through one threw InvalidCastException before the command was sent, making the retry categories added in #540 unusable from the async API.

The announcement never needed the sync interface: it only needed it to create a batch to group the two commands, which don't need grouping. It is now typed as IDatabaseAsync and dispatched fire-and-forget via an internal ClientSetInfoAsync overload that takes dispatch flags, so there is no cast, no batch, and no round-trip on the caller's first command. In the expected case - fire-and-forget completing synchronously - no state machine is entered on this path at all: the overload hands back a cached completed task, and the caller only awaits (to consume a fault) if a task somehow comes back not-yet-completed. A synchronous failure in the version probe can no longer fail the caller's command either; announcing who we are is best-effort.

Renamed SetInfoInPipeline -> SetLibraryInfoOnce (internal): there is no longer a pipeline involved.

Task.IsCompletedSuccessfully only exists on modern .NET, so netstandard2.0/net481 get it as an extension property polyfill rather than open-coding the Status test at each site.

Audited the rest of the library for the same shape: this was the only unconditional cast to a sync SE.Redis interface; SearchCommandsAsync's cluster cursor path was already type-tested.

Tests cover an async module command and the first-use announcement over db.WithRetry(...) - both fail with InvalidCastException before this change - plus the synchronous completion that the fire-and-forget dispatch relies on.


Note

Medium Risk
Touches first-command behavior on every connection and transaction edge cases for library announcement; dependency bump to experimental WithRetry APIs affects all consumers.

Overview
Fixes async module commands on db.WithRetry(...) by removing the IDatabase cast in the one-time CLIENT SETINFO announcement. SetLibraryInfoOnce (renamed from SetInfoInPipeline) runs on IDatabaseAsync, sends lib-name/lib-ver as fire-and-forget (no batch, no extra round-trip on the caller’s first command), and skips ITransactionAsync so SETINFO is not queued into MULTI/EXEC; announcement failures are best-effort.

Adds an internal ClientSetInfoAsync(..., CommandFlags) fast path for synchronous fire-and-forget completion, a Task.IsCompletedSuccessfully polyfill for netstandard/net481, and WithRetryTests for retry DB/transactions and transaction announcement behavior.

Dependency: StackExchange.Redis 3.0.25 → 3.1.3; CommandCategories now aliases CommandFlags.CommandRetry* (drops int casts); SER007 suppressed repo-wide; test projects use central package version (no 3.1.0 override).

Reviewed by Cursor Bugbot for commit 40f3a69. Bugbot is set up for automated code reviews on this repo. Configure here.

Auxiliary.ExecuteAsync unconditionally cast its IDatabaseAsync to IDatabase in
order to send the one-time CLIENT SETINFO lib-name/lib-ver pair. A retry-wrapped
database (SE.Redis 3.1.0 WithRetry) is async-only - RetryDatabase implements
IDatabaseAsync but not IDatabase - so every async module command issued through
one threw InvalidCastException before the command was sent, making the retry
categories added in #540 unusable from the async API.

The announcement never needed the sync interface: it only needed it to create a
batch to group the two commands, which don't need grouping. It is now typed as
IDatabaseAsync and dispatched fire-and-forget via an internal ClientSetInfoAsync
overload that takes dispatch flags, so there is no cast, no batch, and no
round-trip on the caller's first command. In the expected case - fire-and-forget
completing synchronously - no state machine is entered on this path at all: the
overload hands back a cached completed task, and the caller only awaits (to
consume a fault) if a task somehow comes back not-yet-completed. A synchronous
failure in the version probe can no longer fail the caller's command either;
announcing who we are is best-effort.

Renamed SetInfoInPipeline -> SetLibraryInfoOnce (internal): there is no longer a
pipeline involved.

Task.IsCompletedSuccessfully only exists on modern .NET, so netstandard2.0/net481
get it as an extension property polyfill rather than open-coding the Status test
at each site.

Audited the rest of the library for the same shape: this was the only
unconditional cast to a sync SE.Redis interface; SearchCommandsAsync's cluster
cursor path was already type-tested.

Tests cover an async module command and the first-use announcement over
db.WithRetry(...) - both fail with InvalidCastException before this change - plus
the synchronous completion that the fire-and-forget dispatch relies on.
@mgravell
mgravell marked this pull request as ready for review August 3, 2026 11:57
@mgravell
mgravell merged commit bc58a34 into master Aug 3, 2026
22 checks passed
@mgravell
mgravell deleted the marc/async-setinfo branch August 3, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant