mirror of https://github.com/go-redis/redis.git
Merge pull request #390 from lijunfei/v4
if readonly is open, read from master when slave is loading data
This commit is contained in:
commit
be32042426
11
cluster.go
11
cluster.go
|
@ -300,6 +300,17 @@ func (c *ClusterClient) Process(cmd Cmder) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// If slave is loading, read from master
|
||||
if errors.IsLoading(cmd.Err()) && c.opt.ReadOnly {
|
||||
trynode, err := c.slotMasterNode(slot)
|
||||
if err == nil && trynode != node {
|
||||
node = trynode
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// On network errors try random node.
|
||||
if errors.IsRetryable(err) {
|
||||
node, err = c.randomNode()
|
||||
|
|
|
@ -10,6 +10,8 @@ const Nil = RedisError("redis: nil")
|
|||
|
||||
type RedisError string
|
||||
|
||||
var LoadingError RedisError = "LOADING Redis is loading the dataset in memory"
|
||||
|
||||
func (e RedisError) Error() string { return string(e) }
|
||||
|
||||
func IsRetryable(err error) bool {
|
||||
|
@ -65,3 +67,7 @@ func IsMoved(err error) (moved bool, ask bool, addr string) {
|
|||
addr = s[ind+1:]
|
||||
return
|
||||
}
|
||||
|
||||
func IsLoading(err error) bool {
|
||||
return err.Error() == string(LoadingError)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue