1
0
mirror of https://github.com/redis/go-redis.git synced 2025-08-07 12:42:55 +03:00

More cluster tests.

This commit is contained in:
Vladimir Mihailenco
2016-10-09 11:12:32 +00:00
parent f5245efa73
commit 639950777c
3 changed files with 158 additions and 77 deletions

View File

@@ -12,6 +12,8 @@ import (
"gopkg.in/redis.v5/internal/pool"
)
var errClusterNoNodes = errors.RedisError("redis: cluster has no nodes")
// ClusterOptions are used to configure a cluster client and should be
// passed to NewClusterClient.
type ClusterOptions struct {
@@ -155,14 +157,14 @@ func (c *ClusterClient) cmdInfo(name string) *CommandInfo {
func (c *ClusterClient) getNodes() map[string]*clusterNode {
var nodes map[string]*clusterNode
c.mu.RLock()
if !c.closed {
nodes = make(map[string]*clusterNode, len(c.nodes))
c.mu.RLock()
for addr, node := range c.nodes {
nodes[addr] = node
}
c.mu.RUnlock()
}
c.mu.RUnlock()
return nodes
}
@@ -261,6 +263,9 @@ func (c *ClusterClient) randomNode() (*clusterNode, error) {
return nil, pool.ErrClosed
}
if len(addrs) == 0 {
return nil, errClusterNoNodes
}
n := rand.Intn(len(addrs))
node, err := c.nodeByAddr(addrs[n])