File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed
Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change 44 "errors"
55 "fmt"
66 "net"
7- "reflect"
87 "regexp"
98 "strconv"
109 "strings"
@@ -104,24 +103,27 @@ func (c *client) GetNumberSentinelSlavesInMemory(ip string, auth *util.AuthConfi
104103 return 0 , err
105104 }
106105 nSlaves := len (slaveInfoBlobs )
107- OUTER:
108106 for _ , slaveInfoBlob := range slaveInfoBlobs {
109- slaveInfo := reflect .ValueOf (slaveInfoBlob )
110- for key , value := range slaveInfoBlob .([]interface {}) {
111- stringValue := value .(string )
112- if stringValue == "slave-priority" {
113- slavePriority := fmt .Sprintf ("%+v" , slaveInfo .Index (key + 1 ))
114- if slavePriority == "0" {
115- nSlaves -= 1
116- }
117- continue OUTER
118- }
107+ slavePriority := slaveInfoFieldByName ("slave-priority" , slaveInfoBlob )
108+ if slavePriority == "0" {
109+ nSlaves -= 1
119110 }
120111 }
121112
122113 return int32 (nSlaves ), nil
123114}
124115
116+ func slaveInfoFieldByName (name string , slaveInfoBlob interface {}) string {
117+ slaveInfo := slaveInfoBlob .([]interface {})
118+ for key , value := range slaveInfo {
119+ stringValue := value .(string )
120+ if stringValue == name {
121+ return slaveInfo [key + 1 ].(string )
122+ }
123+ }
124+ return ""
125+ }
126+
125127func isSentinelReady (info string ) error {
126128 matchStatus := sentinelStatusRE .FindStringSubmatch (info )
127129 if len (matchStatus ) == 0 || matchStatus [1 ] != "ok" {
You can’t perform that action at this time.
0 commit comments