mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Add ctx as first arg
This commit is contained in:
195
command.go
195
command.go
@ -1,6 +1,7 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -95,6 +96,7 @@ func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int {
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
type baseCmd struct {
|
||||
ctx context.Context
|
||||
args []interface{}
|
||||
err error
|
||||
|
||||
@ -147,9 +149,12 @@ type Cmd struct {
|
||||
val interface{}
|
||||
}
|
||||
|
||||
func NewCmd(args ...interface{}) *Cmd {
|
||||
func NewCmd(ctx context.Context, args ...interface{}) *Cmd {
|
||||
return &Cmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,9 +313,12 @@ type SliceCmd struct {
|
||||
|
||||
var _ Cmder = (*SliceCmd)(nil)
|
||||
|
||||
func NewSliceCmd(args ...interface{}) *SliceCmd {
|
||||
func NewSliceCmd(ctx context.Context, args ...interface{}) *SliceCmd {
|
||||
return &SliceCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,9 +354,12 @@ type StatusCmd struct {
|
||||
|
||||
var _ Cmder = (*StatusCmd)(nil)
|
||||
|
||||
func NewStatusCmd(args ...interface{}) *StatusCmd {
|
||||
func NewStatusCmd(ctx context.Context, args ...interface{}) *StatusCmd {
|
||||
return &StatusCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,9 +390,12 @@ type IntCmd struct {
|
||||
|
||||
var _ Cmder = (*IntCmd)(nil)
|
||||
|
||||
func NewIntCmd(args ...interface{}) *IntCmd {
|
||||
func NewIntCmd(ctx context.Context, args ...interface{}) *IntCmd {
|
||||
return &IntCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,9 +430,12 @@ type IntSliceCmd struct {
|
||||
|
||||
var _ Cmder = (*IntSliceCmd)(nil)
|
||||
|
||||
func NewIntSliceCmd(args ...interface{}) *IntSliceCmd {
|
||||
func NewIntSliceCmd(ctx context.Context, args ...interface{}) *IntSliceCmd {
|
||||
return &IntSliceCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,9 +477,12 @@ type DurationCmd struct {
|
||||
|
||||
var _ Cmder = (*DurationCmd)(nil)
|
||||
|
||||
func NewDurationCmd(precision time.Duration, args ...interface{}) *DurationCmd {
|
||||
func NewDurationCmd(ctx context.Context, precision time.Duration, args ...interface{}) *DurationCmd {
|
||||
return &DurationCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
precision: precision,
|
||||
}
|
||||
}
|
||||
@ -506,9 +526,12 @@ type TimeCmd struct {
|
||||
|
||||
var _ Cmder = (*TimeCmd)(nil)
|
||||
|
||||
func NewTimeCmd(args ...interface{}) *TimeCmd {
|
||||
func NewTimeCmd(ctx context.Context, args ...interface{}) *TimeCmd {
|
||||
return &TimeCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -556,9 +579,12 @@ type BoolCmd struct {
|
||||
|
||||
var _ Cmder = (*BoolCmd)(nil)
|
||||
|
||||
func NewBoolCmd(args ...interface{}) *BoolCmd {
|
||||
func NewBoolCmd(ctx context.Context, args ...interface{}) *BoolCmd {
|
||||
return &BoolCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -610,9 +636,12 @@ type StringCmd struct {
|
||||
|
||||
var _ Cmder = (*StringCmd)(nil)
|
||||
|
||||
func NewStringCmd(args ...interface{}) *StringCmd {
|
||||
func NewStringCmd(ctx context.Context, args ...interface{}) *StringCmd {
|
||||
return &StringCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -700,9 +729,12 @@ type FloatCmd struct {
|
||||
|
||||
var _ Cmder = (*FloatCmd)(nil)
|
||||
|
||||
func NewFloatCmd(args ...interface{}) *FloatCmd {
|
||||
func NewFloatCmd(ctx context.Context, args ...interface{}) *FloatCmd {
|
||||
return &FloatCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -733,9 +765,12 @@ type StringSliceCmd struct {
|
||||
|
||||
var _ Cmder = (*StringSliceCmd)(nil)
|
||||
|
||||
func NewStringSliceCmd(args ...interface{}) *StringSliceCmd {
|
||||
func NewStringSliceCmd(ctx context.Context, args ...interface{}) *StringSliceCmd {
|
||||
return &StringSliceCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -783,9 +818,12 @@ type BoolSliceCmd struct {
|
||||
|
||||
var _ Cmder = (*BoolSliceCmd)(nil)
|
||||
|
||||
func NewBoolSliceCmd(args ...interface{}) *BoolSliceCmd {
|
||||
func NewBoolSliceCmd(ctx context.Context, args ...interface{}) *BoolSliceCmd {
|
||||
return &BoolSliceCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -826,9 +864,12 @@ type StringStringMapCmd struct {
|
||||
|
||||
var _ Cmder = (*StringStringMapCmd)(nil)
|
||||
|
||||
func NewStringStringMapCmd(args ...interface{}) *StringStringMapCmd {
|
||||
func NewStringStringMapCmd(ctx context.Context, args ...interface{}) *StringStringMapCmd {
|
||||
return &StringStringMapCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -875,9 +916,12 @@ type StringIntMapCmd struct {
|
||||
|
||||
var _ Cmder = (*StringIntMapCmd)(nil)
|
||||
|
||||
func NewStringIntMapCmd(args ...interface{}) *StringIntMapCmd {
|
||||
func NewStringIntMapCmd(ctx context.Context, args ...interface{}) *StringIntMapCmd {
|
||||
return &StringIntMapCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -924,9 +968,12 @@ type StringStructMapCmd struct {
|
||||
|
||||
var _ Cmder = (*StringStructMapCmd)(nil)
|
||||
|
||||
func NewStringStructMapCmd(args ...interface{}) *StringStructMapCmd {
|
||||
func NewStringStructMapCmd(ctx context.Context, args ...interface{}) *StringStructMapCmd {
|
||||
return &StringStructMapCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -972,9 +1019,12 @@ type XMessageSliceCmd struct {
|
||||
|
||||
var _ Cmder = (*XMessageSliceCmd)(nil)
|
||||
|
||||
func NewXMessageSliceCmd(args ...interface{}) *XMessageSliceCmd {
|
||||
func NewXMessageSliceCmd(ctx context.Context, args ...interface{}) *XMessageSliceCmd {
|
||||
return &XMessageSliceCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1069,9 +1119,12 @@ type XStreamSliceCmd struct {
|
||||
|
||||
var _ Cmder = (*XStreamSliceCmd)(nil)
|
||||
|
||||
func NewXStreamSliceCmd(args ...interface{}) *XStreamSliceCmd {
|
||||
func NewXStreamSliceCmd(ctx context.Context, args ...interface{}) *XStreamSliceCmd {
|
||||
return &XStreamSliceCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1138,9 +1191,12 @@ type XPendingCmd struct {
|
||||
|
||||
var _ Cmder = (*XPendingCmd)(nil)
|
||||
|
||||
func NewXPendingCmd(args ...interface{}) *XPendingCmd {
|
||||
func NewXPendingCmd(ctx context.Context, args ...interface{}) *XPendingCmd {
|
||||
return &XPendingCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1237,9 +1293,12 @@ type XPendingExtCmd struct {
|
||||
|
||||
var _ Cmder = (*XPendingExtCmd)(nil)
|
||||
|
||||
func NewXPendingExtCmd(args ...interface{}) *XPendingExtCmd {
|
||||
func NewXPendingExtCmd(ctx context.Context, args ...interface{}) *XPendingExtCmd {
|
||||
return &XPendingExtCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1317,9 +1376,12 @@ type XInfoGroups struct {
|
||||
|
||||
var _ Cmder = (*XInfoGroupsCmd)(nil)
|
||||
|
||||
func NewXInfoGroupsCmd(stream string) *XInfoGroupsCmd {
|
||||
func NewXInfoGroupsCmd(ctx context.Context, stream string) *XInfoGroupsCmd {
|
||||
return &XInfoGroupsCmd{
|
||||
baseCmd: baseCmd{args: []interface{}{"xinfo", "groups", stream}},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: []interface{}{"xinfo", "groups", stream},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1401,9 +1463,12 @@ type ZSliceCmd struct {
|
||||
|
||||
var _ Cmder = (*ZSliceCmd)(nil)
|
||||
|
||||
func NewZSliceCmd(args ...interface{}) *ZSliceCmd {
|
||||
func NewZSliceCmd(ctx context.Context, args ...interface{}) *ZSliceCmd {
|
||||
return &ZSliceCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1453,9 +1518,12 @@ type ZWithKeyCmd struct {
|
||||
|
||||
var _ Cmder = (*ZWithKeyCmd)(nil)
|
||||
|
||||
func NewZWithKeyCmd(args ...interface{}) *ZWithKeyCmd {
|
||||
func NewZWithKeyCmd(ctx context.Context, args ...interface{}) *ZWithKeyCmd {
|
||||
return &ZWithKeyCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1508,14 +1576,17 @@ type ScanCmd struct {
|
||||
page []string
|
||||
cursor uint64
|
||||
|
||||
process func(cmd Cmder) error
|
||||
process cmdable
|
||||
}
|
||||
|
||||
var _ Cmder = (*ScanCmd)(nil)
|
||||
|
||||
func NewScanCmd(process func(cmd Cmder) error, args ...interface{}) *ScanCmd {
|
||||
func NewScanCmd(ctx context.Context, process cmdable, args ...interface{}) *ScanCmd {
|
||||
return &ScanCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
process: process,
|
||||
}
|
||||
}
|
||||
@ -1565,9 +1636,12 @@ type ClusterSlotsCmd struct {
|
||||
|
||||
var _ Cmder = (*ClusterSlotsCmd)(nil)
|
||||
|
||||
func NewClusterSlotsCmd(args ...interface{}) *ClusterSlotsCmd {
|
||||
func NewClusterSlotsCmd(ctx context.Context, args ...interface{}) *ClusterSlotsCmd {
|
||||
return &ClusterSlotsCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1682,10 +1756,13 @@ type GeoLocationCmd struct {
|
||||
|
||||
var _ Cmder = (*GeoLocationCmd)(nil)
|
||||
|
||||
func NewGeoLocationCmd(q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd {
|
||||
func NewGeoLocationCmd(ctx context.Context, q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd {
|
||||
return &GeoLocationCmd{
|
||||
baseCmd: baseCmd{args: geoLocationArgs(q, args...)},
|
||||
q: q,
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: geoLocationArgs(q, args...),
|
||||
},
|
||||
q: q,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1826,9 +1903,12 @@ type GeoPosCmd struct {
|
||||
|
||||
var _ Cmder = (*GeoPosCmd)(nil)
|
||||
|
||||
func NewGeoPosCmd(args ...interface{}) *GeoPosCmd {
|
||||
func NewGeoPosCmd(ctx context.Context, args ...interface{}) *GeoPosCmd {
|
||||
return &GeoPosCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -1899,9 +1979,12 @@ type CommandsInfoCmd struct {
|
||||
|
||||
var _ Cmder = (*CommandsInfoCmd)(nil)
|
||||
|
||||
func NewCommandsInfoCmd(args ...interface{}) *CommandsInfoCmd {
|
||||
func NewCommandsInfoCmd(ctx context.Context, args ...interface{}) *CommandsInfoCmd {
|
||||
return &CommandsInfoCmd{
|
||||
baseCmd: baseCmd{args: args},
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user