diff --git a/README.md b/README.md index 4487c6e9a..113898f44 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ For example: "idx:bicycle", "@pickup_zone:[CONTAINS $bike]", &redis.FTSearchOptions{ - Params: map[string]interface{}{ + Params: map[string]any{ "bike": "POINT(-0.1278 51.5074)", }, DialectVersion: 3, diff --git a/acl_commands.go b/acl_commands.go index 9cb800bb3..ce214ad2f 100644 --- a/acl_commands.go +++ b/acl_commands.go @@ -3,7 +3,7 @@ package redis import "context" type ACLCmdable interface { - ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd + ACLDryRun(ctx context.Context, username string, command ...any) *StringCmd ACLLog(ctx context.Context, count int64) *ACLLogCmd ACLLogReset(ctx context.Context) *StatusCmd @@ -20,8 +20,8 @@ type ACLCatArgs struct { Category string } -func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd { - args := make([]interface{}, 0, 3+len(command)) +func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...any) *StringCmd { + args := make([]any, 0, 3+len(command)) args = append(args, "acl", "dryrun", username) args = append(args, command...) cmd := NewStringCmd(ctx, args...) @@ -30,7 +30,7 @@ func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...inte } func (c cmdable) ACLLog(ctx context.Context, count int64) *ACLLogCmd { - args := make([]interface{}, 0, 3) + args := make([]any, 0, 3) args = append(args, "acl", "log") if count > 0 { args = append(args, count) @@ -53,7 +53,7 @@ func (c cmdable) ACLDelUser(ctx context.Context, username string) *IntCmd { } func (c cmdable) ACLSetUser(ctx context.Context, username string, rules ...string) *StatusCmd { - args := make([]interface{}, 3+len(rules)) + args := make([]any, 3+len(rules)) args[0] = "acl" args[1] = "setuser" args[2] = username diff --git a/acl_commands_test.go b/acl_commands_test.go index a96621dbc..a41a5c7e8 100644 --- a/acl_commands_test.go +++ b/acl_commands_test.go @@ -430,7 +430,7 @@ var _ = Describe("ACL Categories", func() { "tdigest": "tdigest.rank", "timeseries": "ts.range", } - var cats []interface{} + var cats []any for cat, subitem := range aclTestCase { cats = append(cats, cat) diff --git a/bench_decode_test.go b/bench_decode_test.go index d61a901a0..515dd1391 100644 --- a/bench_decode_test.go +++ b/bench_decode_test.go @@ -219,7 +219,7 @@ func respString(b *testing.B, stub ClientStubFunc) { func respArray(b *testing.B, stub ClientStubFunc) { rdb := stub([]byte("*3\r\n$5\r\nhello\r\n:10\r\n+OK\r\n")) - var val []interface{} + var val []any b.ResetTimer() for i := 0; i < b.N; i++ { diff --git a/bitmap_commands.go b/bitmap_commands.go index a21558289..786e5420e 100644 --- a/bitmap_commands.go +++ b/bitmap_commands.go @@ -15,8 +15,8 @@ type BitMapCmdable interface { BitOpNot(ctx context.Context, destKey string, key string) *IntCmd BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd - BitField(ctx context.Context, key string, values ...interface{}) *IntSliceCmd - BitFieldRO(ctx context.Context, key string, values ...interface{}) *IntSliceCmd + BitField(ctx context.Context, key string, values ...any) *IntSliceCmd + BitFieldRO(ctx context.Context, key string, values ...any) *IntSliceCmd } func (c cmdable) GetBit(ctx context.Context, key string, offset int64) *IntCmd { @@ -66,7 +66,7 @@ func (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) * } func (c cmdable) bitOp(ctx context.Context, op, destKey string, keys ...string) *IntCmd { - args := make([]interface{}, 3+len(keys)) + args := make([]any, 3+len(keys)) args[0] = "bitop" args[1] = op args[2] = destKey @@ -97,7 +97,7 @@ func (c cmdable) BitOpNot(ctx context.Context, destKey string, key string) *IntC // BitPos is an API before Redis version 7.0, cmd: bitpos key bit start end // if you need the `byte | bit` parameter, please use `BitPosSpan`. func (c cmdable) BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd { - args := make([]interface{}, 3+len(pos)) + args := make([]any, 3+len(pos)) args[0] = "bitpos" args[1] = key args[2] = bit @@ -131,9 +131,9 @@ func (c cmdable) BitPosSpan(ctx context.Context, key string, bit int8, start, en // BitField accepts multiple values: // - BitField("set", "i1", "offset1", "value1","cmd2", "type2", "offset2", "value2") // - BitField([]string{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"}) -// - BitField([]interface{}{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"}) -func (c cmdable) BitField(ctx context.Context, key string, values ...interface{}) *IntSliceCmd { - args := make([]interface{}, 2, 2+len(values)) +// - BitField([]any{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"}) +func (c cmdable) BitField(ctx context.Context, key string, values ...any) *IntSliceCmd { + args := make([]any, 2, 2+len(values)) args[0] = "bitfield" args[1] = key args = appendArgs(args, values) @@ -145,8 +145,8 @@ func (c cmdable) BitField(ctx context.Context, key string, values ...interface{} // BitFieldRO - Read-only variant of the BITFIELD command. // It is like the original BITFIELD but only accepts GET subcommand and can safely be used in read-only replicas. // - BitFieldRO(ctx, key, "", "", "","") -func (c cmdable) BitFieldRO(ctx context.Context, key string, values ...interface{}) *IntSliceCmd { - args := make([]interface{}, 2, 2+len(values)) +func (c cmdable) BitFieldRO(ctx context.Context, key string, values ...any) *IntSliceCmd { + args := make([]any, 2, 2+len(values)) args[0] = "BITFIELD_RO" args[1] = key if len(values)%2 != 0 { diff --git a/cluster_commands.go b/cluster_commands.go index 4857b01ea..9e6323941 100644 --- a/cluster_commands.go +++ b/cluster_commands.go @@ -127,7 +127,7 @@ func (c cmdable) ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd { } func (c cmdable) ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd { - args := make([]interface{}, 2+len(slots)) + args := make([]any, 2+len(slots)) args[0] = "cluster" args[1] = "delslots" for i, slot := range slots { @@ -166,7 +166,7 @@ func (c cmdable) ClusterFailover(ctx context.Context) *StatusCmd { } func (c cmdable) ClusterAddSlots(ctx context.Context, slots ...int) *StatusCmd { - args := make([]interface{}, 2+len(slots)) + args := make([]any, 2+len(slots)) args[0] = "cluster" args[1] = "addslots" for i, num := range slots { diff --git a/command.go b/command.go index 5fa347f43..70c13d576 100644 --- a/command.go +++ b/command.go @@ -28,7 +28,7 @@ type Cmder interface { // all args of the command. // e.g. "set k v ex 10" -> "[set k v ex 10]". - Args() []interface{} + Args() []any // format request and response string. // e.g. "set k v ex 10" -> "set k v ex 10: OK", "get k" -> "get k: v". @@ -98,7 +98,7 @@ func cmdFirstKeyPos(cmd Cmder) int { return 1 } -func cmdString(cmd Cmder, val interface{}) string { +func cmdString(cmd Cmder, val any) string { b := make([]byte, 0, 64) for i, arg := range cmd.Args() { @@ -123,10 +123,10 @@ func cmdString(cmd Cmder, val interface{}) string { type baseCmd struct { ctx context.Context - args []interface{} + args []any err error keyPos int8 - rawVal interface{} + rawVal any _readTimeout *time.Duration } @@ -155,7 +155,7 @@ func (cmd *baseCmd) FullName() string { } } -func (cmd *baseCmd) Args() []interface{} { +func (cmd *baseCmd) Args() []any { return cmd.args } @@ -209,10 +209,10 @@ func (cmd *baseCmd) readRawReply(rd *proto.Reader) (err error) { type Cmd struct { baseCmd - val interface{} + val any } -func NewCmd(ctx context.Context, args ...interface{}) *Cmd { +func NewCmd(ctx context.Context, args ...any) *Cmd { return &Cmd{ baseCmd: baseCmd{ ctx: ctx, @@ -225,15 +225,15 @@ func (cmd *Cmd) String() string { return cmdString(cmd, cmd.val) } -func (cmd *Cmd) SetVal(val interface{}) { +func (cmd *Cmd) SetVal(val any) { cmd.val = val } -func (cmd *Cmd) Val() interface{} { +func (cmd *Cmd) Val() any { return cmd.val } -func (cmd *Cmd) Result() (interface{}, error) { +func (cmd *Cmd) Result() (any, error) { return cmd.val, cmd.err } @@ -244,7 +244,7 @@ func (cmd *Cmd) Text() (string, error) { return toString(cmd.val) } -func toString(val interface{}) (string, error) { +func toString(val any) (string, error) { switch val := val.(type) { case string: return val, nil @@ -276,7 +276,7 @@ func (cmd *Cmd) Int64() (int64, error) { return toInt64(cmd.val) } -func toInt64(val interface{}) (int64, error) { +func toInt64(val any) (int64, error) { switch val := val.(type) { case int64: return val, nil @@ -295,7 +295,7 @@ func (cmd *Cmd) Uint64() (uint64, error) { return toUint64(cmd.val) } -func toUint64(val interface{}) (uint64, error) { +func toUint64(val any) (uint64, error) { switch val := val.(type) { case int64: return uint64(val), nil @@ -314,7 +314,7 @@ func (cmd *Cmd) Float32() (float32, error) { return toFloat32(cmd.val) } -func toFloat32(val interface{}) (float32, error) { +func toFloat32(val any) (float32, error) { switch val := val.(type) { case int64: return float32(val), nil @@ -337,7 +337,7 @@ func (cmd *Cmd) Float64() (float64, error) { return toFloat64(cmd.val) } -func toFloat64(val interface{}) (float64, error) { +func toFloat64(val any) (float64, error) { switch val := val.(type) { case int64: return float64(val), nil @@ -356,7 +356,7 @@ func (cmd *Cmd) Bool() (bool, error) { return toBool(cmd.val) } -func toBool(val interface{}) (bool, error) { +func toBool(val any) (bool, error) { switch val := val.(type) { case bool: return val, nil @@ -370,12 +370,12 @@ func toBool(val interface{}) (bool, error) { } } -func (cmd *Cmd) Slice() ([]interface{}, error) { +func (cmd *Cmd) Slice() ([]any, error) { if cmd.err != nil { return nil, cmd.err } switch val := cmd.val.(type) { - case []interface{}: + case []any: return val, nil default: return nil, fmt.Errorf("redis: unexpected type=%T for Slice", val) @@ -494,12 +494,12 @@ func (cmd *Cmd) readReply(rd *proto.Reader) (err error) { type SliceCmd struct { baseCmd - val []interface{} + val []any } var _ Cmder = (*SliceCmd)(nil) -func NewSliceCmd(ctx context.Context, args ...interface{}) *SliceCmd { +func NewSliceCmd(ctx context.Context, args ...any) *SliceCmd { return &SliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -508,15 +508,15 @@ func NewSliceCmd(ctx context.Context, args ...interface{}) *SliceCmd { } } -func (cmd *SliceCmd) SetVal(val []interface{}) { +func (cmd *SliceCmd) SetVal(val []any) { cmd.val = val } -func (cmd *SliceCmd) Val() []interface{} { +func (cmd *SliceCmd) Val() []any { return cmd.val } -func (cmd *SliceCmd) Result() ([]interface{}, error) { +func (cmd *SliceCmd) Result() ([]any, error) { return cmd.val, cmd.err } @@ -526,14 +526,14 @@ func (cmd *SliceCmd) String() string { // Scan scans the results from the map into a destination struct. The map keys // are matched in the Redis struct fields by the `redis:"field"` tag. -func (cmd *SliceCmd) Scan(dst interface{}) error { +func (cmd *SliceCmd) Scan(dst any) error { if cmd.err != nil { return cmd.err } // Pass the list of keys and values. // Skip the first two args for: HMGET key - var args []interface{} + var args []any if cmd.args[0] == "hmget" { args = cmd.args[2:] } else { @@ -559,7 +559,7 @@ type StatusCmd struct { var _ Cmder = (*StatusCmd)(nil) -func NewStatusCmd(ctx context.Context, args ...interface{}) *StatusCmd { +func NewStatusCmd(ctx context.Context, args ...any) *StatusCmd { return &StatusCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -603,7 +603,7 @@ type IntCmd struct { var _ Cmder = (*IntCmd)(nil) -func NewIntCmd(ctx context.Context, args ...interface{}) *IntCmd { +func NewIntCmd(ctx context.Context, args ...any) *IntCmd { return &IntCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -647,7 +647,7 @@ type IntSliceCmd struct { var _ Cmder = (*IntSliceCmd)(nil) -func NewIntSliceCmd(ctx context.Context, args ...interface{}) *IntSliceCmd { +func NewIntSliceCmd(ctx context.Context, args ...any) *IntSliceCmd { return &IntSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -697,7 +697,7 @@ type DurationCmd struct { var _ Cmder = (*DurationCmd)(nil) -func NewDurationCmd(ctx context.Context, precision time.Duration, args ...interface{}) *DurationCmd { +func NewDurationCmd(ctx context.Context, precision time.Duration, args ...any) *DurationCmd { return &DurationCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -749,7 +749,7 @@ type TimeCmd struct { var _ Cmder = (*TimeCmd)(nil) -func NewTimeCmd(ctx context.Context, args ...interface{}) *TimeCmd { +func NewTimeCmd(ctx context.Context, args ...any) *TimeCmd { return &TimeCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -800,7 +800,7 @@ type BoolCmd struct { var _ Cmder = (*BoolCmd)(nil) -func NewBoolCmd(ctx context.Context, args ...interface{}) *BoolCmd { +func NewBoolCmd(ctx context.Context, args ...any) *BoolCmd { return &BoolCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -847,7 +847,7 @@ type StringCmd struct { var _ Cmder = (*StringCmd)(nil) -func NewStringCmd(ctx context.Context, args ...interface{}) *StringCmd { +func NewStringCmd(ctx context.Context, args ...any) *StringCmd { return &StringCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -925,7 +925,7 @@ func (cmd *StringCmd) Time() (time.Time, error) { return time.Parse(time.RFC3339Nano, cmd.Val()) } -func (cmd *StringCmd) Scan(val interface{}) error { +func (cmd *StringCmd) Scan(val any) error { if cmd.err != nil { return cmd.err } @@ -951,7 +951,7 @@ type FloatCmd struct { var _ Cmder = (*FloatCmd)(nil) -func NewFloatCmd(ctx context.Context, args ...interface{}) *FloatCmd { +func NewFloatCmd(ctx context.Context, args ...any) *FloatCmd { return &FloatCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -991,7 +991,7 @@ type FloatSliceCmd struct { var _ Cmder = (*FloatSliceCmd)(nil) -func NewFloatSliceCmd(ctx context.Context, args ...interface{}) *FloatSliceCmd { +func NewFloatSliceCmd(ctx context.Context, args ...any) *FloatSliceCmd { return &FloatSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1046,7 +1046,7 @@ type StringSliceCmd struct { var _ Cmder = (*StringSliceCmd)(nil) -func NewStringSliceCmd(ctx context.Context, args ...interface{}) *StringSliceCmd { +func NewStringSliceCmd(ctx context.Context, args ...any) *StringSliceCmd { return &StringSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1071,7 +1071,7 @@ func (cmd *StringSliceCmd) String() string { return cmdString(cmd, cmd.val) } -func (cmd *StringSliceCmd) ScanSlice(container interface{}) error { +func (cmd *StringSliceCmd) ScanSlice(container any) error { return proto.ScanSlice(cmd.Val(), container) } @@ -1109,7 +1109,7 @@ type KeyValueSliceCmd struct { var _ Cmder = (*KeyValueSliceCmd)(nil) -func NewKeyValueSliceCmd(ctx context.Context, args ...interface{}) *KeyValueSliceCmd { +func NewKeyValueSliceCmd(ctx context.Context, args ...any) *KeyValueSliceCmd { return &KeyValueSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1198,7 +1198,7 @@ type BoolSliceCmd struct { var _ Cmder = (*BoolSliceCmd)(nil) -func NewBoolSliceCmd(ctx context.Context, args ...interface{}) *BoolSliceCmd { +func NewBoolSliceCmd(ctx context.Context, args ...any) *BoolSliceCmd { return &BoolSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1247,7 +1247,7 @@ type MapStringStringCmd struct { var _ Cmder = (*MapStringStringCmd)(nil) -func NewMapStringStringCmd(ctx context.Context, args ...interface{}) *MapStringStringCmd { +func NewMapStringStringCmd(ctx context.Context, args ...any) *MapStringStringCmd { return &MapStringStringCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1274,7 +1274,7 @@ func (cmd *MapStringStringCmd) String() string { // Scan scans the results from the map into a destination struct. The map keys // are matched in the Redis struct fields by the `redis:"field"` tag. -func (cmd *MapStringStringCmd) Scan(dest interface{}) error { +func (cmd *MapStringStringCmd) Scan(dest any) error { if cmd.err != nil { return cmd.err } @@ -1326,7 +1326,7 @@ type MapStringIntCmd struct { var _ Cmder = (*MapStringIntCmd)(nil) -func NewMapStringIntCmd(ctx context.Context, args ...interface{}) *MapStringIntCmd { +func NewMapStringIntCmd(ctx context.Context, args ...any) *MapStringIntCmd { return &MapStringIntCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1376,10 +1376,10 @@ func (cmd *MapStringIntCmd) readReply(rd *proto.Reader) error { // ------------------------------------------------------------------------------ type MapStringSliceInterfaceCmd struct { baseCmd - val map[string][]interface{} + val map[string][]any } -func NewMapStringSliceInterfaceCmd(ctx context.Context, args ...interface{}) *MapStringSliceInterfaceCmd { +func NewMapStringSliceInterfaceCmd(ctx context.Context, args ...any) *MapStringSliceInterfaceCmd { return &MapStringSliceInterfaceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1392,15 +1392,15 @@ func (cmd *MapStringSliceInterfaceCmd) String() string { return cmdString(cmd, cmd.val) } -func (cmd *MapStringSliceInterfaceCmd) SetVal(val map[string][]interface{}) { +func (cmd *MapStringSliceInterfaceCmd) SetVal(val map[string][]any) { cmd.val = val } -func (cmd *MapStringSliceInterfaceCmd) Result() (map[string][]interface{}, error) { +func (cmd *MapStringSliceInterfaceCmd) Result() (map[string][]any, error) { return cmd.val, cmd.err } -func (cmd *MapStringSliceInterfaceCmd) Val() map[string][]interface{} { +func (cmd *MapStringSliceInterfaceCmd) Val() map[string][]any { return cmd.val } @@ -1410,7 +1410,7 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) { return err } - cmd.val = make(map[string][]interface{}) + cmd.val = make(map[string][]any) switch readType { case proto.RespMap: @@ -1427,7 +1427,7 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) { if err != nil { return err } - cmd.val[k] = make([]interface{}, nn) + cmd.val[k] = make([]any, nn) for j := 0; j < nn; j++ { value, err := rd.ReadReply() if err != nil { @@ -1454,7 +1454,7 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) { if err != nil { return err } - cmd.val[key] = make([]interface{}, 0, itemLen-1) + cmd.val[key] = make([]any, 0, itemLen-1) for j := 1; j < itemLen; j++ { // Read the inner array for timestamp-value pairs data, err := rd.ReadReply() @@ -1479,7 +1479,7 @@ type StringStructMapCmd struct { var _ Cmder = (*StringStructMapCmd)(nil) -func NewStringStructMapCmd(ctx context.Context, args ...interface{}) *StringStructMapCmd { +func NewStringStructMapCmd(ctx context.Context, args ...any) *StringStructMapCmd { return &StringStructMapCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1525,7 +1525,7 @@ func (cmd *StringStructMapCmd) readReply(rd *proto.Reader) error { type XMessage struct { ID string - Values map[string]interface{} + Values map[string]any } type XMessageSliceCmd struct { @@ -1536,7 +1536,7 @@ type XMessageSliceCmd struct { var _ Cmder = (*XMessageSliceCmd)(nil) -func NewXMessageSliceCmd(ctx context.Context, args ...interface{}) *XMessageSliceCmd { +func NewXMessageSliceCmd(ctx context.Context, args ...any) *XMessageSliceCmd { return &XMessageSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1604,13 +1604,13 @@ func readXMessage(rd *proto.Reader) (XMessage, error) { }, nil } -func stringInterfaceMapParser(rd *proto.Reader) (map[string]interface{}, error) { +func stringInterfaceMapParser(rd *proto.Reader) (map[string]any, error) { n, err := rd.ReadMapLen() if err != nil { return nil, err } - m := make(map[string]interface{}, n) + m := make(map[string]any, n) for i := 0; i < n; i++ { key, err := rd.ReadString() if err != nil { @@ -1642,7 +1642,7 @@ type XStreamSliceCmd struct { var _ Cmder = (*XStreamSliceCmd)(nil) -func NewXStreamSliceCmd(ctx context.Context, args ...interface{}) *XStreamSliceCmd { +func NewXStreamSliceCmd(ctx context.Context, args ...any) *XStreamSliceCmd { return &XStreamSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1715,7 +1715,7 @@ type XPendingCmd struct { var _ Cmder = (*XPendingCmd)(nil) -func NewXPendingCmd(ctx context.Context, args ...interface{}) *XPendingCmd { +func NewXPendingCmd(ctx context.Context, args ...any) *XPendingCmd { return &XPendingCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1798,7 +1798,7 @@ type XPendingExtCmd struct { var _ Cmder = (*XPendingExtCmd)(nil) -func NewXPendingExtCmd(ctx context.Context, args ...interface{}) *XPendingExtCmd { +func NewXPendingExtCmd(ctx context.Context, args ...any) *XPendingExtCmd { return &XPendingExtCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1868,7 +1868,7 @@ type XAutoClaimCmd struct { var _ Cmder = (*XAutoClaimCmd)(nil) -func NewXAutoClaimCmd(ctx context.Context, args ...interface{}) *XAutoClaimCmd { +func NewXAutoClaimCmd(ctx context.Context, args ...any) *XAutoClaimCmd { return &XAutoClaimCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -1938,7 +1938,7 @@ type XAutoClaimJustIDCmd struct { var _ Cmder = (*XAutoClaimJustIDCmd)(nil) -func NewXAutoClaimJustIDCmd(ctx context.Context, args ...interface{}) *XAutoClaimJustIDCmd { +func NewXAutoClaimJustIDCmd(ctx context.Context, args ...any) *XAutoClaimJustIDCmd { return &XAutoClaimJustIDCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -2025,7 +2025,7 @@ func NewXInfoConsumersCmd(ctx context.Context, stream string, group string) *XIn return &XInfoConsumersCmd{ baseCmd: baseCmd{ ctx: ctx, - args: []interface{}{"xinfo", "consumers", stream, group}, + args: []any{"xinfo", "consumers", stream, group}, }, } } @@ -2115,7 +2115,7 @@ func NewXInfoGroupsCmd(ctx context.Context, stream string) *XInfoGroupsCmd { return &XInfoGroupsCmd{ baseCmd: baseCmd{ ctx: ctx, - args: []interface{}{"xinfo", "groups", stream}, + args: []any{"xinfo", "groups", stream}, }, } } @@ -2230,7 +2230,7 @@ func NewXInfoStreamCmd(ctx context.Context, stream string) *XInfoStreamCmd { return &XInfoStreamCmd{ baseCmd: baseCmd{ ctx: ctx, - args: []interface{}{"xinfo", "stream", stream}, + args: []any{"xinfo", "stream", stream}, }, } } @@ -2373,7 +2373,7 @@ type XInfoStreamConsumerPending struct { var _ Cmder = (*XInfoStreamFullCmd)(nil) -func NewXInfoStreamFullCmd(ctx context.Context, args ...interface{}) *XInfoStreamFullCmd { +func NewXInfoStreamFullCmd(ctx context.Context, args ...any) *XInfoStreamFullCmd { return &XInfoStreamFullCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -2672,7 +2672,7 @@ type ZSliceCmd struct { var _ Cmder = (*ZSliceCmd)(nil) -func NewZSliceCmd(ctx context.Context, args ...interface{}) *ZSliceCmd { +func NewZSliceCmd(ctx context.Context, args ...any) *ZSliceCmd { return &ZSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -2750,7 +2750,7 @@ type ZWithKeyCmd struct { var _ Cmder = (*ZWithKeyCmd)(nil) -func NewZWithKeyCmd(ctx context.Context, args ...interface{}) *ZWithKeyCmd { +func NewZWithKeyCmd(ctx context.Context, args ...any) *ZWithKeyCmd { return &ZWithKeyCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -2807,7 +2807,7 @@ type ScanCmd struct { var _ Cmder = (*ScanCmd)(nil) -func NewScanCmd(ctx context.Context, process cmdable, args ...interface{}) *ScanCmd { +func NewScanCmd(ctx context.Context, process cmdable, args ...any) *ScanCmd { return &ScanCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -2888,7 +2888,7 @@ type ClusterSlotsCmd struct { var _ Cmder = (*ClusterSlotsCmd)(nil) -func NewClusterSlotsCmd(ctx context.Context, args ...interface{}) *ClusterSlotsCmd { +func NewClusterSlotsCmd(ctx context.Context, args ...any) *ClusterSlotsCmd { return &ClusterSlotsCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3041,7 +3041,7 @@ type GeoLocationCmd struct { var _ Cmder = (*GeoLocationCmd)(nil) -func NewGeoLocationCmd(ctx context.Context, q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd { +func NewGeoLocationCmd(ctx context.Context, q *GeoRadiusQuery, args ...any) *GeoLocationCmd { return &GeoLocationCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3051,7 +3051,7 @@ func NewGeoLocationCmd(ctx context.Context, q *GeoRadiusQuery, args ...interface } } -func geoLocationArgs(q *GeoRadiusQuery, args ...interface{}) []interface{} { +func geoLocationArgs(q *GeoRadiusQuery, args ...any) []any { args = append(args, q.Radius) if q.Unit != "" { args = append(args, q.Unit) @@ -3197,7 +3197,7 @@ type GeoSearchStoreQuery struct { StoreDist bool } -func geoSearchLocationArgs(q *GeoSearchLocationQuery, args []interface{}) []interface{} { +func geoSearchLocationArgs(q *GeoSearchLocationQuery, args []any) []any { args = geoSearchArgs(&q.GeoSearchQuery, args) if q.WithCoord { @@ -3213,7 +3213,7 @@ func geoSearchLocationArgs(q *GeoSearchLocationQuery, args []interface{}) []inte return args } -func geoSearchArgs(q *GeoSearchQuery, args []interface{}) []interface{} { +func geoSearchArgs(q *GeoSearchQuery, args []any) []any { if q.Member != "" { args = append(args, "frommember", q.Member) } else { @@ -3256,7 +3256,7 @@ type GeoSearchLocationCmd struct { var _ Cmder = (*GeoSearchLocationCmd)(nil) func NewGeoSearchLocationCmd( - ctx context.Context, opt *GeoSearchLocationQuery, args ...interface{}, + ctx context.Context, opt *GeoSearchLocationQuery, args ...any, ) *GeoSearchLocationCmd { return &GeoSearchLocationCmd{ baseCmd: baseCmd{ @@ -3348,7 +3348,7 @@ type GeoPosCmd struct { var _ Cmder = (*GeoPosCmd)(nil) -func NewGeoPosCmd(ctx context.Context, args ...interface{}) *GeoPosCmd { +func NewGeoPosCmd(ctx context.Context, args ...any) *GeoPosCmd { return &GeoPosCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3429,7 +3429,7 @@ type CommandsInfoCmd struct { var _ Cmder = (*CommandsInfoCmd)(nil) -func NewCommandsInfoCmd(ctx context.Context, args ...interface{}) *CommandsInfoCmd { +func NewCommandsInfoCmd(ctx context.Context, args ...any) *CommandsInfoCmd { return &CommandsInfoCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3619,7 +3619,7 @@ type SlowLogCmd struct { var _ Cmder = (*SlowLogCmd)(nil) -func NewSlowLogCmd(ctx context.Context, args ...interface{}) *SlowLogCmd { +func NewSlowLogCmd(ctx context.Context, args ...any) *SlowLogCmd { return &SlowLogCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3713,12 +3713,12 @@ func (cmd *SlowLogCmd) readReply(rd *proto.Reader) error { type MapStringInterfaceCmd struct { baseCmd - val map[string]interface{} + val map[string]any } var _ Cmder = (*MapStringInterfaceCmd)(nil) -func NewMapStringInterfaceCmd(ctx context.Context, args ...interface{}) *MapStringInterfaceCmd { +func NewMapStringInterfaceCmd(ctx context.Context, args ...any) *MapStringInterfaceCmd { return &MapStringInterfaceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3727,15 +3727,15 @@ func NewMapStringInterfaceCmd(ctx context.Context, args ...interface{}) *MapStri } } -func (cmd *MapStringInterfaceCmd) SetVal(val map[string]interface{}) { +func (cmd *MapStringInterfaceCmd) SetVal(val map[string]any) { cmd.val = val } -func (cmd *MapStringInterfaceCmd) Val() map[string]interface{} { +func (cmd *MapStringInterfaceCmd) Val() map[string]any { return cmd.val } -func (cmd *MapStringInterfaceCmd) Result() (map[string]interface{}, error) { +func (cmd *MapStringInterfaceCmd) Result() (map[string]any, error) { return cmd.val, cmd.err } @@ -3749,7 +3749,7 @@ func (cmd *MapStringInterfaceCmd) readReply(rd *proto.Reader) error { return err } - cmd.val = make(map[string]interface{}, n) + cmd.val = make(map[string]any, n) for i := 0; i < n; i++ { k, err := rd.ReadString() if err != nil { @@ -3782,7 +3782,7 @@ type MapStringStringSliceCmd struct { var _ Cmder = (*MapStringStringSliceCmd)(nil) -func NewMapStringStringSliceCmd(ctx context.Context, args ...interface{}) *MapStringStringSliceCmd { +func NewMapStringStringSliceCmd(ctx context.Context, args ...any) *MapStringStringSliceCmd { return &MapStringStringSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3838,13 +3838,13 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error { // ----------------------------------------------------------------------- -// MapMapStringInterfaceCmd represents a command that returns a map of strings to interface{}. +// MapMapStringInterfaceCmd represents a command that returns a map of strings to any. type MapMapStringInterfaceCmd struct { baseCmd - val map[string]interface{} + val map[string]any } -func NewMapMapStringInterfaceCmd(ctx context.Context, args ...interface{}) *MapMapStringInterfaceCmd { +func NewMapMapStringInterfaceCmd(ctx context.Context, args ...any) *MapMapStringInterfaceCmd { return &MapMapStringInterfaceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3857,15 +3857,15 @@ func (cmd *MapMapStringInterfaceCmd) String() string { return cmdString(cmd, cmd.val) } -func (cmd *MapMapStringInterfaceCmd) SetVal(val map[string]interface{}) { +func (cmd *MapMapStringInterfaceCmd) SetVal(val map[string]any) { cmd.val = val } -func (cmd *MapMapStringInterfaceCmd) Result() (map[string]interface{}, error) { +func (cmd *MapMapStringInterfaceCmd) Result() (map[string]any, error) { return cmd.val, cmd.err } -func (cmd *MapMapStringInterfaceCmd) Val() map[string]interface{} { +func (cmd *MapMapStringInterfaceCmd) Val() map[string]any { return cmd.val } @@ -3875,10 +3875,10 @@ func (cmd *MapMapStringInterfaceCmd) readReply(rd *proto.Reader) (err error) { if err != nil { return err } - resultMap := map[string]interface{}{} + resultMap := map[string]any{} switch midResponse := data.(type) { - case map[interface{}]interface{}: // resp3 will return map + case map[any]any: // resp3 will return map for k, v := range midResponse { stringKey, ok := k.(string) if !ok { @@ -3886,10 +3886,10 @@ func (cmd *MapMapStringInterfaceCmd) readReply(rd *proto.Reader) (err error) { } resultMap[stringKey] = v } - case []interface{}: // resp2 will return array of arrays + case []any: // resp2 will return array of arrays n := len(midResponse) for i := 0; i < n; i++ { - finalArr, ok := midResponse[i].([]interface{}) // final array that we need to transform to map + finalArr, ok := midResponse[i].([]any) // final array that we need to transform to map if !ok { return fmt.Errorf("redis: unexpected response %#v", data) } @@ -3919,12 +3919,12 @@ func (cmd *MapMapStringInterfaceCmd) readReply(rd *proto.Reader) (err error) { type MapStringInterfaceSliceCmd struct { baseCmd - val []map[string]interface{} + val []map[string]any } var _ Cmder = (*MapStringInterfaceSliceCmd)(nil) -func NewMapStringInterfaceSliceCmd(ctx context.Context, args ...interface{}) *MapStringInterfaceSliceCmd { +func NewMapStringInterfaceSliceCmd(ctx context.Context, args ...any) *MapStringInterfaceSliceCmd { return &MapStringInterfaceSliceCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -3933,15 +3933,15 @@ func NewMapStringInterfaceSliceCmd(ctx context.Context, args ...interface{}) *Ma } } -func (cmd *MapStringInterfaceSliceCmd) SetVal(val []map[string]interface{}) { +func (cmd *MapStringInterfaceSliceCmd) SetVal(val []map[string]any) { cmd.val = val } -func (cmd *MapStringInterfaceSliceCmd) Val() []map[string]interface{} { +func (cmd *MapStringInterfaceSliceCmd) Val() []map[string]any { return cmd.val } -func (cmd *MapStringInterfaceSliceCmd) Result() ([]map[string]interface{}, error) { +func (cmd *MapStringInterfaceSliceCmd) Result() ([]map[string]any, error) { return cmd.val, cmd.err } @@ -3955,13 +3955,13 @@ func (cmd *MapStringInterfaceSliceCmd) readReply(rd *proto.Reader) error { return err } - cmd.val = make([]map[string]interface{}, n) + cmd.val = make([]map[string]any, n) for i := 0; i < n; i++ { nn, err := rd.ReadMapLen() if err != nil { return err } - cmd.val[i] = make(map[string]interface{}, nn) + cmd.val[i] = make(map[string]any, nn) for f := 0; f < nn; f++ { k, err := rd.ReadString() if err != nil { @@ -3990,7 +3990,7 @@ type KeyValuesCmd struct { var _ Cmder = (*KeyValuesCmd)(nil) -func NewKeyValuesCmd(ctx context.Context, args ...interface{}) *KeyValuesCmd { +func NewKeyValuesCmd(ctx context.Context, args ...any) *KeyValuesCmd { return &KeyValuesCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -4052,7 +4052,7 @@ type ZSliceWithKeyCmd struct { var _ Cmder = (*ZSliceWithKeyCmd)(nil) -func NewZSliceWithKeyCmd(ctx context.Context, args ...interface{}) *ZSliceWithKeyCmd { +func NewZSliceWithKeyCmd(ctx context.Context, args ...any) *ZSliceWithKeyCmd { return &ZSliceWithKeyCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -4145,7 +4145,7 @@ type FunctionListCmd struct { var _ Cmder = (*FunctionListCmd)(nil) -func NewFunctionListCmd(ctx context.Context, args ...interface{}) *FunctionListCmd { +func NewFunctionListCmd(ctx context.Context, args ...any) *FunctionListCmd { return &FunctionListCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -4326,7 +4326,7 @@ type FunctionStatsCmd struct { var _ Cmder = (*FunctionStatsCmd)(nil) -func NewFunctionStatsCmd(ctx context.Context, args ...interface{}) *FunctionStatsCmd { +func NewFunctionStatsCmd(ctx context.Context, args ...any) *FunctionStatsCmd { return &FunctionStatsCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -4544,7 +4544,7 @@ type LCSCmd struct { } func NewLCSCmd(ctx context.Context, q *LCSQuery) *LCSCmd { - args := make([]interface{}, 3, 7) + args := make([]any, 3, 7) args[0] = "lcs" args[1] = q.Key1 args[2] = q.Key2 @@ -4692,7 +4692,7 @@ type KeyFlagsCmd struct { var _ Cmder = (*KeyFlagsCmd)(nil) -func NewKeyFlagsCmd(ctx context.Context, args ...interface{}) *KeyFlagsCmd { +func NewKeyFlagsCmd(ctx context.Context, args ...any) *KeyFlagsCmd { return &KeyFlagsCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -4774,7 +4774,7 @@ type ClusterLinksCmd struct { var _ Cmder = (*ClusterLinksCmd)(nil) -func NewClusterLinksCmd(ctx context.Context, args ...interface{}) *ClusterLinksCmd { +func NewClusterLinksCmd(ctx context.Context, args ...any) *ClusterLinksCmd { return &ClusterLinksCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -4876,7 +4876,7 @@ type ClusterShardsCmd struct { var _ Cmder = (*ClusterShardsCmd)(nil) -func NewClusterShardsCmd(ctx context.Context, args ...interface{}) *ClusterShardsCmd { +func NewClusterShardsCmd(ctx context.Context, args ...any) *ClusterShardsCmd { return &ClusterShardsCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -5009,7 +5009,7 @@ type RankWithScoreCmd struct { var _ Cmder = (*RankWithScoreCmd)(nil) -func NewRankWithScoreCmd(ctx context.Context, args ...interface{}) *RankWithScoreCmd { +func NewRankWithScoreCmd(ctx context.Context, args ...any) *RankWithScoreCmd { return &RankWithScoreCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -5157,7 +5157,7 @@ type ClientInfoCmd struct { var _ Cmder = (*ClientInfoCmd)(nil) -func NewClientInfoCmd(ctx context.Context, args ...interface{}) *ClientInfoCmd { +func NewClientInfoCmd(ctx context.Context, args ...any) *ClientInfoCmd { return &ClientInfoCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -5355,7 +5355,7 @@ type ACLLogCmd struct { var _ Cmder = (*ACLLogCmd)(nil) -func NewACLLogCmd(ctx context.Context, args ...interface{}) *ACLLogCmd { +func NewACLLogCmd(ctx context.Context, args ...any) *ACLLogCmd { return &ACLLogCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -5466,7 +5466,7 @@ type InfoCmd struct { var _ Cmder = (*InfoCmd)(nil) -func NewInfoCmd(ctx context.Context, args ...interface{}) *InfoCmd { +func NewInfoCmd(ctx context.Context, args ...any) *InfoCmd { return &InfoCmd{ baseCmd: baseCmd{ ctx: ctx, @@ -5555,7 +5555,7 @@ func newMonitorCmd(ctx context.Context, ch chan string) *MonitorCmd { return &MonitorCmd{ baseCmd: baseCmd{ ctx: ctx, - args: []interface{}{"monitor"}, + args: []any{"monitor"}, }, ch: ch, status: monitorStatusIdle, diff --git a/commands.go b/commands.go index 271323242..18246ef73 100644 --- a/commands.go +++ b/commands.go @@ -50,7 +50,7 @@ func formatSec(ctx context.Context, dur time.Duration) int64 { return int64(dur / time.Second) } -func appendArgs(dst, src []interface{}) []interface{} { +func appendArgs(dst, src []any) []any { if len(src) == 1 { return appendArg(dst, src[0]) } @@ -59,17 +59,17 @@ func appendArgs(dst, src []interface{}) []interface{} { return dst } -func appendArg(dst []interface{}, arg interface{}) []interface{} { +func appendArg(dst []any, arg any) []any { switch arg := arg.(type) { case []string: for _, s := range arg { dst = append(dst, s) } return dst - case []interface{}: + case []any: dst = append(dst, arg...) return dst - case map[string]interface{}: + case map[string]any: for k, v := range arg { dst = append(dst, k, v) } @@ -103,7 +103,7 @@ func appendArg(dst []interface{}, arg interface{}) []interface{} { } // appendStructField appends the field and value held by the structure v to dst, and returns the appended dst. -func appendStructField(dst []interface{}, v reflect.Value) []interface{} { +func appendStructField(dst []any, v reflect.Value) []any { typ := v.Type() for i := 0; i < typ.NumField(); i++ { tag := typ.Field(i).Tag.Get("redis") @@ -174,10 +174,10 @@ type Cmdable interface { Command(ctx context.Context) *CommandsInfoCmd CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd - CommandGetKeys(ctx context.Context, commands ...interface{}) *StringSliceCmd - CommandGetKeysAndFlags(ctx context.Context, commands ...interface{}) *KeyFlagsCmd + CommandGetKeys(ctx context.Context, commands ...any) *StringSliceCmd + CommandGetKeysAndFlags(ctx context.Context, commands ...any) *KeyFlagsCmd ClientGetName(ctx context.Context) *StringCmd - Echo(ctx context.Context, message interface{}) *StringCmd + Echo(ctx context.Context, message any) *StringCmd Ping(ctx context.Context) *StatusCmd Quit(ctx context.Context) *StatusCmd Unlink(ctx context.Context, keys ...string) *IntCmd @@ -342,7 +342,7 @@ func (info LibraryInfo) Validate() error { func (c statefulCmdable) Hello(ctx context.Context, ver int, username, password, clientName string, ) *MapStringInterfaceCmd { - args := make([]interface{}, 0, 7) + args := make([]any, 0, 7) args = append(args, "hello", ver) if password != "" { if username != "" { @@ -375,7 +375,7 @@ type FilterBy struct { } func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd { - args := make([]interface{}, 0, 5) + args := make([]any, 0, 5) args = append(args, "command", "list") if filter != nil { if filter.Module != "" { @@ -391,8 +391,8 @@ func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSlice return cmd } -func (c cmdable) CommandGetKeys(ctx context.Context, commands ...interface{}) *StringSliceCmd { - args := make([]interface{}, 2+len(commands)) +func (c cmdable) CommandGetKeys(ctx context.Context, commands ...any) *StringSliceCmd { + args := make([]any, 2+len(commands)) args[0] = "command" args[1] = "getkeys" copy(args[2:], commands) @@ -401,8 +401,8 @@ func (c cmdable) CommandGetKeys(ctx context.Context, commands ...interface{}) *S return cmd } -func (c cmdable) CommandGetKeysAndFlags(ctx context.Context, commands ...interface{}) *KeyFlagsCmd { - args := make([]interface{}, 2+len(commands)) +func (c cmdable) CommandGetKeysAndFlags(ctx context.Context, commands ...any) *KeyFlagsCmd { + args := make([]any, 2+len(commands)) args[0] = "command" args[1] = "getkeysandflags" copy(args[2:], commands) @@ -418,7 +418,7 @@ func (c cmdable) ClientGetName(ctx context.Context) *StringCmd { return cmd } -func (c cmdable) Echo(ctx context.Context, message interface{}) *StringCmd { +func (c cmdable) Echo(ctx context.Context, message any) *StringCmd { cmd := NewStringCmd(ctx, "echo", message) _ = c(ctx, cmd) return cmd @@ -430,7 +430,7 @@ func (c cmdable) Ping(ctx context.Context) *StatusCmd { return cmd } -func (c cmdable) Do(ctx context.Context, args ...interface{}) *Cmd { +func (c cmdable) Do(ctx context.Context, args ...any) *Cmd { cmd := NewCmd(ctx, args...) _ = c(ctx, cmd) return cmd @@ -464,7 +464,7 @@ func (c cmdable) ClientKill(ctx context.Context, ipPort string) *StatusCmd { // // CLIENT KILL