From 57762166777418c24dbdccbec56675c2ef44285f Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 24 Aug 2019 11:55:13 +0300 Subject: [PATCH] Cleanup --- command.go | 69 ++++++++++++++++++++++++++--------------------------- iterator.go | 6 ++--- redis.go | 12 +++++----- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/command.go b/command.go index e4e13a9..1378370 100644 --- a/command.go +++ b/command.go @@ -17,11 +17,10 @@ type Cmder interface { Args() []interface{} stringArg(int) string - readReply(rd *proto.Reader) error - setErr(error) - readTimeout() *time.Duration + readReply(rd *proto.Reader) error + setErr(error) Err() error } @@ -92,8 +91,8 @@ func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int { //------------------------------------------------------------------------------ type baseCmd struct { - _args []interface{} - err error + args []interface{} + err error _readTimeout *time.Duration } @@ -101,7 +100,7 @@ type baseCmd struct { var _ Cmder = (*Cmd)(nil) func (cmd *baseCmd) Name() string { - if len(cmd._args) == 0 { + if len(cmd.args) == 0 { return "" } // Cmd name must be lower cased. @@ -109,14 +108,14 @@ func (cmd *baseCmd) Name() string { } func (cmd *baseCmd) Args() []interface{} { - return cmd._args + return cmd.args } func (cmd *baseCmd) stringArg(pos int) string { - if pos < 0 || pos >= len(cmd._args) { + if pos < 0 || pos >= len(cmd.args) { return "" } - s, _ := cmd._args[pos].(string) + s, _ := cmd.args[pos].(string) return s } @@ -146,7 +145,7 @@ type Cmd struct { func NewCmd(args ...interface{}) *Cmd { return &Cmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -303,7 +302,7 @@ var _ Cmder = (*SliceCmd)(nil) func NewSliceCmd(args ...interface{}) *SliceCmd { return &SliceCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -341,7 +340,7 @@ var _ Cmder = (*StatusCmd)(nil) func NewStatusCmd(args ...interface{}) *StatusCmd { return &StatusCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -374,7 +373,7 @@ var _ Cmder = (*IntCmd)(nil) func NewIntCmd(args ...interface{}) *IntCmd { return &IntCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -407,7 +406,7 @@ var _ Cmder = (*IntSliceCmd)(nil) func NewIntSliceCmd(args ...interface{}) *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 { return &DurationCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, precision: precision, } } @@ -497,7 +496,7 @@ var _ Cmder = (*TimeCmd)(nil) func NewTimeCmd(args ...interface{}) *TimeCmd { return &TimeCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -547,7 +546,7 @@ var _ Cmder = (*BoolCmd)(nil) func NewBoolCmd(args ...interface{}) *BoolCmd { return &BoolCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -601,7 +600,7 @@ var _ Cmder = (*StringCmd)(nil) func NewStringCmd(args ...interface{}) *StringCmd { return &StringCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -691,7 +690,7 @@ var _ Cmder = (*FloatCmd)(nil) func NewFloatCmd(args ...interface{}) *FloatCmd { return &FloatCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -724,7 +723,7 @@ var _ Cmder = (*StringSliceCmd)(nil) func NewStringSliceCmd(args ...interface{}) *StringSliceCmd { return &StringSliceCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -774,7 +773,7 @@ var _ Cmder = (*BoolSliceCmd)(nil) func NewBoolSliceCmd(args ...interface{}) *BoolSliceCmd { return &BoolSliceCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -817,7 +816,7 @@ var _ Cmder = (*StringStringMapCmd)(nil) func NewStringStringMapCmd(args ...interface{}) *StringStringMapCmd { return &StringStringMapCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -866,7 +865,7 @@ var _ Cmder = (*StringIntMapCmd)(nil) func NewStringIntMapCmd(args ...interface{}) *StringIntMapCmd { return &StringIntMapCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -915,7 +914,7 @@ var _ Cmder = (*StringStructMapCmd)(nil) func NewStringStructMapCmd(args ...interface{}) *StringStructMapCmd { return &StringStructMapCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -963,7 +962,7 @@ var _ Cmder = (*XMessageSliceCmd)(nil) func NewXMessageSliceCmd(args ...interface{}) *XMessageSliceCmd { return &XMessageSliceCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -1054,7 +1053,7 @@ var _ Cmder = (*XStreamSliceCmd)(nil) func NewXStreamSliceCmd(args ...interface{}) *XStreamSliceCmd { return &XStreamSliceCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -1123,7 +1122,7 @@ var _ Cmder = (*XPendingCmd)(nil) func NewXPendingCmd(args ...interface{}) *XPendingCmd { return &XPendingCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -1222,7 +1221,7 @@ var _ Cmder = (*XPendingExtCmd)(nil) func NewXPendingExtCmd(args ...interface{}) *XPendingExtCmd { return &XPendingExtCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -1296,7 +1295,7 @@ var _ Cmder = (*ZSliceCmd)(nil) func NewZSliceCmd(args ...interface{}) *ZSliceCmd { return &ZSliceCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -1348,7 +1347,7 @@ var _ Cmder = (*ZWithKeyCmd)(nil) func NewZWithKeyCmd(args ...interface{}) *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 { return &ScanCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, process: process, } } @@ -1460,7 +1459,7 @@ var _ Cmder = (*ClusterSlotsCmd)(nil) func NewClusterSlotsCmd(args ...interface{}) *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 { return &GeoLocationCmd{ - baseCmd: baseCmd{_args: geoLocationArgs(q, args...)}, + baseCmd: baseCmd{args: geoLocationArgs(q, args...)}, q: q, } } @@ -1721,7 +1720,7 @@ var _ Cmder = (*GeoPosCmd)(nil) func NewGeoPosCmd(args ...interface{}) *GeoPosCmd { return &GeoPosCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } @@ -1795,7 +1794,7 @@ var _ Cmder = (*CommandsInfoCmd)(nil) func NewCommandsInfoCmd(args ...interface{}) *CommandsInfoCmd { return &CommandsInfoCmd{ - baseCmd: baseCmd{_args: args}, + baseCmd: baseCmd{args: args}, } } diff --git a/iterator.go b/iterator.go index a1e69e2..f9d3aab 100644 --- a/iterator.go +++ b/iterator.go @@ -43,10 +43,10 @@ func (it *ScanIterator) Next() bool { } // Fetch next page. - if it.cmd._args[0] == "scan" { - it.cmd._args[1] = it.cmd.cursor + if it.cmd.args[0] == "scan" { + it.cmd.args[1] = it.cmd.cursor } else { - it.cmd._args[2] = it.cmd.cursor + it.cmd.args[2] = it.cmd.cursor } err := it.cmd.process(it.cmd) diff --git a/redis.go b/redis.go index 94698be..b87289c 100644 --- a/redis.go +++ b/redis.go @@ -46,7 +46,7 @@ func (hs hooks) process( cmdErr := fn(ctx, cmd) - _, err = hs.afterProcess(ctx, cmd) + err = hs.afterProcess(ctx, cmd) if err != nil { return err } @@ -65,7 +65,7 @@ func (hs hooks) beforeProcess(ctx context.Context, cmd Cmder) (context.Context, 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 for _, h := range hs.hooks { err := h.AfterProcess(ctx, cmd) @@ -73,7 +73,7 @@ func (hs hooks) afterProcess(ctx context.Context, cmd Cmder) (context.Context, e firstErr = err } } - return ctx, firstErr + return firstErr } func (hs hooks) processPipeline( @@ -86,7 +86,7 @@ func (hs hooks) processPipeline( cmdsErr := fn(ctx, cmds) - _, err = hs.afterProcessPipeline(ctx, cmds) + err = hs.afterProcessPipeline(ctx, cmds) if err != nil { return err } @@ -105,7 +105,7 @@ func (hs hooks) beforeProcessPipeline(ctx context.Context, cmds []Cmder) (contex 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 for _, h := range hs.hooks { err := h.AfterProcessPipeline(ctx, cmds) @@ -113,7 +113,7 @@ func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) (context firstErr = err } } - return ctx, firstErr + return firstErr } //------------------------------------------------------------------------------