mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
16
cluster.go
16
cluster.go
@ -68,6 +68,9 @@ type ClusterOptions struct {
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
|
||||
// PoolFIFO uses FIFO mode for each node connection pool GET/PUT (default LIFO).
|
||||
PoolFIFO bool
|
||||
|
||||
// PoolSize applies per cluster node and not for the whole cluster.
|
||||
PoolSize int
|
||||
MinIdleConns int
|
||||
@ -146,6 +149,7 @@ func (opt *ClusterOptions) clientOptions() *Options {
|
||||
ReadTimeout: opt.ReadTimeout,
|
||||
WriteTimeout: opt.WriteTimeout,
|
||||
|
||||
PoolFIFO: opt.PoolFIFO,
|
||||
PoolSize: opt.PoolSize,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
MaxConnAge: opt.MaxConnAge,
|
||||
@ -591,8 +595,16 @@ func (c *clusterState) slotRandomNode(slot int) (*clusterNode, error) {
|
||||
if len(nodes) == 0 {
|
||||
return c.nodes.Random()
|
||||
}
|
||||
n := rand.Intn(len(nodes))
|
||||
return nodes[n], nil
|
||||
if len(nodes) == 1 {
|
||||
return nodes[0], nil
|
||||
}
|
||||
randomNodes := rand.Perm(len(nodes))
|
||||
for _, idx := range randomNodes {
|
||||
if node := nodes[idx]; !node.Failing() {
|
||||
return node, nil
|
||||
}
|
||||
}
|
||||
return nodes[randomNodes[0]], nil
|
||||
}
|
||||
|
||||
func (c *clusterState) slotNodes(slot int) []*clusterNode {
|
||||
|
Reference in New Issue
Block a user