Repository navigation
Send primary-only commands to the primary when the caller prefers a replica - #3291
Merged
mgravell merged 2 commits intoOct 23, 2026
Merged
Conversation
…eplica KeyDelete, KeyExpire (milliseconds), LockExtend and LockRelease pick a server up front to check its features. With PreferReplica that picked a replica, and the primary-only message was then rejected with 'Command cannot be issued to a replica'. GetFeatures now upgrades the flags the same way Message does. Fixes StackExchange#2821
Collaborator
|
Makes perfect sense at a glance. I'll look at it in more detail tomorrow, thanks! |
Collaborator
|
Looks good, thanks. I pushed one small commit onto your branch (fd37aec) rather than round-tripping two nits:
No behaviour change from your version. Will merge once CI is green. |
mgravell
approved these changes
Oct 23, 2026
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.
Fixes #2821
A few methods pick a server up front, through
RedisBase.GetFeatures, to decide which command to send:KeyDelete(DEL vs UNLINK)KeyExpirewith sub-second precision (PEXPIRE)LockExtend(SET IFEQ)LockRelease(DELEX)GetFeaturespassed the caller's flags straight toSelectServer, so withPreferReplicait picked a replica. The message itself is upgraded toDemandMasterbyMessage.SetPrimaryOnly, but because the replica was passed in explicitly, the send failed withCommand cannot be issued to a replica. Commands that pick their server when the message is sent, likeStringSet, already went to the primary, which is the difference the issue describes.GetFeaturesnow applies the same rule asMessage.SetPrimaryOnlyfor primary-only commands:PreferMaster/PreferReplicabecomeDemandMasterbefore selecting.DemandReplicais left alone, so it still fails the way it does for every other primary-only command.RedisServeroverridesGetFeaturesand isn't affected.Test:
KeyTests.PrimaryOnlyCommandsWithPreferReplicaRunOnThePrimaryruns against the primary/replica pair and calls each method, sync and async, withPreferReplica. I ran CI on my fork. Without the fix, the test fails on RESP2 and RESP3 withCommand cannot be issued to a replica: PEXPIRE .... With the fix, the Ubuntu job passes.Checklist