This commit is contained in:
Vladimir Mihailenco 2019-08-24 11:55:13 +03:00
parent 2c55c0b55a
commit 5776216677
3 changed files with 43 additions and 44 deletions

View File

@ -17,11 +17,10 @@ type Cmder interface {
Args() []interface{} Args() []interface{}
stringArg(int) string stringArg(int) string
readReply(rd *proto.Reader) error
setErr(error)
readTimeout() *time.Duration readTimeout() *time.Duration
readReply(rd *proto.Reader) error
setErr(error)
Err() error Err() error
} }
@ -92,8 +91,8 @@ func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
type baseCmd struct { type baseCmd struct {
_args []interface{} args []interface{}
err error err error
_readTimeout *time.Duration _readTimeout *time.Duration
} }
@ -101,7 +100,7 @@ type baseCmd struct {
var _ Cmder = (*Cmd)(nil) var _ Cmder = (*Cmd)(nil)
func (cmd *baseCmd) Name() string { func (cmd *baseCmd) Name() string {
if len(cmd._args) == 0 { if len(cmd.args) == 0 {
return "" return ""
} }
// Cmd name must be lower cased. // Cmd name must be lower cased.
@ -109,14 +108,14 @@ func (cmd *baseCmd) Name() string {
} }
func (cmd *baseCmd) Args() []interface{} { func (cmd *baseCmd) Args() []interface{} {
return cmd._args return cmd.args
} }
func (cmd *baseCmd) stringArg(pos int) string { func (cmd *baseCmd) stringArg(pos int) string {
if pos < 0 || pos >= len(cmd._args) { if pos < 0 || pos >= len(cmd.args) {
return "" return ""
} }
s, _ := cmd._args[pos].(string) s, _ := cmd.args[pos].(string)
return s return s
} }
@ -146,7 +145,7 @@ type Cmd struct {
func NewCmd(args ...interface{}) *Cmd { func NewCmd(args ...interface{}) *Cmd {
return &Cmd{ return &Cmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -303,7 +302,7 @@ var _ Cmder = (*SliceCmd)(nil)
func NewSliceCmd(args ...interface{}) *SliceCmd { func NewSliceCmd(args ...interface{}) *SliceCmd {
return &SliceCmd{ return &SliceCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -341,7 +340,7 @@ var _ Cmder = (*StatusCmd)(nil)
func NewStatusCmd(args ...interface{}) *StatusCmd { func NewStatusCmd(args ...interface{}) *StatusCmd {
return &StatusCmd{ return &StatusCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -374,7 +373,7 @@ var _ Cmder = (*IntCmd)(nil)
func NewIntCmd(args ...interface{}) *IntCmd { func NewIntCmd(args ...interface{}) *IntCmd {
return &IntCmd{ return &IntCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -407,7 +406,7 @@ var _ Cmder = (*IntSliceCmd)(nil)
func NewIntSliceCmd(args ...interface{}) *IntSliceCmd { func NewIntSliceCmd(args ...interface{}) *IntSliceCmd {
return &IntSliceCmd{ return &IntSliceCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -451,7 +450,7 @@ var _ Cmder = (*DurationCmd)(nil)
func NewDurationCmd(precision time.Duration, args ...interface{}) *DurationCmd { func NewDurationCmd(precision time.Duration, args ...interface{}) *DurationCmd {
return &DurationCmd{ return &DurationCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
precision: precision, precision: precision,
} }
} }
@ -497,7 +496,7 @@ var _ Cmder = (*TimeCmd)(nil)
func NewTimeCmd(args ...interface{}) *TimeCmd { func NewTimeCmd(args ...interface{}) *TimeCmd {
return &TimeCmd{ return &TimeCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -547,7 +546,7 @@ var _ Cmder = (*BoolCmd)(nil)
func NewBoolCmd(args ...interface{}) *BoolCmd { func NewBoolCmd(args ...interface{}) *BoolCmd {
return &BoolCmd{ return &BoolCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -601,7 +600,7 @@ var _ Cmder = (*StringCmd)(nil)
func NewStringCmd(args ...interface{}) *StringCmd { func NewStringCmd(args ...interface{}) *StringCmd {
return &StringCmd{ return &StringCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -691,7 +690,7 @@ var _ Cmder = (*FloatCmd)(nil)
func NewFloatCmd(args ...interface{}) *FloatCmd { func NewFloatCmd(args ...interface{}) *FloatCmd {
return &FloatCmd{ return &FloatCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -724,7 +723,7 @@ var _ Cmder = (*StringSliceCmd)(nil)
func NewStringSliceCmd(args ...interface{}) *StringSliceCmd { func NewStringSliceCmd(args ...interface{}) *StringSliceCmd {
return &StringSliceCmd{ return &StringSliceCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -774,7 +773,7 @@ var _ Cmder = (*BoolSliceCmd)(nil)
func NewBoolSliceCmd(args ...interface{}) *BoolSliceCmd { func NewBoolSliceCmd(args ...interface{}) *BoolSliceCmd {
return &BoolSliceCmd{ return &BoolSliceCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -817,7 +816,7 @@ var _ Cmder = (*StringStringMapCmd)(nil)
func NewStringStringMapCmd(args ...interface{}) *StringStringMapCmd { func NewStringStringMapCmd(args ...interface{}) *StringStringMapCmd {
return &StringStringMapCmd{ return &StringStringMapCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -866,7 +865,7 @@ var _ Cmder = (*StringIntMapCmd)(nil)
func NewStringIntMapCmd(args ...interface{}) *StringIntMapCmd { func NewStringIntMapCmd(args ...interface{}) *StringIntMapCmd {
return &StringIntMapCmd{ return &StringIntMapCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -915,7 +914,7 @@ var _ Cmder = (*StringStructMapCmd)(nil)
func NewStringStructMapCmd(args ...interface{}) *StringStructMapCmd { func NewStringStructMapCmd(args ...interface{}) *StringStructMapCmd {
return &StringStructMapCmd{ return &StringStructMapCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -963,7 +962,7 @@ var _ Cmder = (*XMessageSliceCmd)(nil)
func NewXMessageSliceCmd(args ...interface{}) *XMessageSliceCmd { func NewXMessageSliceCmd(args ...interface{}) *XMessageSliceCmd {
return &XMessageSliceCmd{ return &XMessageSliceCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -1054,7 +1053,7 @@ var _ Cmder = (*XStreamSliceCmd)(nil)
func NewXStreamSliceCmd(args ...interface{}) *XStreamSliceCmd { func NewXStreamSliceCmd(args ...interface{}) *XStreamSliceCmd {
return &XStreamSliceCmd{ return &XStreamSliceCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -1123,7 +1122,7 @@ var _ Cmder = (*XPendingCmd)(nil)
func NewXPendingCmd(args ...interface{}) *XPendingCmd { func NewXPendingCmd(args ...interface{}) *XPendingCmd {
return &XPendingCmd{ return &XPendingCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -1222,7 +1221,7 @@ var _ Cmder = (*XPendingExtCmd)(nil)
func NewXPendingExtCmd(args ...interface{}) *XPendingExtCmd { func NewXPendingExtCmd(args ...interface{}) *XPendingExtCmd {
return &XPendingExtCmd{ return &XPendingExtCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -1296,7 +1295,7 @@ var _ Cmder = (*ZSliceCmd)(nil)
func NewZSliceCmd(args ...interface{}) *ZSliceCmd { func NewZSliceCmd(args ...interface{}) *ZSliceCmd {
return &ZSliceCmd{ return &ZSliceCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -1348,7 +1347,7 @@ var _ Cmder = (*ZWithKeyCmd)(nil)
func NewZWithKeyCmd(args ...interface{}) *ZWithKeyCmd { func NewZWithKeyCmd(args ...interface{}) *ZWithKeyCmd {
return &ZWithKeyCmd{ return &ZWithKeyCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -1408,7 +1407,7 @@ var _ Cmder = (*ScanCmd)(nil)
func NewScanCmd(process func(cmd Cmder) error, args ...interface{}) *ScanCmd { func NewScanCmd(process func(cmd Cmder) error, args ...interface{}) *ScanCmd {
return &ScanCmd{ return &ScanCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
process: process, process: process,
} }
} }
@ -1460,7 +1459,7 @@ var _ Cmder = (*ClusterSlotsCmd)(nil)
func NewClusterSlotsCmd(args ...interface{}) *ClusterSlotsCmd { func NewClusterSlotsCmd(args ...interface{}) *ClusterSlotsCmd {
return &ClusterSlotsCmd{ return &ClusterSlotsCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -1577,7 +1576,7 @@ var _ Cmder = (*GeoLocationCmd)(nil)
func NewGeoLocationCmd(q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd { func NewGeoLocationCmd(q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd {
return &GeoLocationCmd{ return &GeoLocationCmd{
baseCmd: baseCmd{_args: geoLocationArgs(q, args...)}, baseCmd: baseCmd{args: geoLocationArgs(q, args...)},
q: q, q: q,
} }
} }
@ -1721,7 +1720,7 @@ var _ Cmder = (*GeoPosCmd)(nil)
func NewGeoPosCmd(args ...interface{}) *GeoPosCmd { func NewGeoPosCmd(args ...interface{}) *GeoPosCmd {
return &GeoPosCmd{ return &GeoPosCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }
@ -1795,7 +1794,7 @@ var _ Cmder = (*CommandsInfoCmd)(nil)
func NewCommandsInfoCmd(args ...interface{}) *CommandsInfoCmd { func NewCommandsInfoCmd(args ...interface{}) *CommandsInfoCmd {
return &CommandsInfoCmd{ return &CommandsInfoCmd{
baseCmd: baseCmd{_args: args}, baseCmd: baseCmd{args: args},
} }
} }

View File

@ -43,10 +43,10 @@ func (it *ScanIterator) Next() bool {
} }
// Fetch next page. // Fetch next page.
if it.cmd._args[0] == "scan" { if it.cmd.args[0] == "scan" {
it.cmd._args[1] = it.cmd.cursor it.cmd.args[1] = it.cmd.cursor
} else { } else {
it.cmd._args[2] = it.cmd.cursor it.cmd.args[2] = it.cmd.cursor
} }
err := it.cmd.process(it.cmd) err := it.cmd.process(it.cmd)

View File

@ -46,7 +46,7 @@ func (hs hooks) process(
cmdErr := fn(ctx, cmd) cmdErr := fn(ctx, cmd)
_, err = hs.afterProcess(ctx, cmd) err = hs.afterProcess(ctx, cmd)
if err != nil { if err != nil {
return err return err
} }
@ -65,7 +65,7 @@ func (hs hooks) beforeProcess(ctx context.Context, cmd Cmder) (context.Context,
return ctx, nil return ctx, nil
} }
func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) (context.Context, error) { func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) error {
var firstErr error var firstErr error
for _, h := range hs.hooks { for _, h := range hs.hooks {
err := h.AfterProcess(ctx, cmd) err := h.AfterProcess(ctx, cmd)
@ -73,7 +73,7 @@ func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) (context.Context, e
firstErr = err firstErr = err
} }
} }
return ctx, firstErr return firstErr
} }
func (hs hooks) processPipeline( func (hs hooks) processPipeline(
@ -86,7 +86,7 @@ func (hs hooks) processPipeline(
cmdsErr := fn(ctx, cmds) cmdsErr := fn(ctx, cmds)
_, err = hs.afterProcessPipeline(ctx, cmds) err = hs.afterProcessPipeline(ctx, cmds)
if err != nil { if err != nil {
return err return err
} }
@ -105,7 +105,7 @@ func (hs hooks) beforeProcessPipeline(ctx context.Context, cmds []Cmder) (contex
return ctx, nil return ctx, nil
} }
func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error) { func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) error {
var firstErr error var firstErr error
for _, h := range hs.hooks { for _, h := range hs.hooks {
err := h.AfterProcessPipeline(ctx, cmds) err := h.AfterProcessPipeline(ctx, cmds)
@ -113,7 +113,7 @@ func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) (context
firstErr = err firstErr = err
} }
} }
return ctx, firstErr return firstErr
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------