Skip to content

Commit 42679bc

Browse files
committed
fixed: GetNumberSentinelSlavesInMemory failed when the master node becomes a slave node
1 parent 93c01ea commit 42679bc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/client/redis/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,20 @@ OUTER:
109109
slaveInfo := reflect.ValueOf(slaveInfoBlob)
110110
for key, value := range slaveInfoBlob.([]interface{}) {
111111
stringValue := value.(string)
112+
// When the master node becomes a slave node, runid will become empty
113+
if stringValue == "runid" {
114+
runID := fmt.Sprintf("%+v", slaveInfo.Index(key+1))
115+
if runID == "" {
116+
nSlaves += 1
117+
continue OUTER
118+
}
119+
}
112120
if stringValue == "slave-priority" {
113121
slavePriority := fmt.Sprintf("%+v", slaveInfo.Index(key+1))
114122
if slavePriority == "1" {
115123
nSlaves += 1
124+
continue OUTER
116125
}
117-
continue OUTER
118126
}
119127
}
120128
}

0 commit comments

Comments
 (0)