fix(command): put IGNORE before LABELS (#4160)

Signed-off-by: Yusuf Efe <120668197+yuefdev@users.noreply.github.com>
This commit is contained in:
Yusuf Efe authored and GitHub committed 2026-10-19 10:17:19 +03:00
1 parent d01bbdfde5
commit a4a376ad55
2 files changed
+74 -15

No files matched your search

+15 -15
View File
@@ -343,15 +343,15 @@ func (c cmdable) TSAddWithArgs(ctx context.Context, key string, timestamp interf
if options.DuplicatePolicy != "" {
args = append(args, "DUPLICATE_POLICY", options.DuplicatePolicy)
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
if options.Labels != nil {
args = append(args, "LABELS")
for label, value := range options.Labels {
args = append(args, label, value)
}
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
}
cmd := NewIntCmd(ctx, args...)
_ = c(ctx, cmd)
@@ -387,15 +387,15 @@ func (c cmdable) TSCreateWithArgs(ctx context.Context, key string, options *TSOp
if options.DuplicatePolicy != "" {
args = append(args, "DUPLICATE_POLICY", options.DuplicatePolicy)
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
if options.Labels != nil {
args = append(args, "LABELS")
for label, value := range options.Labels {
args = append(args, label, value)
}
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
}
cmd := NewStatusCmd(ctx, args...)
_ = c(ctx, cmd)
@@ -418,15 +418,15 @@ func (c cmdable) TSAlter(ctx context.Context, key string, options *TSAlterOption
if options.DuplicatePolicy != "" {
args = append(args, "DUPLICATE_POLICY", options.DuplicatePolicy)
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
if options.Labels != nil {
args = append(args, "LABELS")
for label, value := range options.Labels {
args = append(args, label, value)
}
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
}
cmd := NewStatusCmd(ctx, args...)
_ = c(ctx, cmd)
@@ -489,15 +489,15 @@ func (c cmdable) TSIncrByWithArgs(ctx context.Context, key string, timestamp flo
if options.DuplicatePolicy != "" {
args = append(args, "DUPLICATE_POLICY", options.DuplicatePolicy)
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
if options.Labels != nil {
args = append(args, "LABELS")
for label, value := range options.Labels {
args = append(args, label, value)
}
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
}
cmd := NewIntCmd(ctx, args...)
_ = c(ctx, cmd)
@@ -535,15 +535,15 @@ func (c cmdable) TSDecrByWithArgs(ctx context.Context, key string, timestamp flo
if options.DuplicatePolicy != "" {
args = append(args, "DUPLICATE_POLICY", options.DuplicatePolicy)
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
if options.Labels != nil {
args = append(args, "LABELS")
for label, value := range options.Labels {
args = append(args, label, value)
}
}
if options.IgnoreMaxTimeDiff != 0 || options.IgnoreMaxValDiff != 0 {
args = append(args, "IGNORE", options.IgnoreMaxTimeDiff, options.IgnoreMaxValDiff)
}
}
cmd := NewIntCmd(ctx, args...)
_ = c(ctx, cmd)
+59
View File
@@ -0,0 +1,59 @@
package redis
import (
"context"
"reflect"
"testing"
)
func TestTSIgnoreBeforeLabels(t *testing.T) {
ctx := context.Background()
labels := map[string]string{"sensor": "temperature"}
options := &TSOptions{IgnoreMaxTimeDiff: 5, IgnoreMaxValDiff: 10, Labels: labels}
alterOptions := &TSAlterOptions{IgnoreMaxTimeDiff: 5, IgnoreMaxValDiff: 10, Labels: labels}
incrDecrOptions := &TSIncrDecrOptions{IgnoreMaxTimeDiff: 5, IgnoreMaxValDiff: 10, Labels: labels}
tests := []struct {
name string
call func(cmdable) Cmder
want []interface{}
}{
{
name: "add",
call: func(c cmdable) Cmder { return c.TSAddWithArgs(ctx, "series", 1000, 1, options) },
want: []interface{}{"TS.ADD", "series", 1000, float64(1)},
},
{
name: "create",
call: func(c cmdable) Cmder { return c.TSCreateWithArgs(ctx, "series", options) },
want: []interface{}{"TS.CREATE", "series"},
},
{
name: "alter",
call: func(c cmdable) Cmder { return c.TSAlter(ctx, "series", alterOptions) },
want: []interface{}{"TS.ALTER", "series"},
},
{
name: "increment",
call: func(c cmdable) Cmder { return c.TSIncrByWithArgs(ctx, "series", 1, incrDecrOptions) },
want: []interface{}{"TS.INCRBY", "series", float64(1)},
},
{
name: "decrement",
call: func(c cmdable) Cmder { return c.TSDecrByWithArgs(ctx, "series", 1, incrDecrOptions) },
want: []interface{}{"TS.DECRBY", "series", float64(1)},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var captured Cmder
cmd := tt.call(captureCmdable(&captured))
// LABELS consumes the remaining arguments as label/value pairs.
want := append(tt.want, "IGNORE", int64(5), float64(10), "LABELS", "sensor", "temperature")
if !reflect.DeepEqual(cmd.Args(), want) {
t.Errorf("args mismatch\n got: %#v\nwant: %#v", cmd.Args(), want)
}
})
}
}