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
57d83d56
Commit
57d83d56
authored
Apr 13, 2011
by
antirez
Browse files
redis-trib create, first version is know working
parent
8231b1ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-trib.rb
View file @
57d83d56
...
...
@@ -75,7 +75,7 @@ class ClusterNode
@dirty
=
false
end
def
info
def
info
_string
slots
=
@slots
.
map
{
|
k
,
v
|
k
}.
reduce
{
|
a
,
b
|
a
=
[(
a
..
a
)]
if
!
a
.
is_a?
(
Array
)
if
b
==
(
a
[
-
1
].
last
)
+
1
...
...
@@ -89,6 +89,15 @@ class ClusterNode
}.
join
(
","
)
"
#{
self
.
to_s
.
ljust
(
25
)
}
slots:
#{
slots
}
"
end
def
info
{
:host
=>
@host
,
:port
=>
@port
,
:slots
=>
@slots
,
:dirty
=>
@dirty
}
end
def
is_dirty?
@dirty
...
...
@@ -127,8 +136,13 @@ class RedisTrib
yes_or_die
"Can I set the above configuration?"
flush_nodes_config
puts
"** Nodes configuration updated"
puts
"Sending CLUSTER MEET messages to join the cluster"
puts
"
**
Sending CLUSTER MEET messages to join the cluster"
join_cluster
check_cluster
end
def
check_cluster
puts
"Check if the cluster looks sane"
end
def
alloc_slots
...
...
@@ -151,11 +165,21 @@ class RedisTrib
def
show_nodes
@nodes
.
each
{
|
n
|
puts
n
.
info
puts
n
.
info
_string
}
end
def
join_cluster
# We use a brute force approach to make sure the node will meet
# each other, that is, sending CLUSTER MEET messages to all the nodes
# about the very same node.
# Thanks to gossip this information should propagate across all the
# cluster in a matter of seconds.
first
=
false
@nodes
.
each
{
|
n
|
if
!
first
then
first
=
n
.
info
;
next
;
end
# Skip the first node
n
.
r
.
cluster
(
"meet"
,
first
[
:host
],
first
[
:port
])
}
end
def
yes_or_die
(
msg
)
...
...
@@ -169,7 +193,8 @@ class RedisTrib
end
COMMANDS
=
{
"create-cluster"
=>
[
"create_cluster"
,
-
2
,
"node1_addr node2_addr ..."
]
"create"
=>
[
"create_cluster"
,
-
2
,
"host1:port host2:port ... hostN:port"
],
"check"
=>
[
"check_cluster"
,
1
,
"host:port"
]
}
# Sanity check
...
...
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