Repository navigation
Feat: Align go-redis TimeseriesCmdable - #422
Conversation
…SDeleteRule, TSGet, TSInfo, TSInfoWithArgs, TSMAdd, TSQueryIndex, TSRevRange
…any]any WORKAROUND: manually convert map[string]any to map[any]any to make go-redis test PASS we don't use (*RedisMessage).ToAny() on map type because it will convert ele to map[string]any
Because tests in go-redis use both of them.
| } | ||
| cmds.TsMrangeTotimestamp(_cmd).Filter(filterExpr...) | ||
| if options.GroupByLabel != nil { | ||
| // FIXME: Wrong API definition: REDUCE |
There was a problem hiding this comment.
Note that our builder API TsMrevrange is wrong (same as below)
| } | ||
| cmds.TsMrevrangeTotimestamp(_cmd).Filter(filterExpr...) | ||
| if options.GroupByLabel != nil { | ||
| // FIXME: Wrong API definition: REDUCE |
There was a problem hiding this comment.
Note that our builder API TsMrevrange is wrong,
according to the doc, it should be:
cmds.TsMrevrangeFilter(_cmd).Groupby(str(options.GroupByLabel).Reduce(str(options.Reducer))
Not:
cmds.TsMrevrangeFilter(_cmd).Groupby(str(options.GroupByLabel), "REDUCE", str(options.Reducer))
4a32f6b to
5f22cd6
Compare
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #422 +/- ##
==========================================
- Coverage 97.03% 96.07% -0.96%
==========================================
Files 76 76
Lines 31445 32162 +717
==========================================
+ Hits 30512 30899 +387
- Misses 788 1083 +295
- Partials 145 180 +35 ☔ View full report in Codecov by Sentry. |
| } | ||
| strIntMap := make(map[string]any, len(m)) | ||
| for k, ele := range m { | ||
| var v any = rueidis.Nil |
There was a problem hiding this comment.
This rueidis.Nil is added to make tests pass, should we use rueidis.Nil or let it be nil if ele.IsNil() is true ?
There was a problem hiding this comment.
I think nil is more reasonable.
| } | ||
| strIntMap := make(map[string]any, len(m)) | ||
| for k, ele := range m { | ||
| var v any = rueidis.Nil |
There was a problem hiding this comment.
I think nil is more reasonable.
| // AsAnyAnyMap converts RedisMessage to map[any]any. | ||
| // we don't use (*RedisMessage).ToAny() on map type because it will convert ele | ||
| // to map[string]any | ||
| func (m *RedisMessage) AsAnyAnyMap() (map[any]any, error) { |
There was a problem hiding this comment.
map[any]any is too hard to use. I don't think we should have this function.
There was a problem hiding this comment.
Okay, I'll remove it.
## 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](https://github.com/redis/rueidis/blob/e03a107/rueidiscompat/adapter.go#L4952)). 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. <!-- CURSOR_SUMMARY --> --- > [!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`**. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b97e484. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This PR implemented adapter for
go-redisTimeseriesCmdable.