Exported the setErr function as public

This commit is contained in:
git-hulk 2020-02-03 17:53:47 +08:00
parent a579d58c59
commit d52b11cb42
7 changed files with 34 additions and 34 deletions

View File

@ -743,7 +743,7 @@ func (c *ClusterClient) ProcessContext(ctx context.Context, cmd Cmder) error {
func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error {
err := c._process(ctx, cmd)
if err != nil {
cmd.setErr(err)
cmd.SetErr(err)
return err
}
return nil

View File

@ -14,7 +14,7 @@ func (c *ClusterClient) DBSize() *IntCmd {
return nil
})
if err != nil {
cmd.setErr(err)
cmd.SetErr(err)
return cmd
}
cmd.val = size

View File

@ -20,14 +20,14 @@ type Cmder interface {
readTimeout() *time.Duration
readReply(rd *proto.Reader) error
setErr(error)
SetErr(error)
Err() error
}
func setCmdsErr(cmds []Cmder, e error) {
for _, cmd := range cmds {
if cmd.Err() == nil {
cmd.setErr(e)
cmd.SetErr(e)
}
}
}
@ -119,7 +119,7 @@ func (cmd *baseCmd) stringArg(pos int) string {
return s
}
func (cmd *baseCmd) setErr(e error) {
func (cmd *baseCmd) SetErr(e error) {
cmd.err = e
}

View File

@ -2537,7 +2537,7 @@ func (c cmdable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd {
func (c cmdable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
cmd := NewGeoLocationCmd(query, "georadius_ro", key, longitude, latitude)
if query.Store != "" || query.StoreDist != "" {
cmd.setErr(errors.New("GeoRadius does not support Store or StoreDist"))
cmd.SetErr(errors.New("GeoRadius does not support Store or StoreDist"))
return cmd
}
_ = c(cmd)
@ -2549,7 +2549,7 @@ func (c cmdable) GeoRadiusStore(key string, longitude, latitude float64, query *
args := geoLocationArgs(query, "georadius", key, longitude, latitude)
cmd := NewIntCmd(args...)
if query.Store == "" && query.StoreDist == "" {
cmd.setErr(errors.New("GeoRadiusStore requires Store or StoreDist"))
cmd.SetErr(errors.New("GeoRadiusStore requires Store or StoreDist"))
return cmd
}
_ = c(cmd)
@ -2560,7 +2560,7 @@ func (c cmdable) GeoRadiusStore(key string, longitude, latitude float64, query *
func (c cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
cmd := NewGeoLocationCmd(query, "georadiusbymember_ro", key, member)
if query.Store != "" || query.StoreDist != "" {
cmd.setErr(errors.New("GeoRadiusByMember does not support Store or StoreDist"))
cmd.SetErr(errors.New("GeoRadiusByMember does not support Store or StoreDist"))
return cmd
}
_ = c(cmd)
@ -2572,7 +2572,7 @@ func (c cmdable) GeoRadiusByMemberStore(key, member string, query *GeoRadiusQuer
args := geoLocationArgs(query, "georadiusbymember", key, member)
cmd := NewIntCmd(args...)
if query.Store == "" && query.StoreDist == "" {
cmd.setErr(errors.New("GeoRadiusByMemberStore requires Store or StoreDist"))
cmd.SetErr(errors.New("GeoRadiusByMemberStore requires Store or StoreDist"))
return cmd
}
_ = c(cmd)

View File

@ -51,14 +51,14 @@ func (hs hooks) process(
) error {
ctx, err := hs.beforeProcess(ctx, cmd)
if err != nil {
cmd.setErr(err)
cmd.SetErr(err)
return err
}
cmdErr := fn(ctx, cmd)
if err := hs.afterProcess(ctx, cmd); err != nil {
cmd.setErr(err)
cmd.SetErr(err)
return err
}
@ -287,7 +287,7 @@ func (c *baseClient) withConn(
func (c *baseClient) process(ctx context.Context, cmd Cmder) error {
err := c._process(ctx, cmd)
if err != nil {
cmd.setErr(err)
cmd.SetErr(err)
return err
}
return nil

View File

@ -6,7 +6,7 @@ import "time"
func NewCmdResult(val interface{}, err error) *Cmd {
var cmd Cmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -14,7 +14,7 @@ func NewCmdResult(val interface{}, err error) *Cmd {
func NewSliceResult(val []interface{}, err error) *SliceCmd {
var cmd SliceCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -22,7 +22,7 @@ func NewSliceResult(val []interface{}, err error) *SliceCmd {
func NewStatusResult(val string, err error) *StatusCmd {
var cmd StatusCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -30,7 +30,7 @@ func NewStatusResult(val string, err error) *StatusCmd {
func NewIntResult(val int64, err error) *IntCmd {
var cmd IntCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -38,7 +38,7 @@ func NewIntResult(val int64, err error) *IntCmd {
func NewDurationResult(val time.Duration, err error) *DurationCmd {
var cmd DurationCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -46,7 +46,7 @@ func NewDurationResult(val time.Duration, err error) *DurationCmd {
func NewBoolResult(val bool, err error) *BoolCmd {
var cmd BoolCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -54,7 +54,7 @@ func NewBoolResult(val bool, err error) *BoolCmd {
func NewStringResult(val string, err error) *StringCmd {
var cmd StringCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -62,7 +62,7 @@ func NewStringResult(val string, err error) *StringCmd {
func NewFloatResult(val float64, err error) *FloatCmd {
var cmd FloatCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -70,7 +70,7 @@ func NewFloatResult(val float64, err error) *FloatCmd {
func NewStringSliceResult(val []string, err error) *StringSliceCmd {
var cmd StringSliceCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -78,7 +78,7 @@ func NewStringSliceResult(val []string, err error) *StringSliceCmd {
func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
var cmd BoolSliceCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -86,7 +86,7 @@ func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
func NewStringStringMapResult(val map[string]string, err error) *StringStringMapCmd {
var cmd StringStringMapCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -94,7 +94,7 @@ func NewStringStringMapResult(val map[string]string, err error) *StringStringMap
func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd {
var cmd StringIntMapCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -102,7 +102,7 @@ func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd
func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
var cmd ZSliceCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -110,7 +110,7 @@ func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
func NewZWithKeyCmdResult(val *ZWithKey, err error) *ZWithKeyCmd {
var cmd ZWithKeyCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -119,7 +119,7 @@ func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd {
var cmd ScanCmd
cmd.page = keys
cmd.cursor = cursor
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -127,7 +127,7 @@ func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd {
func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
var cmd ClusterSlotsCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -135,7 +135,7 @@ func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
var cmd GeoLocationCmd
cmd.locations = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -143,7 +143,7 @@ func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
func NewGeoPosCmdResult(val []*GeoPos, err error) *GeoPosCmd {
var cmd GeoPosCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -151,7 +151,7 @@ func NewGeoPosCmdResult(val []*GeoPos, err error) *GeoPosCmd {
func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsInfoCmd {
var cmd CommandsInfoCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -159,7 +159,7 @@ func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsI
func NewXMessageSliceCmdResult(val []XMessage, err error) *XMessageSliceCmd {
var cmd XMessageSliceCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}
@ -167,6 +167,6 @@ func NewXMessageSliceCmdResult(val []XMessage, err error) *XMessageSliceCmd {
func NewXStreamSliceCmdResult(val []XStream, err error) *XStreamSliceCmd {
var cmd XStreamSliceCmd
cmd.val = val
cmd.setErr(err)
cmd.SetErr(err)
return &cmd
}

View File

@ -561,7 +561,7 @@ func (c *Ring) cmdShard(cmd Cmder) (*ringShard, error) {
func (c *Ring) process(ctx context.Context, cmd Cmder) error {
err := c._process(ctx, cmd)
if err != nil {
cmd.setErr(err)
cmd.SetErr(err)
return err
}
return nil