Skip to content

fix(rueidiscompat): send TS.MREVRANGE from TSMRevRange - #1053

Merged
rueian merged 2 commits into
redis:mainfrom
yamamoto7:fix/compat-tsmrevrange
Nov 10, 2026
Merged

rueian merged 2 commits into
redis:mainfrom
yamamoto7:fix/compat-tsmrevrange

Conversation

@yamamoto7

@yamamoto7 yamamoto7 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

Compat.TSMRevRange sent TS.MRANGE, so it returned samples oldest first. It now sends TS.MREVRANGE, which matches TSMRevRangeWithArgs and go-redis. No API change.

Problem

TSMRevRange built TsMrange() instead of TsMrevrange() (adapter.go:4952). There is no error, so code that treats the first sample as the latest one silently reads the oldest one.

One series with samples at 1000, 2000, 3000, then TSMRevRange(ctx, 0, 10000, filter):

go-redis TSMRevRange        : [[3000 3] [2000 2] [1000 1]]
compat   TSMRevRange        : [[1000 1] [2000 2] [3000 3]]
compat   TSMRevRangeWithArgs: [[3000 3] [2000 2] [1000 1]]
server calls during compat TSMRevRange (INFO commandstats):
  TS.MRANGE 0->1, TS.MREVRANGE 1->1

It has been this way since TSMRevRange was added in #422. The tests didn't catch it:

  • The adapter test only checked the number of samples.
  • The pipeline golden recorded TS.MRANGE for TSMRevRange, so it pinned the bug.

The other range commands (TSRange, TSRevRange, TSMRange, and their WithArgs variants) use the right builders.

Fix

  • adapter.go: use TsMrevrange() in TSMRevRange.
  • adapter_test.go: also check the first and last samples, so the test fails if the order is wrong.
  • pipeline_test.go: change the golden entry for TSMRevRange from TS.MRANGE to TS.MREVRANGE.

Verification

Tested on main @ e03a107 with Redis 7.4.0 (redis-stack) and Redis 8.2.11:

before: compat TSMRevRange: [[1000 1] [2000 2] [3000 3]]  (TS.MRANGE +1)
after:  compat TSMRevRange: [[3000 3] [2000 2] [1000 1]]  (TS.MREVRANGE +1)
  • Without the adapter.go change, both the new assertion and TestPipeliner fail.
  • With it, all 18 timeseries specs and TestPipeliner pass.

Note

Medium Risk
Fixes silent wrong sample ordering for any caller relying on TSMRevRange for “latest first” data; behavior change is intentional and aligns with the command name and other clients.

Overview
Compat.TSMRevRange was issuing TS.MRANGE, so multi-series reverse-range results came back oldest-first instead of newest-first—unlike TSMRevRangeWithArgs and go-redis. The builder is now TsMrevrange() so the client sends TS.MREVRANGE; the public API is unchanged.

Tests were tightened so regressions on order are caught: adapter specs assert the first and last samples in each series, and the pipeline golden for TSMRevRange expects TS.MREVRANGE instead of TS.MRANGE.

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

TSMRevRange built TsMrange(), so it sent TS.MRANGE and returned
samples in ascending order. TSMRevRangeWithArgs and go-redis send
TS.MREVRANGE and return them in descending order.

Check the sample order in the adapter test, and correct the pipeline
golden that recorded TS.MRANGE for TSMRevRange.
@rueian
rueian merged commit eb2e55c into redis:main Nov 10, 2026
32 checks passed
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.

2 participants