@@ -57,9 +57,9 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
5757 # Contact the first responding startup node.
5858 set idx 0; # Index of the node that will respond.
5959 foreach start_node $::redis_cluster::startup_nodes($id) {
60- lassign [split $start_node :] host port
60+ lassign [split $start_node :] start_host start_port
6161 if {[catch {
62- set r [redis $host $port ]
62+ set r [redis $start_host $start_port ]
6363 set nodes_descr [$r cluster nodes]
6464 $r close
6565 }]} {
@@ -81,11 +81,45 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
8181 set left [lrange $l 0 [expr {$idx -1}]]
8282 set right [lrange $l [expr {$idx +1}] end]
8383 set l [concat [lindex $l $idx ] $left $right ]
84- set :redis_cluster::startup_nodes($id ) $l
84+ set :: redis_cluster::startup_nodes($id ) $l
8585 }
8686
87- puts $nodes_descr
88- exit
87+ # Parse CLUSTER NODES output to populate the nodes description.
88+ set nodes {} ; # addr -> node description hash.
89+ foreach line [split $nodes_descr " \n " ] {
90+ set line [string trim $line ]
91+ if {$line eq {}} continue
92+ set args [split $line " " ]
93+ lassign $args nodeid addr flags slaveof pingsent pongrecv configepoch linkstate
94+ set slots [lrange $args 8 end]
95+ if {$addr eq {:0}} {
96+ set addr $start_host :$start_port
97+ }
98+ lassign [split $addr :] host port
99+
100+ # Connect to the node
101+ set link {}
102+ catch {set link [redis $host $port ]}
103+
104+ # Build this node description as an hash.
105+ set node [dict create \
106+ id $nodeid \
107+ addr $addr \
108+ host $host \
109+ port $port \
110+ flags $flags \
111+ slaveof $slaveof \
112+ link $link \
113+ ]
114+ dict set nodes $addr $node
115+ }
116+
117+ set ::redis_cluster::nodes($id ) $nodes
118+
119+ # TODO: Populates the slots -> nodes map.
120+ dict for {addr node} $nodes {
121+ puts " $addr -> $node "
122+ }
89123}
90124
91125proc ::redis_cluster::__dispatch__ {id method args} {
0 commit comments