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
6b4e9558
Commit
6b4e9558
authored
Apr 29, 2014
by
antirez
Browse files
Cluster test: basic cluster nodes info access functions.
parent
a11ae385
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/cluster/cluster.tcl
View file @
6b4e9558
...
...
@@ -4,4 +4,41 @@
# This softare is released under the BSD License. See the COPYING file for
# more information.
# Returns a parsed CLUSTER NODES output as a list of dictionaries.
proc get_cluster_nodes id
{
set lines
[
split
[
R $id cluster nodes
]
"
\r\n
"
]
set nodes
{}
foreach l $lines
{
set l
[
string trim $l
]
if
{
$l
eq
{}}
continue
set args
[
split $l
]
set node
[
dict create
\
id
[
lindex $args 0
]
\
addr
[
lindex $args 1
]
\
flags
[
split
[
lindex $args 2
]
,
]
\
slaveof
[
lindex $args 3
]
\
ping_sent
[
lindex $args 4
]
\
pong_recv
[
lindex $args 5
]
\
config_epoch
[
lindex $args 6
]
\
linkstate
[
lindex $args 7
]
\
slots
[
lrange $args 8 -1
]
\
]
lappend nodes $node
}
return $nodes
}
# Test node for flag.
proc has_flag
{
node flag
}
{
expr
{[
lsearch -exact
[
dict get $node flags
]
$flag
]
!= -1
}
}
# Returns the parsed myself node entry as a dictionary.
proc get_myself id
{
set nodes
[
get_cluster_nodes $id
]
foreach n $nodes
{
if
{[
has_flag $n myself
]}
{
return $n
}
}
return
{}
}
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