Class: Dumper::Database::Redis

Inherits:
Base
  • Object
show all
Defined in:
lib/dumper/database/redis.rb

Constant Summary collapse

DUMP_TOOL =
'redis-cli'
FORMAT =
'rdb'

Instance Attribute Summary

Attributes inherited from Base

#config, #custom_options, #filename, #format, #tmpdir

Instance Method Summary collapse

Methods inherited from Base

#dump_path, #dump_tool_path, #file_ext, #finalize

Methods included from Utility::ObjectFinder

#find_instance_in_object_space

Instance Method Details

#commandObject



7
8
9
10
# File 'lib/dumper/database/redis.rb', line 7

def command
  uncompressed = filename.sub('.gz','')
  "cd #{tmpdir} && cp #{@config[:dbpath]} #{uncompressed} && gzip #{uncompressed}"
end

#set_config_for(rails_env = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dumper/database/redis.rb', line 12

def set_config_for(rails_env=nil)
  return unless defined?(::Redis) &&
    (main_thread_redis = find_instance_in_object_space(::Redis))

  # redis-rb v4 added CLIENT command support
  m = main_thread_redis.respond_to?(:_client) ? :_client : :client
  client = main_thread_redis.send(m)

  # New connection for the agent thread
  redis = ::Redis.new(:host => client.host, :port => client.port, :password => client.password, :db => client.db)
  dir         = redis.config(:get, :dir)['dir']
  dbfilename  = redis.config(:get, :dbfilename)['dbfilename']
  dbpath = "#{dir}/#{dbfilename}"

  return unless File.exist?(dbpath) # Redis must run on the back up node

  @config = {
    :host => client.host,
    :port => client.port,
    :password => client.password,
    :database => client.db,
    :dump_tool => dump_tool_path,
    :dbpath => dbpath
  }
end