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
407798c1
Commit
407798c1
authored
Apr 11, 2011
by
Salvatore Sanfilippo
Browse files
Redis-trib initial implementation (currently can not do any actual work)
parent
1c708b25
Changes
1
Show whitespace changes
Inline
Side-by-side
src/redis-trib.rb
0 → 100755
View file @
407798c1
#!/usr/bin/env ruby
require
'rubygems'
require
'redis'
class
RedisTrib
def
xputs
(
s
)
printf
s
STDOUT
.
flush
end
def
check_arity
(
req_args
,
num_args
)
if
((
req_args
>
0
and
num_args
!=
req_args
)
||
(
req_args
<
0
and
num_args
<
req_args
.
abs
))
puts
"Wrong number of arguments for specified sub command"
exit
1
end
end
def
parse_node
(
node
)
s
=
node
.
split
(
":"
)
if
s
.
length
!=
2
puts
"Invalid node name
#{
node
}
"
exit
1
end
return
{
:host
=>
s
[
0
],
:port
=>
s
[
1
].
to_i
}
end
def
connect_to_node
(
naddr
)
xputs
"Connecting to node
#{
naddr
[
:host
]
}
:
#{
naddr
[
:port
]
}
: "
begin
r
=
Redis
.
new
(
:host
=>
naddr
[
:host
],
:port
=>
naddr
[
:port
])
r
.
ping
rescue
puts
"ERROR"
puts
"Sorry, can't connect to node
#{
naddr
[
:host
]
}
:
#{
naddr
[
:port
]
}
"
exit
1
end
puts
"OK"
end
def
create_cluster
puts
"Creating cluster"
ARGV
[
1
..-
1
].
each
{
|
node
|
naddr
=
parse_node
(
node
)
r
=
connect_to_node
(
naddr
)
}
end
end
COMMANDS
=
{
"create-cluster"
=>
[
"create_cluster"
,
-
2
]
}
# Sanity check
if
ARGV
.
length
==
0
puts
"Usage: redis-trib <command> <arguments ...>"
exit
1
end
rt
=
RedisTrib
.
new
cmd_spec
=
COMMANDS
[
ARGV
[
0
].
downcase
]
if
!
cmd_spec
puts
"Unknown redis-trib subcommand '
#{
ARGV
[
0
]
}
'"
exit
1
end
rt
.
check_arity
(
cmd_spec
[
1
],
ARGV
.
length
)
# Dispatch
rt
.
send
(
cmd_spec
[
0
])
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