@@ -43,7 +43,8 @@ def initialize(info = {})
4343 register_options (
4444 [
4545 OptPath . new ( 'LocalFile' , [ false , 'Local file to be uploaded' ] ) ,
46- OptString . new ( 'RemoteFile' , [ false , 'Remote file path' ] )
46+ OptString . new ( 'RemoteFile' , [ false , 'Remote file path' ] ) ,
47+ OptBool . new ( 'DISABLE_RDBCOMPRESSION' , [ false , 'Disable string compression when dump .rdb databases' , true ] )
4748 ]
4849 )
4950 end
@@ -59,6 +60,7 @@ def send_file(path, content)
5960 # XXX: this is a hack -- we should really parse the responses more correctly
6061 original_dir = redis_command ( 'CONFIG' , 'GET' , 'dir' ) . split ( /\r \n / ) . last
6162 original_dbfilename = redis_command ( 'CONFIG' , 'GET' , 'dbfilename' ) . split ( /\r \n / ) . last
63+ original_rdbcompression = redis_command ( 'CONFIG' , 'GET' , 'rdbcompression' ) . split ( /\r \n / ) . last
6264
6365 # set the directory which stores the current redis local store
6466 data = redis_command ( 'CONFIG' , 'SET' , 'dir' , dirname )
@@ -68,6 +70,17 @@ def send_file(path, content)
6870 data = redis_command ( 'CONFIG' , 'SET' , 'dbfilename' , basename )
6971 return unless data . include? ( '+OK' )
7072
73+ # Compression string objects using LZF when dump .rdb databases ?
74+ # For default that's set to 'yes' as it's almost always a win.
75+ # If you want to save some CPU in the saving child set it to 'no' but
76+ # the dataset will likely be bigger if you have compressible values or
77+ # keys.
78+
79+ if datastore [ 'DISABLE_RDBCOMPRESSION' ] && original_rdbcompression . upcase == 'YES'
80+ data = redis_command ( 'CONFIG' , 'SET' , 'rdbcompression' , 'no' )
81+ return unless data . include? ( '+OK' )
82+ end
83+
7184 # set a key in this db that contains our content
7285 # XXX: this does not work well (at all) if the content we are uploading is
7386 # multiline. It also probably doesn't work well if the content isn't
@@ -76,6 +89,7 @@ def send_file(path, content)
7689 data = redis_command ( 'SET' , key , content )
7790 return unless data . include? ( '+OK' )
7891 data = redis_command ( 'SAVE' )
92+
7993 if data . include? ( '+OK' )
8094 print_good ( "#{ peer } -- saved #{ content . size } bytes inside of redis DB at #{ path } " )
8195 else
@@ -87,6 +101,7 @@ def send_file(path, content)
87101 # XXX: ensure that these get sent if we prematurely return if a previous command fails
88102 redis_command ( 'CONFIG' , 'SET' , 'dir' , original_dir )
89103 redis_command ( 'CONFIG' , 'SET' , 'dbfilename' , original_dbfilename )
104+ redis_command ( 'CONFIG' , 'SET' , 'rdbcompression' , original_rdbcompression )
90105 redis_command ( 'DEL' , key )
91106 redis_command ( 'SAVE' )
92107 end
0 commit comments