forked from mirror/redis
Cleanup code
This commit is contained in:
parent
ddbd81ea6c
commit
1173a9589f
32
cluster.go
32
cluster.go
|
@ -205,17 +205,19 @@ func (c *clusterNodes) Close() error {
|
||||||
return firstErr
|
return firstErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clusterNodes) Err() error {
|
func (c *clusterNodes) Addrs() ([]string, error) {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
defer c.mu.RUnlock()
|
closed := c.closed
|
||||||
|
addrs := c.addrs
|
||||||
|
c.mu.RUnlock()
|
||||||
|
|
||||||
if c.closed {
|
if closed {
|
||||||
return pool.ErrClosed
|
return nil, pool.ErrClosed
|
||||||
}
|
}
|
||||||
if len(c.addrs) == 0 {
|
if len(addrs) == 0 {
|
||||||
return errClusterNoNodes
|
return nil, errClusterNoNodes
|
||||||
}
|
}
|
||||||
return nil
|
return addrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clusterNodes) NextGeneration() uint32 {
|
func (c *clusterNodes) NextGeneration() uint32 {
|
||||||
|
@ -298,16 +300,9 @@ func (c *clusterNodes) GetOrCreate(addr string) (*clusterNode, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clusterNodes) Random() (*clusterNode, error) {
|
func (c *clusterNodes) Random() (*clusterNode, error) {
|
||||||
c.mu.RLock()
|
addrs, err := c.Addrs()
|
||||||
closed := c.closed
|
if err != nil {
|
||||||
addrs := c.addrs
|
return nil, err
|
||||||
c.mu.RUnlock()
|
|
||||||
|
|
||||||
if closed {
|
|
||||||
return nil, pool.ErrClosed
|
|
||||||
}
|
|
||||||
if len(addrs) == 0 {
|
|
||||||
return nil, errClusterNoNodes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodeErr error
|
var nodeErr error
|
||||||
|
@ -504,7 +499,8 @@ func (c *ClusterClient) state() (*clusterState, error) {
|
||||||
return v.(*clusterState), nil
|
return v.(*clusterState), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.nodes.Err(); err != nil {
|
_, err := c.nodes.Addrs()
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue