Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
e1a1d904
Commit
e1a1d904
authored
Nov 06, 2013
by
antirez
Browse files
Merge branch 'unstable' of github.com:/antirez/redis into unstable
parents
80da056c
b5ec3ede
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils/redis-copy.rb
View file @
e1a1d904
...
@@ -3,66 +3,23 @@
...
@@ -3,66 +3,23 @@
#
#
# Copy the whole dataset from one Redis instance to another one
# Copy the whole dataset from one Redis instance to another one
#
#
# WARNING:
currently hashes and sorted sets are not supported! This
# WARNING:
this utility is deprecated and serves as a legacy adapter
#
program should be updated
.
#
for the more-robust redis-copy gem
.
require
'rubygems'
require
'shellwords'
require
'redis'
require
'digest/sha1'
def
redisCopy
(
opts
=
{})
def
redisCopy
(
opts
=
{})
sha1
=
""
src
=
"
#{
opts
[
:srchost
]
}
:
#{
opts
[
:srcport
]
}
"
src
=
Redis
.
new
(
:host
=>
opts
[
:srchost
],
:port
=>
opts
[
:srcport
])
dst
=
"
#{
opts
[
:dsthost
]
}
:
#{
opts
[
:dstport
]
}
"
dst
=
Redis
.
new
(
:host
=>
opts
[
:dsthost
],
:port
=>
opts
[
:dstport
])
`redis-copy
#{
src
.
shellescape
}
#{
dst
.
shellescape
}
`
puts
"Loading key names..."
rescue
Errno
::
ENOENT
keys
=
src
.
keys
(
'*'
)
$stderr
.
puts
'This utility requires the redis-copy executable'
,
puts
"Copying
#{
keys
.
length
}
keys..."
'from the redis-copy gem on https://rubygems.org'
,
c
=
0
'To install it, run `gem install redis-copy`.'
keys
.
each
{
|
k
|
exit
1
vtype
=
src
.
type?
(
k
)
ttl
=
src
.
ttl
(
k
).
to_i
if
vtype
!=
"none"
if
vtype
==
"string"
dst
[
k
]
=
src
[
k
]
elsif
vtype
==
"list"
list
=
src
.
lrange
(
k
,
0
,
-
1
)
if
list
.
length
==
0
# Empty list special case
dst
.
lpush
(
k
,
""
)
dst
.
lpop
(
k
)
else
list
.
each
{
|
ele
|
dst
.
rpush
(
k
,
ele
)
}
end
elsif
vtype
==
"set"
set
=
src
.
smembers
(
k
)
if
set
.
length
==
0
# Empty set special case
dst
.
sadd
(
k
,
""
)
dst
.
srem
(
k
,
""
)
else
set
.
each
{
|
ele
|
dst
.
sadd
(
k
,
ele
)
}
end
elsif
vtype
==
"none"
puts
"WARNING: key '
#{
k
}
' was removed in the meanwhile."
end
# Handle keys with an expire time set
if
ttl
!=
-
1
and
vtype
!=
"none"
dst
.
expire
(
k
,
ttl
)
end
c
=
c
+
1
if
(
c
%
1000
)
==
0
puts
"
#{
c
}
/
#{
keys
.
length
}
completed"
end
}
puts
"DONE!"
end
end
$stderr
.
puts
"This utility is deprecated. Use the redis-copy gem instead."
if
ARGV
.
length
!=
4
if
ARGV
.
length
!=
4
puts
"Usage: redis-copy.rb <srchost> <srcport> <dsthost> <dstport>"
puts
"Usage: redis-copy.rb <srchost> <srcport> <dsthost> <dstport>"
exit
1
exit
1
...
...
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