#!/usr/bin/ruby # = Redis-Dump # # # Usage: # # $ redis-report -h # $ redis-report # $ redis-report -d 15 # #-- RD_HOME = File.expand_path File.join(File.dirname(__FILE__), '..') lib_dir = File.join(RD_HOME, 'lib') $:.unshift lib_dir require 'redis/dump' require 'drydock' # Command-line interface for bin/redis-dump class Redis::Dump::CLI extend Drydock default :report trawler :report global :u, :uri, String, "Redis URI (e.g. redis://hostname[:port])" global :d, :database, Integer, "Redis database (e.g. -d 15)" global :v, :verbose, "Increase output" do @verbose ||= 0 @verbose += 1 end global :V, :version, "Display version" do puts "Version: #{Redis::Dump::VERSION.to_s}" exit 0 end global :D, :debug do Redis::Dump.debug = true end global :nosafe do Redis::Dump.safe = false end before do |obj| obj.global.uri ||= 'redis://%s:%s' % [Redis::Dump.host, Redis::Dump.port] obj.global.uri = 'redis://' << obj.global.uri unless obj.global.uri.match(/^redis:\/\//) obj.global.database &&= obj.global.database.to_i obj.global.database ||= (0..15) Redis::Dump.ld " redis_uri: #{obj.global.uri} (#{obj.global.database})" end usage "= 1 dbs[record['db']] ||= 0 dbs[record['db']] += record['size'] total_size += record['size'] end puts dbs.keys.sort.collect { |db| " db#{db}: #{dbs[db].to_bytes}" } puts "total: #{total_size.to_bytes}" end end begin Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run? rescue Drydock::ArgError, Drydock::OptError => ex STDERR.puts ex.message STDERR.puts ex.usage rescue Drydock::InvalidArgument => ex STDERR.puts ex.message rescue Drydock::UnknownCommand => ex STDERR.puts "Unknown command: %s" % ex.name rescue Interrupt puts $/, "Exiting... " exit 1 rescue => ex STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}" STDERR.puts ex.backtrace if Redis::Dump.debug end