redis-dump 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10cd6b5b38373bf672fd814a0e27c602af033971
4
- data.tar.gz: 2d60859c6b5f6aeef16bb5c67ef567e4ce2e1197
3
+ metadata.gz: abca1efe649fb8dc2fa0da791d9dba9e57035e8d
4
+ data.tar.gz: 03443fc968e02ba47f5a829a2bd0ec00df6cc239
5
5
  SHA512:
6
- metadata.gz: bd71e2af932393d4522f54f6144603c4798939cca837747d0e8809831df115ca1d45e0ab45a7e248d0ef11c2d8e8e58049e5ae342745386458d33bb897911b54
7
- data.tar.gz: e8c14c0a6f049bc4cef426ef6b251859c9ea80533deffe2cff76ed2ff3093f2617a301e27fc3ea48c6174bf68247c1e7a44cbac836fcd1aeafa8c75aa8e6743c
6
+ metadata.gz: 4a2e15b302f3532f3a6a245dc6f7074ca703bbf08c374c6fd9c5eaee9636bea10833f63f5a55487d45aec2a16a5bdb17a3ec612fd053211a670ec982360a1c87
7
+ data.tar.gz: 4da09294ae6d1fe5d9fc0d27e4f2fe56bd5f6a259ee87080ba246f7d344217b98e17ce714ab17135e515a6b4fde18913b2dbc533d1390aa6571ebba7a9f77385
Binary file
data.tar.gz.sig CHANGED
@@ -1 +1,3 @@
1
- ��!k��Ơ̵'}D�[��fH�[�C ��s��ǻ��r�@��UNIQ�P�+�!l�'�z��TW*�?z�T�=@/�V���H�����4����d��`�yÍV:��2lz��4�Һ_r���ݛm�'���K�Ѕ!£���ȟ{�~���L���8�P|�D񤋩���7�O�zj3\Ğ��{��&a��6U&� �X�����$��ׂ�!b>:!����� �M�b��a!�V�NƱ�q�-��5�
1
+ _���;F���NDC��Q$�=��$[s��Uz��oٻ�
2
+ "�Ȁ�.o��V
3
+ %���$�
@@ -1,5 +1,16 @@
1
1
  REDIS-DUMP, CHANGES
2
2
 
3
+ #### 0.4.0 (2017-11-23) ###############################
4
+
5
+ * ADDED: support for redis >= 4.0
6
+ * ADDED: support for base64 encoded string keys
7
+ * FIXED: redis passwords with special characters
8
+
9
+
10
+ #### 0.3.6 (2017-11-09) ###############################
11
+
12
+ * FIXED: redis < 4.0 dependency [Clemens Fuchslocher]
13
+
3
14
  #### 0.3.5 (2013-02-07) ###############################
4
15
 
5
16
  * Array#select fix for Ruby 1.8 [TIT]
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Solutious Inc, Delano Mandelbaum
1
+ Copyright (c) 2010-2017 Solutious Inc, Delano Mandelbaum
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
16
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
17
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
19
+ THE SOFTWARE.
@@ -1,24 +1,24 @@
1
- = Redis-Dump v0.3 ALPHA
1
+ = Redis-Dump v0.4 BETA
2
2
 
3
3
  <i>Backup and restore your Redis data to and from JSON.</i>
4
4
 
5
- <b>NOTE: This is alpha software. TEST IT BEFORE RELYING ON IT.</b>
5
+ <b>NOTE: This is beta software. TEST IT BEFORE RELYING ON IT.</b>
6
6
 
7
7
 
8
8
  == Usage
9
9
 
10
- There are two executables: <tt>redis-dump</tt> and <tt>redis-load</tt>.
10
+ There are two executables: <tt>redis-dump</tt> and <tt>redis-load</tt>.
11
11
 
12
- $ redis-dump
12
+ $ redis-dump
13
13
  $ redis-dump -u 127.0.0.1:6371 > db_full.json
14
14
  $ redis-dump -u 127.0.0.1:6371 -d 15 > db_db15.json
15
-
15
+
16
16
  $ < db_full.json redis-load
17
17
  $ < db_db15.json redis-load -d 15
18
18
  # OR
19
19
  $ cat db_full | redis-load
20
20
  $ cat db_db15.json | redis-load -d 15
21
-
21
+
22
22
  # You can specify the redis URI via an environment variable
23
23
  $ export REDIS_URI=127.0.0.1:6371
24
24
  $ redis-dump
@@ -28,16 +28,16 @@ There are two executables: <tt>redis-dump</tt> and <tt>redis-load</tt>.
28
28
  # :<password>@<domain>:<port>
29
29
  # Note the leading colon is important for specifying no username.
30
30
  $ redis-dump -u :234288a830f009980e08@example.redistogo.com:9055
31
-
31
+
32
32
  == Output format
33
33
 
34
34
  All redis datatypes are output to a simple JSON object. All objects have the following 5 fields:
35
35
 
36
36
  * db (Integer)
37
37
  * key (String)
38
- * ttl (Integer): The amount of time in seconds that the key will live. If no expire is set, it's -1.
39
- * type (String), one of: string, list, set, zset, hash, none.
40
- * value (String): A JSON-encoded string. For keys of type list, set, zset, and hash, the data is given a specific structure (see below).
38
+ * ttl (Integer): The amount of time in seconds that the key will live. If no expire is set, it's -1.
39
+ * type (String), one of: string, list, set, zset, hash, none.
40
+ * value (String): A JSON-encoded string. For keys of type list, set, zset, and hash, the data is given a specific structure (see below).
41
41
 
42
42
  Here are examples of each datatype:
43
43
 
@@ -49,23 +49,23 @@ Here are examples of each datatype:
49
49
 
50
50
  === Important note about TTLs
51
51
 
52
- One of the purposes of redis-dump is the ability to restore the database to a known state. When you restore a redis database from a redis-dump file, <em>the expires are reset to their values at the time the dump was created</em>. This is different from restoring from Redis' native .rdb or .aof files (expires are stored relative to the actual time they were set).
52
+ One of the purposes of redis-dump is the ability to restore the database to a known state. When you restore a redis database from a redis-dump file, <em>the expires are reset to their values at the time the dump was created</em>. This is different from restoring from Redis' native .rdb or .aof files (expires are stored relative to the actual time they were set).
53
53
 
54
54
 
55
55
  == Output directly to an encrypted file
56
56
 
57
57
  For most sensitive data, you should consider encrypting the data directly without writing first to a temp file. You can do this using the power of [gpg](http://www.gnupg.org/) and file descriptors. Here are a couple examples:
58
-
58
+
59
59
  # Encrypt the data (interactive)
60
60
  $ redis-dump -u 127.0.0.1:6371 -d 15 | gpg --force-mdc -v -c > path/2/backup-db15.json.gpg
61
-
61
+
62
62
  # Encrypt the data (automated)
63
63
  $ redis-dump -u 127.0.0.1:6371 -d 15 | 3</path/2/passphrase.txt gpg --force-mdc -v -c --passphrase-fd 3 > path/2/backup-db15.json.gpg
64
-
64
+
65
65
  # Decrypt the file (interactive)
66
66
  $ gpg path/2/backup-db15.json.gpg
67
67
  Enter passphrase: *******
68
-
68
+
69
69
  # Decrypt the file (automated)
70
70
  $ 3</path/2/passphrase.txt gpg --passphrase-fd 3 path/2/backup-db15.json.gpg
71
71
 
@@ -73,7 +73,7 @@ For most sensitive data, you should consider encrypting the data directly withou
73
73
  == Loading data with binary strings
74
74
 
75
75
  If you have binary or serialized data in your Redis database, the YAJL parser may not load your dump file because it sees some of the binary data as 'invalid bytes in UTF8 string'. If you are certain that your data is binary and not malformed UTF8, you can use the -n flag to redis-load to tell YAJL to not check the input for UTF8 validity. Use with caution!
76
-
76
+
77
77
  == Installation
78
78
 
79
79
  $ gem install redis-dump
@@ -88,7 +88,7 @@ Or of you want to run it directly:
88
88
  $ gem install drydock
89
89
  $ ruby -rubygems bin/redis-dump
90
90
 
91
-
91
+
92
92
  == More Info
93
93
 
94
94
  * Codes[http://github.com/delano/redis-dump]
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ begin
23
23
  s.authors = ["Delano Mandelbaum"]
24
24
 
25
25
  s.add_dependency("yajl-ruby", ">= 0.1")
26
- s.add_dependency("redis", ">= 2.0", "< 4.0")
26
+ s.add_dependency("redis", ">= 4.0")
27
27
  s.add_dependency("uri-redis", ">= 0.4.0")
28
28
  s.add_dependency("drydock", ">= 0.6.9")
29
29
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.4.0
@@ -1,10 +1,10 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  # = Redis-Dump
4
- #
4
+ #
5
5
  #
6
6
  # Usage:
7
- #
7
+ #
8
8
  # $ redis-dump -h
9
9
  # $ redis-dump > dumpfile_full.json
10
10
  # $ redis-dump -d 15 > dumpfile_db15.json
@@ -13,7 +13,7 @@
13
13
 
14
14
  RD_HOME = File.expand_path File.join(File.dirname(__FILE__), '..')
15
15
  lib_dir = File.join(RD_HOME, 'lib')
16
- $:.unshift lib_dir
16
+ $:.unshift lib_dir
17
17
 
18
18
  require 'redis/dump'
19
19
  require 'drydock'
@@ -21,17 +21,25 @@ require 'drydock'
21
21
  # Command-line interface for bin/redis-dump
22
22
  class Redis::Dump::CLI
23
23
  extend Drydock
24
-
24
+
25
25
  default :dump
26
26
  trawler :dump
27
-
27
+
28
28
  global :u, :uri, String, "Redis URI (e.g. redis://hostname[:port])"
29
29
  global :d, :database, Integer, "Redis database (e.g. -d 15)"
30
+ global :a, :password, String, "Redis password (e.g. -a 'my@pass/word')" do |v|
31
+ Redis::Dump.password = v
32
+ end
30
33
  global :s, :sleep, Integer, "Sleep for S seconds after dumping (for debugging)"
31
34
  global :c, :count, Integer, "Chunk size (default: #{Redis::Dump.chunk_size})"
32
35
  global :f, :filter, String, "Filter selected keys (passed directly to redis' KEYS command)"
33
- global :O, :without_optimizations, "Disable run time optimizations"
34
- global :V, :version, "Display version" do
36
+ global :b, :base64, "Encode key values as base64 (useful for binary values)" do
37
+ Redis::Dump.with_base64 = true
38
+ end
39
+ global :O, :without_optimizations, "Disable run time optimizations" do
40
+ Redis::Dump.with_optimizations = false
41
+ end
42
+ global :V, :version, "Display version" do
35
43
  puts "redis-dump v#{Redis::Dump::VERSION.to_s}"
36
44
  exit 0
37
45
  end
@@ -41,24 +49,23 @@ class Redis::Dump::CLI
41
49
  global :nosafe do
42
50
  Redis::Dump.safe = false
43
51
  end
44
-
52
+
45
53
  before do |obj|
46
54
  obj.global.uri ||= ENV['REDIS_URI']
47
55
  obj.global.uri ||= 'redis://%s:%s' % [Redis::Dump.host, Redis::Dump.port]
48
56
  obj.global.uri = 'redis://' << obj.global.uri unless obj.global.uri.match(/^redis:\/\//)
49
57
  obj.global.database &&= obj.global.database.to_i
50
58
  obj.global.database ||= (0..15)
51
- Redis::Dump.with_optimizations = false if obj.global.without_optimizations
52
59
  Redis::Dump.chunk_size = obj.global.count if obj.global.count
53
60
  Redis::Dump.ld "redis_uri: #{obj.global.uri} (#{obj.global.database})"
54
61
  Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
55
62
  end
56
-
63
+
57
64
  after do |obj|
58
65
  Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
59
66
  sleep obj.global.sleep.to_i if obj.global.sleep
60
67
  end
61
-
68
+
62
69
  usage "redis-dump > dumpfile_full.json"
63
70
  usage "redis-dump -d 15 > dumpfile_db15.json"
64
71
  usage "redis-dump -d 15 -c 100_000 > dumpfile_db15.json"
@@ -70,10 +77,10 @@ class Redis::Dump::CLI
70
77
  puts records
71
78
  end
72
79
  end
73
-
80
+
74
81
  end
75
82
 
76
-
83
+
77
84
  begin
78
85
  Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
79
86
  rescue RuntimeError => ex
@@ -91,4 +98,4 @@ rescue Interrupt
91
98
  rescue => ex
92
99
  STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
93
100
  STDERR.puts ex.backtrace if Redis::Dump.debug
94
- end
101
+ end
@@ -1,10 +1,10 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  # = Redis-Dump
4
- #
4
+ #
5
5
  #
6
6
  # Usage:
7
- #
7
+ #
8
8
  # $ redis-load -h
9
9
  # $ <dumpfile_full.json redis-load
10
10
  # $ <dumpfile_db15.json redis-load -d 15
@@ -13,7 +13,7 @@
13
13
 
14
14
  RD_HOME = File.expand_path File.join(File.dirname(__FILE__), '..')
15
15
  lib_dir = File.join(RD_HOME, 'lib')
16
- $:.unshift lib_dir
16
+ $:.unshift lib_dir
17
17
 
18
18
  require 'redis/dump'
19
19
  require 'drydock'
@@ -21,17 +21,23 @@ require 'drydock'
21
21
  # Command-line interface for bin/redis-dump
22
22
  class Redis::Dump::CLI
23
23
  extend Drydock
24
-
24
+
25
25
  default :load
26
26
  trawler :load
27
-
27
+
28
28
  global :u, :uri, String, "Redis URI (e.g. redis://hostname[:port])"
29
29
  global :d, :database, Integer, "Redis database (e.g. -d 15)"
30
+ global :a, :password, String, "Redis password (e.g. -a 'my@pass/word')" do |v|
31
+ Redis::Dump.password = v
32
+ end
30
33
  global :s, :sleep, Integer, "Sleep for S seconds after dumping (for debugging)"
34
+ global :b, :base64, "Decode key values from base64 (used with redis-dump -b)" do
35
+ Redis::Dump.with_base64 = true
36
+ end
31
37
  global :n, :no_check_utf8 do
32
38
  Redis::Dump.check_utf8 = false
33
39
  end
34
- global :V, :version, "Display version" do
40
+ global :V, :version, "Display version" do
35
41
  puts "redis-dump v#{Redis::Dump::VERSION.to_s}"
36
42
  exit 0
37
43
  end
@@ -41,7 +47,7 @@ class Redis::Dump::CLI
41
47
  global :nosafe do
42
48
  Redis::Dump.safe = false
43
49
  end
44
-
50
+
45
51
  before do |obj|
46
52
  obj.global.uri ||= ENV['REDIS_URI']
47
53
  obj.global.uri ||= 'redis://%s:%s' % [Redis::Dump.host, Redis::Dump.port]
@@ -51,12 +57,12 @@ class Redis::Dump::CLI
51
57
  Redis::Dump.ld "redis_uri: #{obj.global.uri} (#{obj.global.database})"
52
58
  Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
53
59
  end
54
-
60
+
55
61
  after do |obj|
56
62
  Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
57
63
  sleep obj.global.sleep.to_i if obj.global.sleep
58
64
  end
59
-
65
+
60
66
  usage "<dumpfile_full.json redis-load"
61
67
  usage "<dumpfile_db15.json redis-load -d 15"
62
68
  command :load do |obj|
@@ -64,7 +70,7 @@ class Redis::Dump::CLI
64
70
  raise "Usage: cat dumpfile_db15.json | redis-load -d 15" if STDIN.tty?
65
71
  rd.load STDIN
66
72
  end
67
-
73
+
68
74
  about "Add test data to redis"
69
75
  usage "redis-load populate -c 1000"
70
76
  usage "redis-load -d 1 populate -c 1000"
@@ -97,7 +103,7 @@ class Redis::Dump::CLI
97
103
  puts time.to_s
98
104
  end
99
105
  end
100
-
106
+
101
107
  command :info do |obj|
102
108
  rd = Redis::Dump.new obj.global.database, obj.global.uri
103
109
  memory = nil
@@ -111,7 +117,7 @@ class Redis::Dump::CLI
111
117
  end
112
118
  end
113
119
 
114
-
120
+
115
121
  begin
116
122
  Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
117
123
  rescue RuntimeError => ex
@@ -5,6 +5,7 @@ end
5
5
  require 'redis'
6
6
  require 'uri/redis'
7
7
  require 'yajl'
8
+ require 'base64'
8
9
 
9
10
  class Redis
10
11
  class Dump
@@ -18,8 +19,9 @@ class Redis
18
19
  @parser = Yajl::Parser.new
19
20
  @chunk_size = 10000
20
21
  @with_optimizations = true
22
+ @with_base64 = false
21
23
  class << self
22
- attr_accessor :debug, :encoder, :parser, :safe, :host, :port, :chunk_size, :with_optimizations
24
+ attr_accessor :debug, :encoder, :parser, :safe, :host, :port, :password, :chunk_size, :with_optimizations, :with_base64
23
25
  def le(msg)
24
26
  STDERR.puts "#%.4f: %s" % [Time.now.utc.to_f, msg]
25
27
  end
@@ -37,7 +39,7 @@ class Redis
37
39
  end
38
40
  attr_accessor :dbs, :uri
39
41
  attr_reader :redis_connections
40
- def initialize(dbs=nil,uri="redis://#{Redis::Dump.host}:#{Redis::Dump.port}")
42
+ def initialize(dbs=nil, uri="redis://#{Redis::Dump.host}:#{Redis::Dump.port}")
41
43
  @redis_connections = {}
42
44
  @uri = uri
43
45
  unless dbs.nil?
@@ -50,8 +52,12 @@ class Redis
50
52
  redis_connections["#{uri}/#{db}"] ||= connect("#{uri}/#{db}")
51
53
  end
52
54
  def connect(this_uri)
53
- #self.class.ld 'CONNECT: ' << this_uri
54
- Redis.connect :url => this_uri
55
+ self.class.ld 'CONNECT: ' << this_uri
56
+ opts = {
57
+ :url => this_uri
58
+ }
59
+ opts[:password] = Redis::Dump.password if Redis::Dump.password
60
+ Redis.new **opts
55
61
  end
56
62
 
57
63
  def each_database
@@ -60,7 +66,6 @@ class Redis
60
66
  end
61
67
  end
62
68
 
63
- # See each_key
64
69
  def dump filter=nil
65
70
  filter ||= '*'
66
71
  entries = []
@@ -71,12 +76,10 @@ class Redis
71
76
  Redis::Dump.ld "Memory after loading keys: #{Redis::Dump.memory_usage}kb"
72
77
  dump_keys.each_with_index do |key,idx|
73
78
  entry, idxplus = key, idx+1
74
- #self.class.ld " #{key} (#{key_dump['type']}): #{key_dump['size'].to_bytes}"
75
- #entry_enc = self.class.encoder.encode entry
76
79
  if block_given?
77
80
  chunk_entries << entry
78
81
  process_chunk idx, dump_keys_size do |count|
79
- Redis::Dump.ld " dumping #{chunk_entries.size} (#{count}) from #{redis.client.id}"
82
+ Redis::Dump.ld " dumping #{chunk_entries.size} (#{count}) from #{redis.connection[:id]}"
80
83
  output_buffer = []
81
84
  chunk_entries = chunk_entries.select do |key|
82
85
  type = Redis::Dump.type(redis, key)
@@ -121,9 +124,9 @@ class Redis
121
124
  entry, idxplus = Redis::Dump.report(redis, key), idx+1
122
125
  chunk_entries << entry
123
126
  process_chunk idx, dump_keys_size do |count|
124
- Redis::Dump.ld " reporting on #{chunk_entries.size} (#{idxplus}) from #{redis.client.id}"
127
+ Redis::Dump.ld " reporting on #{chunk_entries.size} (#{idxplus}) from #{redis.connection[:id]}"
125
128
  chunk_entries.each do |e|
126
- #puts record if obj.global.verbose >= 1
129
+ puts record if obj.global.verbose >= 1
127
130
  dbs[e['db']] ||= 0
128
131
  dbs[e['db']] += e['size']
129
132
  total_size += e['size']
@@ -146,14 +149,18 @@ class Redis
146
149
  next
147
150
  end
148
151
  this_redis = redis(obj["db"])
149
- #Redis::Dump.ld "load[#{this_redis.hash}, #{obj}]"
152
+ Redis::Dump.ld "load[#{this_redis.hash}, #{obj}]"
150
153
  if each_record.nil?
151
154
  if Redis::Dump.safe && this_redis.exists(obj['key'])
152
- #Redis::Dump.ld " record exists (no change)"
155
+ Redis::Dump.ld " record exists (no change)"
153
156
  next
154
157
  end
155
158
  begin
156
- Redis::Dump.set_value this_redis, obj['key'], obj['type'], obj['value'], obj['ttl']
159
+ val, type = obj['value'], obj['type']
160
+ if Redis::Dump.with_base64 && type === 'string'
161
+ val = Base64.decode64 val
162
+ end
163
+ ret = Redis::Dump.set_value this_redis, obj['key'], type, val, obj['ttl']
157
164
  rescue => ex
158
165
  Redis::Dump.le '(key: %s) %s' % [obj['key'], ex.message]
159
166
  end
@@ -171,21 +178,23 @@ class Redis
171
178
  type
172
179
  end
173
180
  def report(this_redis, key)
174
- info = { 'db' => this_redis.client.db, 'key' => key }
181
+ info = { 'db' => this_redis.connection[:db], 'key' => key }
175
182
  info['type'] = type(this_redis, key)
176
183
  info['size'] = stringify(this_redis, key, info['type'], info['value']).size
177
184
  info['bytes'] = info['size'].to_bytes
178
- #ld "report[#{this_redis.hash}, #{info}]"
179
185
  info
180
186
  end
181
187
  def dump(this_redis, key, type=nil)
182
188
  type ||= type(this_redis, key)
183
- info = { 'db' => this_redis.client.db, 'key' => key }
189
+ info = { 'db' => this_redis.connection[:db], 'key' => key }
184
190
  info['ttl'] = this_redis.ttl key
185
191
  info['type'] = type
192
+ stringified = stringify(this_redis, key, info['type'], info['value'])
186
193
  info['value'] = value(this_redis, key, info['type'])
187
- info['size'] = stringify(this_redis, key, info['type'], info['value']).size
188
- #ld "dump[#{this_redis.hash}, #{info}]"
194
+ info['size'] = stringified.size
195
+ if Redis::Dump.with_base64 && type === 'string'
196
+ info['value'] = Base64.encode64(info['value'])
197
+ end
189
198
  info
190
199
  end
191
200
  def dump_strings(this_redis, keys)
@@ -193,10 +202,14 @@ class Redis
193
202
  idx = -1
194
203
  keys.collect { |key|
195
204
  idx += 1
205
+ val = vals[idx].to_s
196
206
  info = {
197
- 'db' => this_redis.client.db, 'key' => key,
198
- 'ttl' => this_redis.ttl(key), 'type' => 'string',
199
- 'value' => vals[idx].to_s, 'size' => vals[idx].to_s.size
207
+ 'db' => this_redis.connection[:db],
208
+ 'key' => key,
209
+ 'ttl' => this_redis.ttl(key),
210
+ 'type' => 'string',
211
+ 'value' => Redis::Dump.with_base64 ? Base64.encode64(val) : val,
212
+ 'size' => vals[idx].to_s.size
200
213
  }
201
214
  block_given? ? yield(info) : info
202
215
  }
@@ -1,13 +1,14 @@
1
1
  require 'redis/dump'
2
2
 
3
3
  # The test instance of redis must be running:
4
- # $ redis-server try/redis-server.conf
4
+ # $ redis-server try/redis.conf
5
5
 
6
6
  @uri_base = "redis://127.0.0.1:6371"
7
7
 
8
8
  Redis::Dump.debug = false
9
9
  Redis::Dump.safe = true
10
10
 
11
+
11
12
  ## Connect to DB
12
13
  @rdump = Redis::Dump.new 0, @uri_base
13
14
  @rdump.redis_connections.size
@@ -43,8 +44,8 @@ db0.redis(0).keys.size
43
44
 
44
45
  ## DB 0 content matches previous dump content
45
46
  values = @rdump.dump
46
- values.sort
47
- #=> @values.sort
47
+ [values[0], values.size]
48
+ #=> [@values[0], @values.size]
48
49
 
49
50
  ## Won't load data in safe mode if records exist
50
51
  @rdump.load @values.join
@@ -58,3 +59,4 @@ Redis::Dump.safe = false
58
59
  Redis::Dump.safe = true
59
60
  db0 = Redis::Dump.new 0, @uri_base
60
61
  db0.redis(0).flushdb
62
+
@@ -1,13 +1,14 @@
1
1
  require 'redis/dump'
2
2
 
3
3
  # The test instance of redis must be running:
4
- # $ redis-server try/redis-server.conf
4
+ # $ redis-server try/redis.conf
5
5
 
6
6
  @uri_base = "redis://127.0.0.1:6371"
7
7
 
8
8
  Redis::Dump.debug = false
9
9
  Redis::Dump.safe = true
10
10
 
11
+
11
12
  ## Connect to DB
12
13
  @rdump = Redis::Dump.new 0..1, @uri_base
13
14
  @rdump.redis_connections.size
@@ -40,4 +41,4 @@ unknown_keys = [URI.parse("#{@uri_base}/0/unknownkey1"), URI.parse("#{@uri_base}
40
41
  Redis::Dump.safe = true
41
42
  db0 = Redis::Dump.new 0..1, @uri_base
42
43
  db0.redis(0).flushdb
43
- db0.redis(1).flushdb
44
+ db0.redis(1).flushdb
@@ -0,0 +1,58 @@
1
+ require 'redis/dump'
2
+ require 'pry'
3
+
4
+ # The test instance of redis must be running:
5
+ # $ redis-server try/redis.conf
6
+
7
+ @uri_base = "redis://127.0.0.1:6371"
8
+
9
+ Redis::Dump.debug = false
10
+ Redis::Dump.safe = true
11
+ Redis::Dump.with_base64 = true
12
+
13
+ ## Connect to DB
14
+ @rdump = Redis::Dump.new 0..1, @uri_base
15
+ @rdump.redis_connections.size
16
+ #=> 2
17
+
18
+ ## Populate
19
+ @rdump.redis(0).set 'stringkey1', 'stringvalue1'
20
+ @rdump.redis(0).set 'stringkey2', 'stringvalue2'
21
+ @rdump.redis(0).keys.size
22
+ #=> 2
23
+
24
+ ## Is base64 encoded
25
+ @values = @rdump.dump
26
+ @values[0]
27
+ #=> "{\"db\":0,\"key\":\"stringkey1\",\"ttl\":-1,\"type\":\"string\",\"value\":\"c3RyaW5ndmFsdWUx\\n\",\"size\":12}"
28
+
29
+ ## Can dump
30
+ @values = @rdump.dump
31
+ @values.size
32
+ #=> 2
33
+
34
+ # Clear DB 0
35
+ db0 = Redis::Dump.new 0, @uri_base
36
+ db0.redis(0).flushdb
37
+ db0.redis(0).keys.size
38
+ #=> 0
39
+
40
+ ## Can load data
41
+ @rdump.load @values.join
42
+ @rdump.redis(0).keys.size
43
+ #=> 2
44
+
45
+ ## Is base64 decoded
46
+ stringkey = @rdump.redis(0).get('stringkey1')
47
+ #=> 'stringvalue1'
48
+
49
+ # Clear DB 0
50
+ db0 = Redis::Dump.new 0, @uri_base
51
+ db0.redis(0).flushdb
52
+ db0.redis(0).keys.size
53
+ #=> 0
54
+
55
+ Redis::Dump.safe = true
56
+ db0 = Redis::Dump.new 0, @uri_base
57
+ db0.redis(0).flushdb
58
+
@@ -1,12 +1,12 @@
1
1
  # redis-dump redis config
2
- # 2013-02-01
2
+ # 2017-11-09
3
3
 
4
4
  dir /tmp
5
5
  pidfile redisdump-test.pid
6
6
  logfile redisdump-test.log
7
7
  dbfilename redisdump-test.rdb
8
8
 
9
- #requirepass CHANGEME
9
+ # requirepass @/
10
10
 
11
11
  bind 127.0.0.1
12
12
  port 6371
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-dump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -30,7 +30,7 @@ cert_chain:
30
30
  L4d54WIy4HkZCqQXoTSiK5HZMIdXkPk3F1bZdJ8Dy1sMRru0rUkkM5mW7TQ75mfW
31
31
  Zp0QrZyNZhtitrXFbZneGRrIA/8G2Krft5Ly/A==
32
32
  -----END CERTIFICATE-----
33
- date: 2017-11-10 00:00:00.000000000 Z
33
+ date: 2017-11-24 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: yajl-ruby
@@ -50,22 +50,16 @@ dependencies:
50
50
  name: redis
51
51
  requirement: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "<"
54
- - !ruby/object:Gem::Version
55
- version: '4.0'
56
53
  - - ">="
57
54
  - !ruby/object:Gem::Version
58
- version: '2.0'
55
+ version: '4.0'
59
56
  type: :runtime
60
57
  prerelease: false
61
58
  version_requirements: !ruby/object:Gem::Requirement
62
59
  requirements:
63
- - - "<"
64
- - !ruby/object:Gem::Version
65
- version: '4.0'
66
60
  - - ">="
67
61
  - !ruby/object:Gem::Version
68
- version: '2.0'
62
+ version: '4.0'
69
63
  - !ruby/object:Gem::Dependency
70
64
  name: uri-redis
71
65
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +112,7 @@ files:
118
112
  - redis-dump.gemspec
119
113
  - try/10_redis_dump_try.rb
120
114
  - try/20_dump_specific_keys_try.rb
115
+ - try/30_dump_base64_try.rb
121
116
  - try/db0.json
122
117
  - try/redis.conf
123
118
  homepage: http://github.com/delano/redis-dump
metadata.gz.sig CHANGED
Binary file