]>
git.saurik.com Git - redis.git/blob - utils/redis-copy.rb
af214b7980630303b7eceab874103f2a88a8e4ea
1 # redis-sha1.rb - Copyright (C) 2009 Salvatore Sanfilippo
2 # BSD license, See the COPYING file for more information.
4 # Performs the SHA1 sum of the whole datset.
5 # This is useful to spot bugs in persistence related code and to make sure
6 # Slaves and Masters are in SYNC.
8 # If you hack this code make sure to sort keys and set elements as this are
9 # unsorted elements. Otherwise the sum may differ with equal dataset.
15 def redisCopy(opts
={})
17 src
= Redis
.new(:host => opts
[:srchost], :port => opts
[:srcport])
18 dst
= Redis
.new(:host => opts
[:dsthost], :port => opts
[:dstport])
19 puts
"Loading key names..."
21 puts
"Copying #{keys.length} keys..."
25 ttl
= src
.ttl(k
).to_i
if vtype !
= "none"
30 list
= src
.lrange(k
,0,-1)
32 # Empty list special case
43 # Empty set special case
52 puts
"WARNING: key '#{k}' was removed in the meanwhile."
55 # Handle keys with an expire time set
56 if ttl !
= -1 and vtype !
= "none"
62 puts
"#{c}/#{keys.length} completed"
69 puts
"Usage: redis-copy.rb <srchost> <srcport> <dsthost> <dstport>"
72 puts
"WARNING: it's up to you to FLUSHDB the destination host before to continue, press any key when ready."
78 puts
"Copying #{srchost}:#{srcport} into #{dsthost}:#{dstport}"
79 redisCopy(:srchost => srchost
, :srcport => srcport
.to_i
,
80 :dsthost => dsthost
, :dstport => dstport
.to_i
)