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)
| 704 | // usable list and silently fall back to the master (see RandomReplicaAddr |
| 705 | // in sentinel.go). |
| 706 | func 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 | |
| 723 | func waitForSentinelClusterStable() { |
| 724 | sentinel1 := redis.NewSentinelClient(&redis.Options{ |
no outgoing calls
no test coverage detected