Skip to content

Commit e1b1298

Browse files
committed
Cluster test: basic cluster nodes info access functions.
1 parent 0bcc7cb commit e1b1298

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/cluster/cluster.tcl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,41 @@
44
# This softare is released under the BSD License. See the COPYING file for
55
# more information.
66

7+
# Returns a parsed CLUSTER NODES output as a list of dictionaries.
8+
proc get_cluster_nodes id {
9+
set lines [split [R $id cluster nodes] "\r\n"]
10+
set nodes {}
11+
foreach l $lines {
12+
set l [string trim $l]
13+
if {$l eq {}} continue
14+
set args [split $l]
15+
set node [dict create \
16+
id [lindex $args 0] \
17+
addr [lindex $args 1] \
18+
flags [split [lindex $args 2] ,] \
19+
slaveof [lindex $args 3] \
20+
ping_sent [lindex $args 4] \
21+
pong_recv [lindex $args 5] \
22+
config_epoch [lindex $args 6] \
23+
linkstate [lindex $args 7] \
24+
slots [lrange $args 8 -1] \
25+
]
26+
lappend nodes $node
27+
}
28+
return $nodes
29+
}
30+
31+
# Test node for flag.
32+
proc has_flag {node flag} {
33+
expr {[lsearch -exact [dict get $node flags] $flag] != -1}
34+
}
35+
36+
# Returns the parsed myself node entry as a dictionary.
37+
proc get_myself id {
38+
set nodes [get_cluster_nodes $id]
39+
foreach n $nodes {
40+
if {[has_flag $n myself]} {return $n}
41+
}
42+
return {}
43+
}
744

0 commit comments

Comments
 (0)