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

Remove Redis Cluster state check

This commit is contained in:
Vladimir Mihailenco
2018-11-24 13:16:21 +02:00
parent 78a66f0e5f
commit 17e8439f2f
3 changed files with 30 additions and 42 deletions

View File

@ -3,6 +3,7 @@ package redis
import (
"fmt"
"net"
"strings"
"github.com/go-redis/redis/internal/hashtag"
"github.com/go-redis/redis/internal/pool"
@ -55,3 +56,27 @@ func (c *ClusterClient) SwapNodes(key string) error {
nodes[0], nodes[1] = nodes[1], nodes[0]
return nil
}
func (state *clusterState) IsConsistent() bool {
if len(state.Masters) < 3 {
return false
}
for _, master := range state.Masters {
s := master.Client.Info("replication").Val()
if !strings.Contains(s, "role:master") {
return false
}
}
if len(state.Slaves) < 3 {
return false
}
for _, slave := range state.Slaves {
s := slave.Client.Info("replication").Val()
if !strings.Contains(s, "role:slave") {
return false
}
}
return true
}