1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-26 19:21:03 +03:00

Use random node to load cluster slots

This commit is contained in:
Vladimir Mihailenco
2020-06-29 17:26:11 +03:00
parent 5b4d00c217
commit 0ffefcde98
7 changed files with 64 additions and 23 deletions

View File

@ -5,7 +5,6 @@ import (
"crypto/tls"
"fmt"
"math"
"math/rand"
"net"
"runtime"
"sort"
@ -17,6 +16,7 @@ import (
"github.com/go-redis/redis/v8/internal/hashtag"
"github.com/go-redis/redis/v8/internal/pool"
"github.com/go-redis/redis/v8/internal/proto"
"golang.org/x/exp/rand"
)
var errClusterNoNodes = fmt.Errorf("redis: cluster has no nodes")
@ -993,7 +993,9 @@ func (c *ClusterClient) loadState(ctx context.Context) (*clusterState, error) {
}
var firstErr error
for _, addr := range addrs {
for _, idx := range rand.Perm(len(addrs)) {
addr := addrs[idx]
node, err := c.nodes.Get(addr)
if err != nil {
if firstErr == nil {