summaryrefslogtreecommitdiff
path: root/utils/redis-copy.rb
diff options
context:
space:
mode:
authorRyan Biesemeyer <ryan@simplymeasured.com>2013-11-06 08:31:57 +0000
committerRyan Biesemeyer <ryan@simplymeasured.com>2013-11-06 08:31:57 +0000
commitae8642fb79867ef7a6a672567e66a43dab94fcbc (patch)
tree0819bdbdd4ea8ef53da95bed3f069a661b22fe12 /utils/redis-copy.rb
parent5fd6dee0e633cc3c2f4cb6f33741e6cb1eed9653 (diff)
downloadredis-ae8642fb79867ef7a6a672567e66a43dab94fcbc.tar.gz
Deprecate utils/redis-copy.rb in favor of redis-copy gem
Diffstat (limited to 'utils/redis-copy.rb')
-rw-r--r--utils/redis-copy.rb67
1 files changed, 12 insertions, 55 deletions
diff --git a/utils/redis-copy.rb b/utils/redis-copy.rb
index d892e377f..7c5c52dd6 100644
--- a/utils/redis-copy.rb
+++ b/utils/redis-copy.rb
@@ -3,66 +3,23 @@
#
# Copy the whole dataset from one Redis instance to another one
#
-# WARNING: currently hashes and sorted sets are not supported! This
-# program should be updated.
+# WARNING: this utility is deprecated and serves as a legacy adapter
+# for the more-robust redis-copy gem.
-require 'rubygems'
-require 'redis'
-require 'digest/sha1'
+require 'shellwords'
def redisCopy(opts={})
- sha1=""
- src = Redis.new(:host => opts[:srchost], :port => opts[:srcport])
- dst = Redis.new(:host => opts[:dsthost], :port => opts[:dstport])
- puts "Loading key names..."
- keys = src.keys('*')
- puts "Copying #{keys.length} keys..."
- c = 0
- keys.each{|k|
- 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!"
+ src = "#{opts[:srchost]}:#{opts[:srcport]}"
+ dst = "#{opts[:dsthost]}:#{opts[:dstport]}"
+ `redis-copy #{src.shellescape} #{dst.shellescape}`
+rescue Errno::ENOENT
+ $stderr.puts 'This utility requires the redis-copy executable',
+ 'from the redis-copy gem on https://rubygems.org',
+ 'To install it, run `gem install redis-copy`.'
+ exit 1
end
+$stderr.puts "This utility is deprecated. Use the redis-copy gem instead."
if ARGV.length != 4
puts "Usage: redis-copy.rb <srchost> <srcport> <dsthost> <dstport>"
exit 1