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 4
4
"errors"
5
5
"fmt"
6
6
"net"
7
- "reflect"
8
7
"regexp"
9
8
"strconv"
10
9
"strings"
@@ -104,24 +103,27 @@ func (c *client) GetNumberSentinelSlavesInMemory(ip string, auth *util.AuthConfi
104
103
return 0 , err
105
104
}
106
105
nSlaves := len (slaveInfoBlobs )
107
- OUTER:
108
106
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
119
110
}
120
111
}
121
112
122
113
return int32 (nSlaves ), nil
123
114
}
124
115
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
+
125
127
func isSentinelReady (info string ) error {
126
128
matchStatus := sentinelStatusRE .FindStringSubmatch (info )
127
129
if len (matchStatus ) == 0 || matchStatus [1 ] != "ok" {
You can’t perform that action at this time.
0 commit comments