Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Aug 24, 2019
1 parent 2c55c0b commit 5776216
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
69 changes: 34 additions & 35 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -92,31 +91,31 @@ func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int {
//------------------------------------------------------------------------------

type baseCmd struct {
_args []interface{}
err error
args []interface{}
err error

_readTimeout *time.Duration
}

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.
return internal.ToLower(cmd.stringArg(0))
}

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
}

Expand Down Expand Up @@ -146,7 +145,7 @@ type Cmd struct {

func NewCmd(args ...interface{}) *Cmd {
return &Cmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -303,7 +302,7 @@ var _ Cmder = (*SliceCmd)(nil)

func NewSliceCmd(args ...interface{}) *SliceCmd {
return &SliceCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -341,7 +340,7 @@ var _ Cmder = (*StatusCmd)(nil)

func NewStatusCmd(args ...interface{}) *StatusCmd {
return &StatusCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -374,7 +373,7 @@ var _ Cmder = (*IntCmd)(nil)

func NewIntCmd(args ...interface{}) *IntCmd {
return &IntCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -407,7 +406,7 @@ var _ Cmder = (*IntSliceCmd)(nil)

func NewIntSliceCmd(args ...interface{}) *IntSliceCmd {
return &IntSliceCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -497,7 +496,7 @@ var _ Cmder = (*TimeCmd)(nil)

func NewTimeCmd(args ...interface{}) *TimeCmd {
return &TimeCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -547,7 +546,7 @@ var _ Cmder = (*BoolCmd)(nil)

func NewBoolCmd(args ...interface{}) *BoolCmd {
return &BoolCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -601,7 +600,7 @@ var _ Cmder = (*StringCmd)(nil)

func NewStringCmd(args ...interface{}) *StringCmd {
return &StringCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -691,7 +690,7 @@ var _ Cmder = (*FloatCmd)(nil)

func NewFloatCmd(args ...interface{}) *FloatCmd {
return &FloatCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -724,7 +723,7 @@ var _ Cmder = (*StringSliceCmd)(nil)

func NewStringSliceCmd(args ...interface{}) *StringSliceCmd {
return &StringSliceCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -774,7 +773,7 @@ var _ Cmder = (*BoolSliceCmd)(nil)

func NewBoolSliceCmd(args ...interface{}) *BoolSliceCmd {
return &BoolSliceCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -817,7 +816,7 @@ var _ Cmder = (*StringStringMapCmd)(nil)

func NewStringStringMapCmd(args ...interface{}) *StringStringMapCmd {
return &StringStringMapCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -866,7 +865,7 @@ var _ Cmder = (*StringIntMapCmd)(nil)

func NewStringIntMapCmd(args ...interface{}) *StringIntMapCmd {
return &StringIntMapCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -915,7 +914,7 @@ var _ Cmder = (*StringStructMapCmd)(nil)

func NewStringStructMapCmd(args ...interface{}) *StringStructMapCmd {
return &StringStructMapCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -963,7 +962,7 @@ var _ Cmder = (*XMessageSliceCmd)(nil)

func NewXMessageSliceCmd(args ...interface{}) *XMessageSliceCmd {
return &XMessageSliceCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -1054,7 +1053,7 @@ var _ Cmder = (*XStreamSliceCmd)(nil)

func NewXStreamSliceCmd(args ...interface{}) *XStreamSliceCmd {
return &XStreamSliceCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -1123,7 +1122,7 @@ var _ Cmder = (*XPendingCmd)(nil)

func NewXPendingCmd(args ...interface{}) *XPendingCmd {
return &XPendingCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -1222,7 +1221,7 @@ var _ Cmder = (*XPendingExtCmd)(nil)

func NewXPendingExtCmd(args ...interface{}) *XPendingExtCmd {
return &XPendingExtCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -1296,7 +1295,7 @@ var _ Cmder = (*ZSliceCmd)(nil)

func NewZSliceCmd(args ...interface{}) *ZSliceCmd {
return &ZSliceCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -1348,7 +1347,7 @@ var _ Cmder = (*ZWithKeyCmd)(nil)

func NewZWithKeyCmd(args ...interface{}) *ZWithKeyCmd {
return &ZWithKeyCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -1460,7 +1459,7 @@ var _ Cmder = (*ClusterSlotsCmd)(nil)

func NewClusterSlotsCmd(args ...interface{}) *ClusterSlotsCmd {
return &ClusterSlotsCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -1721,7 +1720,7 @@ var _ Cmder = (*GeoPosCmd)(nil)

func NewGeoPosCmd(args ...interface{}) *GeoPosCmd {
return &GeoPosCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down Expand Up @@ -1795,7 +1794,7 @@ var _ Cmder = (*CommandsInfoCmd)(nil)

func NewCommandsInfoCmd(args ...interface{}) *CommandsInfoCmd {
return &CommandsInfoCmd{
baseCmd: baseCmd{_args: args},
baseCmd: baseCmd{args: args},
}
}

Expand Down
6 changes: 3 additions & 3 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -65,15 +65,15 @@ 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)
if err != nil && firstErr == nil {
firstErr = err
}
}
return ctx, firstErr
return firstErr
}

func (hs hooks) processPipeline(
Expand All @@ -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
}
Expand All @@ -105,15 +105,15 @@ 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)
if err != nil && firstErr == nil {
firstErr = err
}
}
return ctx, firstErr
return firstErr
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 5776216

Please sign in to comment.