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
d3f7fbfc
Commit
d3f7fbfc
authored
Sep 28, 2011
by
antirez
Browse files
initial node loading info code for redis-trib
parent
1ef8b0a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-trib.rb
View file @
d3f7fbfc
...
@@ -22,6 +22,8 @@ class ClusterNode
...
@@ -22,6 +22,8 @@ class ClusterNode
@port
=
s
[
1
]
@port
=
s
[
1
]
@slots
=
{}
@slots
=
{}
@dirty
=
false
@dirty
=
false
@info
=
nil
@friends
=
[]
end
end
def
to_s
def
to_s
...
@@ -29,6 +31,7 @@ class ClusterNode
...
@@ -29,6 +31,7 @@ class ClusterNode
end
end
def
connect
(
o
=
{})
def
connect
(
o
=
{})
return
if
@r
xputs
"Connecting to node
#{
self
}
: "
xputs
"Connecting to node
#{
self
}
: "
begin
begin
@r
=
Redis
.
new
(
:host
=>
@host
,
:port
=>
@port
)
@r
=
Redis
.
new
(
:host
=>
@host
,
:port
=>
@port
)
...
@@ -58,6 +61,39 @@ class ClusterNode
...
@@ -58,6 +61,39 @@ class ClusterNode
end
end
end
end
def
load_info
(
o
=
{})
self
.
connect
nodes
=
@r
.
cluster
(
"nodes"
).
split
(
"
\n
"
)
nodes
.
each
{
|
n
|
# name addr flags role ping_sent ping_recv link_status slots
name
,
addr
,
flags
,
role
,
ping_sent
,
ping_recv
,
link_status
,
slots
=
n
.
split
(
" "
)
info
=
{
:name
=>
name
,
:addr
=>
addr
,
:flags
=>
flags
.
split
(
","
),
:role
=>
role
,
:ping_sent
=>
ping_sent
.
to_i
,
:ping_recv
=>
ping_recv
.
to_i
,
:link_status
=>
link_status
}
if
info
[
:flags
].
index
(
"myself"
)
@info
=
info
@slots
=
{}
slots
.
split
(
","
).
each
{
|
s
|
if
s
.
index
(
"-"
)
start
,
stop
=
s
.
split
(
"-"
)
self
.
add_slots
((
start
.
to_i
)
..
(
stop
.
to_i
))
else
self
.
add_slots
((
s
.
to_i
)
..
(
s
.
to_i
))
end
}
@dirty
=
false
elsif
o
[
:getfriends
]
@friends
<<
info
end
}
end
def
add_slots
(
slots
)
def
add_slots
(
slots
)
slots
.
each
{
|
s
|
slots
.
each
{
|
s
|
@slots
[
s
]
=
:new
@slots
[
s
]
=
:new
...
@@ -205,6 +241,7 @@ class RedisTrib
...
@@ -205,6 +241,7 @@ class RedisTrib
node
=
ClusterNode
.
new
(
ARGV
[
1
])
node
=
ClusterNode
.
new
(
ARGV
[
1
])
node
.
connect
(
:abort
=>
true
)
node
.
connect
(
:abort
=>
true
)
node
.
assert_cluster
node
.
assert_cluster
node
.
load_info
add_node
(
node
)
add_node
(
node
)
check_cluster
check_cluster
end
end
...
...
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