summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-05-02 10:55:07 +0200
committerantirez <antirez@gmail.com>2014-05-02 10:56:02 +0200
commitfcd2065f8eb6ca0518027188eea5c03eaa3d5e70 (patch)
treeb19ba4b7f4c7eb80b67c24c818e8c83056b5341f
parent5344357f802c4882a2af781fab4ba72d6c26e34d (diff)
downloadredis-fcd2065f8eb6ca0518027188eea5c03eaa3d5e70.tar.gz
Cluster: Tcl cluster client: slots-nodes map and close method.
Now the client is able to actually run commands in a Redis Cluster assuming the slots->nodes map is stable.
-rw-r--r--tests/support/cluster.tcl27
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/support/cluster.tcl b/tests/support/cluster.tcl
index c04214109..811dd6d9d 100644
--- a/tests/support/cluster.tcl
+++ b/tests/support/cluster.tcl
@@ -109,6 +109,7 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
port $port \
flags $flags \
slaveof $slaveof \
+ slots $slots \
link $link \
]
dict set nodes $addr $node
@@ -116,10 +117,32 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
set ::redis_cluster::nodes($id) $nodes
- # TODO: Populates the slots -> nodes map.
+ # Populates the slots -> nodes map.
dict for {addr node} $nodes {
- puts "$addr -> $node"
+ foreach slotrange [dict get $node slots] {
+ lassign [split $slotrange -] start end
+ if {$end == {}} {set end $start}
+ for {set j $start} {$j <= $end} {incr j} {
+ dict set ::redis_cluster::slots($id) $j $addr
+ }
+ }
+ }
+}
+
+# Free a redis_cluster handle.
+proc ::redis_cluster::__method__close {id} {
+ catch {
+ set nodes $::redis_cluster::nodes($id)
+ dict for {addr node} $nodes {
+ catch {
+ [dict get $node link] close
+ }
+ }
}
+ catch {unset ::redis_cluster::startup_nodes($id)}
+ catch {unset ::redis_cluster::nodes($id)}
+ catch {unset ::redis_cluster::slots($id)}
+ catch {interp alias {} ::redis_cluster::instance$id {}}
}
proc ::redis_cluster::__dispatch__ {id method args} {