]>
git.saurik.com Git - redis.git/blob - utils/redis-copy.rb
1 # redis-copy.rb - Copyright (C) 2009-2010 Salvatore Sanfilippo
2 # BSD license, See the COPYING file for more information.
4 # Copy the whole dataset from one Redis instance to another one
6 # WARNING: currently hashes and sorted sets are not supported! This
7 # program should be updated.
13 def redisCopy(opts
={})
15 src
= Redis
.new(:host => opts
[:srchost], :port => opts
[:srcport])
16 dst
= Redis
.new(:host => opts
[:dsthost], :port => opts
[:dstport])
17 puts
"Loading key names..."
19 puts
"Copying #{keys.length} keys..."
23 ttl
= src
.ttl(k
).to_i
if vtype !
= "none"
28 list
= src
.lrange(k
,0,-1)
30 # Empty list special case
41 # Empty set special case
50 puts
"WARNING: key '#{k}' was removed in the meanwhile."
53 # Handle keys with an expire time set
54 if ttl !
= -1 and vtype !
= "none"
60 puts
"#{c}/#{keys.length} completed"
67 puts
"Usage: redis-copy.rb <srchost> <srcport> <dsthost> <dstport>"
70 puts
"WARNING: it's up to you to FLUSHDB the destination host before to continue, press any key when ready."
76 puts
"Copying #{srchost}:#{srcport} into #{dsthost}:#{dstport}"
77 redisCopy(:srchost => srchost
, :srcport => srcport
.to_i
,
78 :dsthost => dsthost
, :dstport => dstport
.to_i
)