Repository navigation
Set command side-effect category for WithRetry - #540
Merged
Merged
Conversation
StackExchange.Redis 3.1.0 added WithRetry, which replays failed operations according to a policy bounded by the command's declared side-effect category. Commands it does not recognise fall back to CommandRetryNever, and it knows nothing about module commands - so today *nothing* NRedisStack issues is eligible for retry. Categorize all 153 builder commands. SerializedCommand gains a CommandFlags category as the first constructor argument, masked on construction to the retry-category region (bits 13-17) plus the server-specific bit (18), so the parameter cannot smuggle in a replica preference or FireAndForget. The uncategorized constructors are [Obsolete] and CS0618 is an error inside the library, so a new command cannot be added without declaring what a replay of it would do. An internal EffectiveFlags property combines the category with the library-wide defaults (absorbing the DEBUG-only NoRedirect from Auxiliary). The library keeps its StackExchange.Redis 3.0.x floor: CommandCategories declares the values as casts rather than referencing the 3.1.0 named members, which are [Experimental] under SER007. On 3.0.x the bits fall outside that version's user-selectable mask and are silently discarded, reproducing current behaviour exactly; on 3.1.0+ they take effect. The test project overrides to 3.1.0 and asserts each rung against the named member, so an upstream renumbering fails loudly instead of silently re-categorizing everything. Notable calls: - BF.ADD/MADD/INSERT are WriteChecked: bloom adds are monotone, so a replay is a state no-op that only changes the returned 0/1. - CF.ADD/INSERT/DEL are WriteAccumulating: a cuckoo filter is a multiset, so a replay changes the counts. - FT.CURSOR READ is WriteAccumulating, not read-only - reading advances the cursor, so a replay skips a page rather than repeating one. It and FT.CURSOR DEL, BF/CF.SCANDUMP and cursored FT.AGGREGATE carry ServerSpecific, which strips failover while still permitting a same-server retry. - FT.CONFIG (GET as well as SET) is ServerAdmin|ServerSpecific, matching how SE.Redis treats plain CONFIG; a different member can be configured differently, so GET is not meaningfully safer. - The blocking core pops are WriteAccumulating: they are destructive reads, so a replay pops a further element and the first one is already lost. - TS.ADD/TS.MADD are uniformly WriteAccumulating for now; see the comment in TimeSeriesCommandsBuilder for why the overload taking TsAddParams cannot see which of three possible rungs applies.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e5ad774aa
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
This was referenced Jul 31, 2026
mgravell
added a commit
that referenced
this pull request
Aug 3, 2026
* Announce the library name without demanding IDatabase 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. * - ref 3.1.3 to take the WithRetry()/ITransaction tweaks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SE.Redis 3.1.0 adds "retry" support; this needs context on the operation being performed (see here), so: we add these.
Note that I have intentionally not added a 3.1.0 dependency yet; the flags work fine with or without that.
Note
Medium Risk
Wide behavioral change under failover/retry: mis-categorized commands could double-apply writes or skip safe retries; mitigated by exhaustive categorization and unit tests pinning argument-dependent cases.
Overview
Adds side-effect categories on every Redis Stack command so StackExchange.Redis 3.1+
WithRetrycan decide whether a lost reply may be replayed. Categories are carried onSerializedCommand(CommandCategory/EffectiveFlags) via a newCommandCategoriesladder that mirrorsCommandFlags.CommandRetry*using cast constants so the library still builds against SE.Redis 3.0.x (extra bits are ignored there).Dispatch now passes
command.EffectiveFlagsinstead of a single globalCommandFlagsvalue; uncategorized command paths useSerializedCommand.Uncategorized, and the oldSerializedCommandconstructors are[Obsolete]with CS0618 treated as an error in the main project so all builders must categorize.Per-module builders (Bloom, JSON, Search, TimeSeries, etc.) tag each command as read-only, conditional write, last-wins, accumulating, never-retry, server-specific, and so on. Notable argument-dependent rules include
JSON.SET(NX/XX →WriteChecked), RediSearch cursor / WITHCURSOR →Never, blocking list/stream pops →WriteAccumulating, andTS.ADDcategory fromTsAddParams.ResolveCategory(timestamp*,ON_DUPLICATE, etc.).ExecuteBroadcastgains overloads that accept an explicit category.Tests pin category bit alignment with SE.Redis 3.1.0 and cover the tricky cases in
CommandCategoryTests.Reviewed by Cursor Bugbot for commit cc8dbe9. Bugbot is set up for automated code reviews on this repo. Configure here.