mirror of https://github.com/go-redis/redis.git
Fix corner cases and a bug
This commit is contained in:
parent
effc0c507a
commit
18e7a81047
11
cluster.go
11
cluster.go
|
@ -533,13 +533,15 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
|
||||||
n := rand.Intn(len(nodes)-1) + 1
|
n := rand.Intn(len(nodes)-1) + 1
|
||||||
slave = nodes[n]
|
slave = nodes[n]
|
||||||
if !slave.Loading() {
|
if !slave.Loading() {
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return slave, nil
|
return slave, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// All slaves are loading - use master.
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *clusterState) slotClosestNode(slot int) (*clusterNode, error) {
|
func (c *clusterState) slotClosestNode(slot int) (*clusterNode, error) {
|
||||||
const threshold = time.Millisecond
|
const threshold = time.Millisecond
|
||||||
|
|
||||||
|
@ -979,9 +981,10 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// If slave is loading - read from master.
|
// If slave is loading - pick another node.
|
||||||
if c.opt.ReadOnly && internal.IsLoadingError(err) {
|
if c.opt.ReadOnly && internal.IsLoadingError(err) {
|
||||||
node.MarkAsLoading()
|
node.MarkAsLoading()
|
||||||
|
node = nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue