Skip to content

Feat: Align go-redis TimeseriesCmdable - #422

Merged
rueian merged 22 commits into
redis:mainfrom
unknowntpo:feat-align-go-redis-timeseries
Dec 13, 2023
Merged

rueian merged 22 commits into
redis:mainfrom
unknowntpo:feat-align-go-redis-timeseries

Conversation

@unknowntpo

Copy link
Copy Markdown
Contributor

This PR implemented adapter for go-redis TimeseriesCmdable.

…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.
Comment thread rueidiscompat/adapter.go
}
cmds.TsMrangeTotimestamp(_cmd).Filter(filterExpr...)
if options.GroupByLabel != nil {
// FIXME: Wrong API definition: REDUCE

@unknowntpo unknowntpo Dec 12, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that our builder API TsMrevrange is wrong (same as below)

Comment thread rueidiscompat/adapter.go
}
cmds.TsMrevrangeTotimestamp(_cmd).Filter(filterExpr...)
if options.GroupByLabel != nil {
// FIXME: Wrong API definition: REDUCE

@unknowntpo unknowntpo Dec 12, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Ref: https://redis.io/commands/ts.mrevrange/

@unknowntpo
unknowntpo force-pushed the feat-align-go-redis-timeseries branch from 4a32f6b to 5f22cd6 Compare December 12, 2023 11:16
@codecov-commenter

codecov-commenter commented Dec 12, 2023 •

Copy link
Copy Markdown

Codecov Report

Attention: 329 lines in your changes are missing coverage. Please review.

Comparison is base (3ed2b3e) 97.03% compared to head (4703b5a) 96.07%.
Report is 29 commits behind head on main.

Files Patch % Lines
rueidiscompat/adapter.go 58.53% 222 Missing and 21 partials ⚠️
rueidiscompat/command.go 34.35% 72 Missing and 14 partials ⚠️

❗ 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.
📢 Have feedback on the report? Share it here.

Comment thread rueidiscompat/command.go Outdated
}
strIntMap := make(map[string]any, len(m))
for k, ele := range m {
var v any = rueidis.Nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rueidis.Nil is added to make tests pass, should we use rueidis.Nil or let it be nil if ele.IsNil() is true ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nil is more reasonable.

Comment thread rueidiscompat/command.go Outdated
}
strIntMap := make(map[string]any, len(m))
for k, ele := range m {
var v any = rueidis.Nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nil is more reasonable.

Comment thread message.go Outdated
// 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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map[any]any is too hard to use. I don't think we should have this function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll remove it.

@rueian
rueian merged commit 170c52c into redis:main Dec 13, 2023
@unknowntpo
unknowntpo deleted the feat-align-go-redis-timeseries branch December 14, 2023 00:47
rueian pushed a commit that referenced this pull request Nov 10, 2026
## 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 -->
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.

3 participants