forked from mirror/redis
Merge pull request #1255 from git-hulk/master
Exported the setErr function as public
This commit is contained in:
commit
68dd70bb72
|
@ -743,7 +743,7 @@ func (c *ClusterClient) ProcessContext(ctx context.Context, cmd Cmder) error {
|
||||||
func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error {
|
func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error {
|
||||||
err := c._process(ctx, cmd)
|
err := c._process(ctx, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -14,7 +14,7 @@ func (c *ClusterClient) DBSize() *IntCmd {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
cmd.val = size
|
cmd.val = size
|
||||||
|
|
|
@ -20,14 +20,14 @@ type Cmder interface {
|
||||||
readTimeout() *time.Duration
|
readTimeout() *time.Duration
|
||||||
readReply(rd *proto.Reader) error
|
readReply(rd *proto.Reader) error
|
||||||
|
|
||||||
setErr(error)
|
SetErr(error)
|
||||||
Err() error
|
Err() error
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCmdsErr(cmds []Cmder, e error) {
|
func setCmdsErr(cmds []Cmder, e error) {
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
if cmd.Err() == nil {
|
if cmd.Err() == nil {
|
||||||
cmd.setErr(e)
|
cmd.SetErr(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func (cmd *baseCmd) stringArg(pos int) string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *baseCmd) setErr(e error) {
|
func (cmd *baseCmd) SetErr(e error) {
|
||||||
cmd.err = e
|
cmd.err = e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package redis_test
|
package redis_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v7"
|
redis "github.com/go-redis/redis/v7"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
@ -84,4 +85,12 @@ var _ = Describe("Cmd", func() {
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(tm2).To(BeTemporally("==", tm))
|
Expect(tm2).To(BeTemporally("==", tm))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("allow to set custom error", func() {
|
||||||
|
e := errors.New("custom error")
|
||||||
|
cmd := redis.Cmd{}
|
||||||
|
cmd.SetErr(e)
|
||||||
|
_, err := cmd.Result()
|
||||||
|
Expect(err).To(Equal(e))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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 {
|
func (c cmdable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
|
||||||
cmd := NewGeoLocationCmd(query, "georadius_ro", key, longitude, latitude)
|
cmd := NewGeoLocationCmd(query, "georadius_ro", key, longitude, latitude)
|
||||||
if query.Store != "" || query.StoreDist != "" {
|
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
|
return cmd
|
||||||
}
|
}
|
||||||
_ = c(cmd)
|
_ = c(cmd)
|
||||||
|
@ -2549,7 +2549,7 @@ func (c cmdable) GeoRadiusStore(key string, longitude, latitude float64, query *
|
||||||
args := geoLocationArgs(query, "georadius", key, longitude, latitude)
|
args := geoLocationArgs(query, "georadius", key, longitude, latitude)
|
||||||
cmd := NewIntCmd(args...)
|
cmd := NewIntCmd(args...)
|
||||||
if query.Store == "" && query.StoreDist == "" {
|
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
|
return cmd
|
||||||
}
|
}
|
||||||
_ = c(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 {
|
func (c cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
|
||||||
cmd := NewGeoLocationCmd(query, "georadiusbymember_ro", key, member)
|
cmd := NewGeoLocationCmd(query, "georadiusbymember_ro", key, member)
|
||||||
if query.Store != "" || query.StoreDist != "" {
|
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
|
return cmd
|
||||||
}
|
}
|
||||||
_ = c(cmd)
|
_ = c(cmd)
|
||||||
|
@ -2572,7 +2572,7 @@ func (c cmdable) GeoRadiusByMemberStore(key, member string, query *GeoRadiusQuer
|
||||||
args := geoLocationArgs(query, "georadiusbymember", key, member)
|
args := geoLocationArgs(query, "georadiusbymember", key, member)
|
||||||
cmd := NewIntCmd(args...)
|
cmd := NewIntCmd(args...)
|
||||||
if query.Store == "" && query.StoreDist == "" {
|
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
|
return cmd
|
||||||
}
|
}
|
||||||
_ = c(cmd)
|
_ = c(cmd)
|
||||||
|
|
6
redis.go
6
redis.go
|
@ -51,14 +51,14 @@ func (hs hooks) process(
|
||||||
) error {
|
) error {
|
||||||
ctx, err := hs.beforeProcess(ctx, cmd)
|
ctx, err := hs.beforeProcess(ctx, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdErr := fn(ctx, cmd)
|
cmdErr := fn(ctx, cmd)
|
||||||
|
|
||||||
if err := hs.afterProcess(ctx, cmd); err != nil {
|
if err := hs.afterProcess(ctx, cmd); err != nil {
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ func (c *baseClient) withConn(
|
||||||
func (c *baseClient) process(ctx context.Context, cmd Cmder) error {
|
func (c *baseClient) process(ctx context.Context, cmd Cmder) error {
|
||||||
err := c._process(ctx, cmd)
|
err := c._process(ctx, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
42
result.go
42
result.go
|
@ -6,7 +6,7 @@ import "time"
|
||||||
func NewCmdResult(val interface{}, err error) *Cmd {
|
func NewCmdResult(val interface{}, err error) *Cmd {
|
||||||
var cmd Cmd
|
var cmd Cmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ func NewCmdResult(val interface{}, err error) *Cmd {
|
||||||
func NewSliceResult(val []interface{}, err error) *SliceCmd {
|
func NewSliceResult(val []interface{}, err error) *SliceCmd {
|
||||||
var cmd SliceCmd
|
var cmd SliceCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func NewSliceResult(val []interface{}, err error) *SliceCmd {
|
||||||
func NewStatusResult(val string, err error) *StatusCmd {
|
func NewStatusResult(val string, err error) *StatusCmd {
|
||||||
var cmd StatusCmd
|
var cmd StatusCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ func NewStatusResult(val string, err error) *StatusCmd {
|
||||||
func NewIntResult(val int64, err error) *IntCmd {
|
func NewIntResult(val int64, err error) *IntCmd {
|
||||||
var cmd IntCmd
|
var cmd IntCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ func NewIntResult(val int64, err error) *IntCmd {
|
||||||
func NewDurationResult(val time.Duration, err error) *DurationCmd {
|
func NewDurationResult(val time.Duration, err error) *DurationCmd {
|
||||||
var cmd DurationCmd
|
var cmd DurationCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ func NewDurationResult(val time.Duration, err error) *DurationCmd {
|
||||||
func NewBoolResult(val bool, err error) *BoolCmd {
|
func NewBoolResult(val bool, err error) *BoolCmd {
|
||||||
var cmd BoolCmd
|
var cmd BoolCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ func NewBoolResult(val bool, err error) *BoolCmd {
|
||||||
func NewStringResult(val string, err error) *StringCmd {
|
func NewStringResult(val string, err error) *StringCmd {
|
||||||
var cmd StringCmd
|
var cmd StringCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func NewStringResult(val string, err error) *StringCmd {
|
||||||
func NewFloatResult(val float64, err error) *FloatCmd {
|
func NewFloatResult(val float64, err error) *FloatCmd {
|
||||||
var cmd FloatCmd
|
var cmd FloatCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func NewFloatResult(val float64, err error) *FloatCmd {
|
||||||
func NewStringSliceResult(val []string, err error) *StringSliceCmd {
|
func NewStringSliceResult(val []string, err error) *StringSliceCmd {
|
||||||
var cmd StringSliceCmd
|
var cmd StringSliceCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ func NewStringSliceResult(val []string, err error) *StringSliceCmd {
|
||||||
func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
|
func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
|
||||||
var cmd BoolSliceCmd
|
var cmd BoolSliceCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
|
||||||
func NewStringStringMapResult(val map[string]string, err error) *StringStringMapCmd {
|
func NewStringStringMapResult(val map[string]string, err error) *StringStringMapCmd {
|
||||||
var cmd StringStringMapCmd
|
var cmd StringStringMapCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ func NewStringStringMapResult(val map[string]string, err error) *StringStringMap
|
||||||
func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd {
|
func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd {
|
||||||
var cmd StringIntMapCmd
|
var cmd StringIntMapCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd
|
||||||
func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
|
func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
|
||||||
var cmd ZSliceCmd
|
var cmd ZSliceCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
|
||||||
func NewZWithKeyCmdResult(val *ZWithKey, err error) *ZWithKeyCmd {
|
func NewZWithKeyCmdResult(val *ZWithKey, err error) *ZWithKeyCmd {
|
||||||
var cmd ZWithKeyCmd
|
var cmd ZWithKeyCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd {
|
||||||
var cmd ScanCmd
|
var cmd ScanCmd
|
||||||
cmd.page = keys
|
cmd.page = keys
|
||||||
cmd.cursor = cursor
|
cmd.cursor = cursor
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd {
|
||||||
func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
|
func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
|
||||||
var cmd ClusterSlotsCmd
|
var cmd ClusterSlotsCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
|
||||||
func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
|
func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
|
||||||
var cmd GeoLocationCmd
|
var cmd GeoLocationCmd
|
||||||
cmd.locations = val
|
cmd.locations = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
|
||||||
func NewGeoPosCmdResult(val []*GeoPos, err error) *GeoPosCmd {
|
func NewGeoPosCmdResult(val []*GeoPos, err error) *GeoPosCmd {
|
||||||
var cmd GeoPosCmd
|
var cmd GeoPosCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ func NewGeoPosCmdResult(val []*GeoPos, err error) *GeoPosCmd {
|
||||||
func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsInfoCmd {
|
func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsInfoCmd {
|
||||||
var cmd CommandsInfoCmd
|
var cmd CommandsInfoCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsI
|
||||||
func NewXMessageSliceCmdResult(val []XMessage, err error) *XMessageSliceCmd {
|
func NewXMessageSliceCmdResult(val []XMessage, err error) *XMessageSliceCmd {
|
||||||
var cmd XMessageSliceCmd
|
var cmd XMessageSliceCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +167,6 @@ func NewXMessageSliceCmdResult(val []XMessage, err error) *XMessageSliceCmd {
|
||||||
func NewXStreamSliceCmdResult(val []XStream, err error) *XStreamSliceCmd {
|
func NewXStreamSliceCmdResult(val []XStream, err error) *XStreamSliceCmd {
|
||||||
var cmd XStreamSliceCmd
|
var cmd XStreamSliceCmd
|
||||||
cmd.val = val
|
cmd.val = val
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return &cmd
|
return &cmd
|
||||||
}
|
}
|
||||||
|
|
2
ring.go
2
ring.go
|
@ -561,7 +561,7 @@ func (c *Ring) cmdShard(cmd Cmder) (*ringShard, error) {
|
||||||
func (c *Ring) process(ctx context.Context, cmd Cmder) error {
|
func (c *Ring) process(ctx context.Context, cmd Cmder) error {
|
||||||
err := c._process(ctx, cmd)
|
err := c._process(ctx, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.setErr(err)
|
cmd.SetErr(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue