MCPcopy
hub / github.com/redis/go-redis / countUsableReplicas

Function countUsableReplicas

sentinel_test.go:706–721  ·  view source on GitHub ↗

countUsableReplicas mirrors the filter applied by parseReplicaAddrs in sentinel.go: a replica is usable only when it is not s_down, o_down, or disconnected. Plain len() on Sentinel's Replicas reply is not enough — post-failover, replicas often linger with the "disconnected" flag for several seconds

(replicas []map[string]string)

Source from the content-addressed store, hash-verified

704// usable list and silently fall back to the master (see RandomReplicaAddr
705// in sentinel.go).
706func countUsableReplicas(replicas []map[string]string) int {
707 usable := 0
708 for _, node := range replicas {
709 down := false
710 for _, flag := range strings.Split(node["flags"], ",") {
711 switch flag {
712 case "s_down", "o_down", "disconnected":
713 down = true
714 }
715 }
716 if !down && node["ip"] != "" && node["port"] != "" {
717 usable++
718 }
719 }
720 return usable
721}
722
723func waitForSentinelClusterStable() {
724 sentinel1 := redis.NewSentinelClient(&redis.Options{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected