#!/usr/bin/ruby # = Redis-Dump # # # Usage: # # $ redis-load -h # $ keys" option :FLUSH, "Flush the redis db before populating. THIS WILL DESTROY DATA." command :populate do |obj| require 'benchmark' obj.option.count ||= 100_000 obj.global.database ||= 0 rd = Redis::Dump.new obj.global.database, obj.global.uri rd.each_database do |redis| now = Time.now.utc.to_i if obj.option.FLUSH puts "Flushing db #{redis.client.id}..." redis.flushdb end puts "Generating..." time = Benchmark.measure do redis.pipelined do obj.option.count.times do |idx| grp = (idx % 10)+1 val = '0' * (grp*100).to_i redis.set 'rdtemp:%d:idx-%d:group-%d' % [now, idx, grp], val end end end info = redis.info puts '%s: %s' % [redis.client.id, info["db#{redis.client.db}"]] puts 'Total used memory: %s' % [info['used_memory_human']] puts time.to_s end end command :info do |obj| rd = Redis::Dump.new obj.global.database, obj.global.uri memory = nil rd.each_database do |redis| info = redis.info memory ||= info['used_memory_human'] next unless info["db#{redis.client.db}"] puts '%s: %s' % [redis.client.id, info["db#{redis.client.db}"]] end puts 'Total used memory: %s' % [memory] end end begin Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run? rescue RuntimeError => ex STDERR.puts ex.message 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