@@ -29,6 +29,7 @@ const (
29
29
)
30
30
31
31
var totalMessages uint64
32
+ var clusterSlicesMu sync.Mutex
32
33
33
34
type testResult struct {
34
35
StartTime int64 `json:"StartTime"`
@@ -126,9 +127,9 @@ func main() {
126
127
127
128
ctx := context .Background ()
128
129
nodeCount := 0
129
- poolSize := * poolSizePtr
130
130
var nodesAddresses []string
131
131
var nodeClients []* redis.Client
132
+ poolSize := * poolSizePtr
132
133
var clusterClient * redis.ClusterClient
133
134
var standaloneClient * redis.Client
134
135
@@ -161,22 +162,7 @@ func main() {
161
162
if err != nil {
162
163
log .Fatal (err )
163
164
}
164
- log .Println ("Getting cluster slots info." )
165
- slots , err := clusterClient .ClusterSlots (ctx ).Result ()
166
- if err != nil {
167
- log .Fatal (err )
168
- }
169
- nodeCount = len (slots )
170
- log .Println (fmt .Sprintf ("Detailing cluster slots info. Total nodes: %d" , nodeCount ))
171
- for _ , slotInfo := range slots {
172
- log .Println (fmt .Sprintf ("\t Slot range start %d end %d. Nodes: %v" , slotInfo .Start , slotInfo .End , slotInfo .Nodes ))
173
- nodesAddresses = append (nodesAddresses , slotInfo .Nodes [0 ].Addr )
174
- }
175
- fn := func (ctx context.Context , client * redis.Client ) (err error ) {
176
- nodeClients = append (nodeClients , client )
177
- return
178
- }
179
- clusterClient .ForEachMaster (ctx , fn )
165
+ nodeCount , nodeClients , nodesAddresses = updateSecondarySlicesCluster (clusterClient , ctx )
180
166
} else {
181
167
nodeCount = 1
182
168
nodesAddresses = append (nodesAddresses , fmt .Sprintf ("%s:%s" , * host , * port ))
@@ -214,6 +200,7 @@ func main() {
214
200
if err != nil {
215
201
log .Fatal (err )
216
202
}
203
+ nodeCount , nodeClients , nodesAddresses = updateSecondarySlicesCluster (clusterClient , ctx )
217
204
}
218
205
// trap Ctrl+C and call cancel on the context
219
206
// We Use this instead of the previous stopChannel + chan radix.PubSubMessage
@@ -334,6 +321,37 @@ func main() {
334
321
wg .Wait ()
335
322
}
336
323
324
+ func updateSecondarySlicesCluster (clusterClient * redis.ClusterClient , ctx context.Context ) (int , []* redis.Client , []string ) {
325
+ var nodeCount = 0
326
+ var nodesAddresses []string
327
+ var nodeClients []* redis.Client
328
+ log .Println ("Getting cluster slots info." )
329
+ slots , err := clusterClient .ClusterSlots (ctx ).Result ()
330
+ if err != nil {
331
+ log .Fatal (err )
332
+ }
333
+
334
+ log .Println (fmt .Sprintf ("Detailing cluster slots info. Total slot groups: %d" , len (slots )))
335
+ for _ , slotInfo := range slots {
336
+ log .Println (fmt .Sprintf ("\t Slot range start %d end %d. Nodes: %v" , slotInfo .Start , slotInfo .End , slotInfo .Nodes ))
337
+ }
338
+ log .Println (fmt .Sprintf ("Detailing cluster node info" ))
339
+ fn := func (ctx context.Context , client * redis.Client ) (err error ) {
340
+ clusterSlicesMu .Lock ()
341
+ nodeClients = append (nodeClients , client )
342
+ addr := client .Conn ().String ()
343
+ addrS := strings .Split (addr , ":" )
344
+ finalAddr := fmt .Sprintf ("%s:%s" , addrS [0 ][len (" Redis<" )- 1 :], addrS [1 ][:len (addrS [1 ])- 3 ])
345
+ log .Println (fmt .Sprintf ("Cluster node pos #%d. Address: %s." , len (nodeClients ), finalAddr ))
346
+ nodesAddresses = append (nodesAddresses , finalAddr )
347
+ clusterSlicesMu .Unlock ()
348
+ return
349
+ }
350
+ clusterClient .ForEachMaster (ctx , fn )
351
+ nodeCount = len (slots )
352
+ return nodeCount , nodeClients , nodesAddresses
353
+ }
354
+
337
355
func updateCLI (tick * time.Ticker , c chan os.Signal , message_limit int64 , w * tabwriter.Writer , test_time int ) (bool , time.Time , time.Duration , uint64 , []float64 ) {
338
356
339
357
start := time .Now ()
0 commit comments