Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
5344357f
Commit
5344357f
authored
May 02, 2014
by
antirez
Browse files
Cluster: Tcl cluster client: build nodes representation.
parent
8b7e23bd
Changes
1
Show whitespace changes
Inline
Side-by-side
tests/support/cluster.tcl
View file @
5344357f
...
...
@@ -57,9 +57,9 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
# Contact the first responding startup node.
set idx 0
;
# Index of the node that will respond.
foreach start_node $::redis_cluster::startup_nodes
(
$id
)
{
lassign
[
split $start_node :
]
host
port
lassign
[
split $start_node :
]
start_host start_
port
if
{[
catch
{
set r
[
redis $
host $
port
]
set r
[
redis $
start_host $start_
port
]
set nodes_descr
[
$r
cluster nodes
]
$r close
}]}
{
...
...
@@ -81,11 +81,45 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} {
set left
[
lrange $l 0
[
expr
{
$idx-1
}]]
set right
[
lrange $l
[
expr
{
$idx
+1
}]
end
]
set l
[
concat
[
lindex $l $idx
]
$left $right
]
set :redis_cluster::startup_nodes
(
$id
)
$l
set
:
:redis_cluster::startup_nodes
(
$id
)
$l
}
puts $nodes_descr
exit
# Parse CLUSTER NODES output to populate the nodes description.
set nodes
{}
;
# addr -> node description hash.
foreach line
[
split $nodes_descr
"
\n
"
]
{
set line
[
string trim $line
]
if
{
$line
eq
{}}
continue
set args
[
split $line
" "
]
lassign $args nodeid addr flags slaveof pingsent pongrecv configepoch linkstate
set slots
[
lrange $args 8 end
]
if
{
$addr
eq
{
:0
}}
{
set addr $start_host:$start_port
}
lassign
[
split $addr :
]
host port
# Connect to the node
set link
{}
catch
{
set link
[
redis $host $port
]}
# Build this node description as an hash.
set node
[
dict create
\
id $nodeid
\
addr $addr
\
host $host
\
port $port
\
flags $flags
\
slaveof $slaveof
\
link $link
\
]
dict set nodes $addr $node
}
set ::redis_cluster::nodes
(
$id
)
$nodes
# TODO: Populates the slots -> nodes map.
dict for
{
addr node
}
$nodes
{
puts
"
$addr
->
$node
"
}
}
proc ::redis_cluster::__dispatch__
{
id method args
}
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment