File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments