Fix ZRangeArgs Rev+ByScore/ByLex incorrectly swapping Start/Stop#3751
Merged
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
Co-authored-by: ndyakov <1547186+ndyakov@users.noreply.github.com> Agent-Logs-Url: https://github.com/redis/go-redis/sessions/18989cb1-ea6a-4fb9-b701-03db3d3fc5ec
Copilot
AI
changed the title
[WIP] Fix ZRANGESTORE command to return expected value with BYSCORE and REV
Fix ZRangeArgs Rev+ByScore/ByLex incorrectly swapping Start/Stop
Mar 25, 2026
ndyakov
approved these changes
Mar 25, 2026
ndyakov
left a comment
Member
There was a problem hiding this comment.
Looks good, @ofekshenawa feel free to review and merge
ofekshenawa
approved these changes
Mar 25, 2026
tmchow
added a commit
to tmchow/rueidis
that referenced
this pull request
Apr 5, 2026
Port of redis/go-redis#3751. Redis 6.2+ ZRANGE with REV expects the caller to supply the range in high-to-low order. The client-side swap was corrupting queries, causing ZRangeStore to return 0 instead of the correct count. Fixes redis#978 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
rueian
pushed a commit
to redis/rueidis
that referenced
this pull request
Apr 6, 2026
## Summary Ports redis/go-redis#3751 to rueidiscompat. `ZRangeStore` (and `zRangeArgs`/`ZRangeArgsWithScores`) returned 0 instead of the correct count when using `Rev: true` with `ByScore` or `ByLex`. The client was swapping `Start`/`Stop` before sending to Redis, but Redis 6.2+ `ZRANGE` with `REV` already expects the caller to supply the range in high-to-low order. Removed the conditional swap in all three locations: - `Compat.zRangeArgs` - `Compat.ZRangeStore` - `CacheCompat.zRangeArgs` Updated affected tests to pass `Start`/`Stop` in the correct high-to-low order. ## Before / After ```go // Before: had to pass low-to-high and rely on client swap (broken for ZRangeStore) adapter.ZRangeStore(ctx, dst, ZRangeArgs{ Key: src, Start: 3, Stop: 5, ByScore: true, Rev: true, }) // returned 0 (wrong) // After: pass high-to-low, matching Redis ZRANGE REV semantics adapter.ZRangeStore(ctx, dst, ZRangeArgs{ Key: src, Start: 5, Stop: 3, ByScore: true, Rev: true, }) // returns correct count ``` Fixes #978 This contribution was developed with AI assistance (Codex). [](https://github.com/EveryInc/compound-engineering-plugin) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes argument ordering sent to Redis for `ZRANGE`/`ZRANGESTORE` when using `Rev` with `ByScore`/`ByLex`, which can affect query results and stored set contents if callers relied on the previous (incorrect) swap. > > **Overview** > Fixes `ZRangeArgs`/`ZRangeArgsWithScores` and `ZRangeStore` to **always send `Start` then `Stop`** to Redis, removing the special-case swap previously done for `Rev` + `ByScore`/`ByLex` (also applied to the cached adapter). > > Updates tests to pass `Start`/`Stop` in the expected high-to-low order when `Rev: true`, aligning behavior with Redis 6.2+ `ZRANGE ... REV` semantics and correcting `ZRANGESTORE` result counts. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5f52ae6. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
rueian
pushed a commit
to valkey-io/valkey-go
that referenced
this pull request
Apr 9, 2026
## Summary Ports redis/go-redis#3751 to rueidiscompat. `ZRangeStore` (and `zRangeArgs`/`ZRangeArgsWithScores`) returned 0 instead of the correct count when using `Rev: true` with `ByScore` or `ByLex`. The client was swapping `Start`/`Stop` before sending to Redis, but Redis 6.2+ `ZRANGE` with `REV` already expects the caller to supply the range in high-to-low order. Removed the conditional swap in all three locations: - `Compat.zRangeArgs` - `Compat.ZRangeStore` - `CacheCompat.zRangeArgs` Updated affected tests to pass `Start`/`Stop` in the correct high-to-low order. ## Before / After ```go // Before: had to pass low-to-high and rely on client swap (broken for ZRangeStore) adapter.ZRangeStore(ctx, dst, ZRangeArgs{ Key: src, Start: 3, Stop: 5, ByScore: true, Rev: true, }) // returned 0 (wrong) // After: pass high-to-low, matching Redis ZRANGE REV semantics adapter.ZRangeStore(ctx, dst, ZRangeArgs{ Key: src, Start: 5, Stop: 3, ByScore: true, Rev: true, }) // returns correct count ``` Fixes #978 This contribution was developed with AI assistance (Codex). [](https://github.com/EveryInc/compound-engineering-plugin) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes argument ordering sent to Redis for `ZRANGE`/`ZRANGESTORE` when using `Rev` with `ByScore`/`ByLex`, which can affect query results and stored set contents if callers relied on the previous (incorrect) swap. > > **Overview** > Fixes `ZRangeArgs`/`ZRangeArgsWithScores` and `ZRangeStore` to **always send `Start` then `Stop`** to Redis, removing the special-case swap previously done for `Rev` + `ByScore`/`ByLex` (also applied to the cached adapter). > > Updates tests to pass `Start`/`Stop` in the expected high-to-low order when `Rev: true`, aligning behavior with Redis 6.2+ `ZRANGE ... REV` semantics and correcting `ZRANGESTORE` result counts. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5f52ae6aad1e2648da29e7684ddd3adce3aacc09. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
ZRangeStore(andZRangeArgs/ZRangeArgsWithScores) returned 0 instead of the correct count when usingRev: truewithByScoreorByLex. The client was swappingStart/Stopbefore sending to Redis, but Redis 6.2+ZRANGEwithREValready expects the caller to supply the range in high→low order — the swap was corrupting the query.Changes
sortedset_commands.go— Remove the conditionalStart/Stopswap inappendArgs. Values are now forwarded to Redis as-is.commands_test.go— Update existingRev+ByScore/Rev+ByLextests to passStart/Stopin the correct high→low order (previously the tests masked the bug by relying on the swap). Add a regression test for the exact scenario from the bug report.ZRangeArgsthat whenRevis set,Startmust be the higher bound andStopthe lower bound.Before / After
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Note
Medium Risk
Changes argument ordering for
ZRANGE/ZRANGESTOREwhen usingRevwithByScore/ByLex, which can affect query results for existing callers that relied on the previous (incorrect) swap. Covered by updated and expanded regression tests.Overview
Fixes
ZRangeArgs.appendArgsto no longer swapStart/StopwhenRevis combined withByScoreorByLex, soZRANGE/ZRANGESTOREmatch Redis’ expected high→low range semantics.Updates
commands_test.goto pass reversed bounds explicitly forRevcases and adds a regression test reproducing theZRANGESTORE ... BYSCORE REVbug. Also refreshes theexample/otelmodule/toolchain and bumps OpenTelemetry-related dependencies.Written by Cursor Bugbot for commit ecb01d9. This will update automatically on new commits. Configure here.