redis-dump 0.4.0 → 0.6.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
- SHA1:
3
- metadata.gz: abca1efe649fb8dc2fa0da791d9dba9e57035e8d
4
- data.tar.gz: 03443fc968e02ba47f5a829a2bd0ec00df6cc239
2
+ SHA256:
3
+ metadata.gz: bd6bb93f7ba8bf8297d3c1726ac91eda76d0f230a36cedf730d90bbdf815ab5f
4
+ data.tar.gz: 31993502c019c5723073dcf1e3c0b0d2dbf187a1657d396261e0506a1870506f
5
5
  SHA512:
6
- metadata.gz: 4a2e15b302f3532f3a6a245dc6f7074ca703bbf08c374c6fd9c5eaee9636bea10833f63f5a55487d45aec2a16a5bdb17a3ec612fd053211a670ec982360a1c87
7
- data.tar.gz: 4da09294ae6d1fe5d9fc0d27e4f2fe56bd5f6a259ee87080ba246f7d344217b98e17ce714ab17135e515a6b4fde18913b2dbc533d1390aa6571ebba7a9f77385
6
+ metadata.gz: e448efa86667cd48563fd1e50df277c686c963156db5465e17e333b542a04267b730c640ec96ed1323a1bd9378c252383890359bda11f89c6b973cafc84267d2
7
+ data.tar.gz: 0ce386d440465041cc33f5a52a079272ad2c11080e757690887e46a3e3e944fa405065d0ab73063fe9666386be52a7ecf27e0835e277b2f0451387ae31aa8381
@@ -0,0 +1,69 @@
1
+ ##
2
+ # Pre-Commit Configuration
3
+ #
4
+ # Initial setup:
5
+ #
6
+ # 0. Install the pre-commit framework (if it isn't already on your system):
7
+
8
+ # $ pip install pre-commit
9
+ #
10
+ # 1. Install the git hook:
11
+ #
12
+ # $ pre-commit install
13
+ #
14
+ #
15
+ # Other commands:
16
+ #
17
+ # Run it on all the files in this repo:
18
+ # $ pre-commit run --all-files
19
+ #
20
+ # Updating plugin repositories:
21
+ # $ pre-commit autoupdate
22
+ #
23
+ # Automatically enable pre-commit on repositories
24
+ # $ git config --global init.templateDir ~/.git-template
25
+ # $ pre-commit init-templatedir ~/.git-template
26
+ #
27
+ # See also:
28
+ # - https://pre-commit.com for more information
29
+ # - https://pre-commit.com/hooks.html for more hooks
30
+ #
31
+
32
+ default_install_hook_types:
33
+ - pre-commit
34
+ - prepare-commit-msg
35
+
36
+ fail_fast: true
37
+
38
+ repos:
39
+ - repo: meta
40
+ hooks:
41
+ - id: check-hooks-apply
42
+ - id: check-useless-excludes
43
+ - id: identity
44
+
45
+ - repo: https://github.com/pre-commit/pre-commit-hooks
46
+ rev: v4.6.0
47
+ hooks:
48
+ - id: trailing-whitespace
49
+ - id: end-of-file-fixer
50
+ - id: check-yaml
51
+ - id: detect-private-key
52
+ - id: mixed-line-ending
53
+ - id: check-added-large-files
54
+ args: ["--maxkb=1000"]
55
+ - id: no-commit-to-branch
56
+ args: ["--branch", "develop", "--branch", "rel/.*"]
57
+ - id: check-merge-conflict
58
+ - id: forbid-submodules
59
+
60
+ - repo: https://github.com/avilaton/add-msg-issue-prefix-hook
61
+ rev: v0.0.11
62
+ hooks:
63
+ - id: add-msg-issue-prefix
64
+ stages: [prepare-commit-msg]
65
+ name: Link commit to Github issue
66
+ args:
67
+ - "--default=[NOJIRA]"
68
+ - "--pattern=[a-zA-Z0-9]{0,10}-?[0-9]{1,5}"
69
+ - "--template=[#{}]"
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7.5
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGES.txt CHANGED
@@ -1,5 +1,19 @@
1
1
  REDIS-DUMP, CHANGES
2
2
 
3
+ #### 0.6.0 (2024-06-17) ###############################
4
+
5
+ * ADDED: Supports redis-rb 5.0
6
+ * ADDED: Supports SSL via rediss://
7
+ * CHANGED: Updated dependencies (see https://github.com/delano/redis-dump/pull/37)
8
+ * FIXED: Resolved `sadd` warnings in redis 4.0 #35
9
+
10
+
11
+ #### 0.5.0 (2023-01-17) ###############################
12
+
13
+ * ADDED: Timeout support for redis connections
14
+ * CHANGED: uri-redis dependency to 1.0.0
15
+
16
+
3
17
  #### 0.4.0 (2017-11-23) ###############################
4
18
 
5
19
  * ADDED: support for redis >= 4.0
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "drydock", ">= 0.6.9"
6
+ gem "oj", ">= 3.16.4"
7
+ gem "redis", ">= 4.0", "< 6.0"
8
+ gem "uri-redis", ">= 1.3.0"
9
+ gem "yajl-ruby", ">= 1.4.3"
10
+
11
+ gem "pry-byebug", "~> 3.10.1", require: false, group: :development
12
+ gem "rake", "~> 13.0", require: false, group: :development
13
+ gem "rubocop", "~> 1.64.1", require: false, group: :development
14
+ gem "tryouts", "~> 2.2.0", require: false, group: :development
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ast (2.4.2)
5
+ bigdecimal (3.1.8)
6
+ byebug (11.1.3)
7
+ coderay (1.1.3)
8
+ connection_pool (2.4.1)
9
+ drydock (0.6.9)
10
+ json (2.7.2)
11
+ language_server-protocol (3.17.0.3)
12
+ method_source (1.1.0)
13
+ oj (3.16.4)
14
+ bigdecimal (>= 3.0)
15
+ parallel (1.25.1)
16
+ parser (3.3.3.0)
17
+ ast (~> 2.4.1)
18
+ racc
19
+ pry (0.14.2)
20
+ coderay (~> 1.1)
21
+ method_source (~> 1.0)
22
+ pry-byebug (3.10.1)
23
+ byebug (~> 11.0)
24
+ pry (>= 0.13, < 0.15)
25
+ racc (1.8.0)
26
+ rainbow (3.1.1)
27
+ rake (13.2.1)
28
+ redis (5.2.0)
29
+ redis-client (>= 0.22.0)
30
+ redis-client (0.22.2)
31
+ connection_pool
32
+ regexp_parser (2.9.2)
33
+ rexml (3.3.0)
34
+ strscan
35
+ rubocop (1.64.1)
36
+ json (~> 2.3)
37
+ language_server-protocol (>= 3.17.0)
38
+ parallel (~> 1.10)
39
+ parser (>= 3.3.0.2)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8, < 3.0)
42
+ rexml (>= 3.2.5, < 4.0)
43
+ rubocop-ast (>= 1.31.1, < 2.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 2.4.0, < 3.0)
46
+ rubocop-ast (1.31.3)
47
+ parser (>= 3.3.1.0)
48
+ ruby-progressbar (1.13.0)
49
+ storable (0.10.0)
50
+ strscan (3.1.0)
51
+ sysinfo (0.10.0)
52
+ drydock (< 1.0)
53
+ storable (~> 0.10)
54
+ tryouts (2.2.0)
55
+ sysinfo (~> 0.10)
56
+ unicode-display_width (2.5.0)
57
+ uri-redis (1.3.0)
58
+ yajl-ruby (1.4.3)
59
+
60
+ PLATFORMS
61
+ arm64-darwin-22
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ drydock (>= 0.6.9)
66
+ oj (>= 3.16.4)
67
+ pry-byebug (~> 3.10.1)
68
+ rake (~> 13.0)
69
+ redis (>= 4.0, < 6.0)
70
+ rubocop (~> 1.64.1)
71
+ tryouts (~> 2.2.0)
72
+ uri-redis (>= 1.3.0)
73
+ yajl-ruby (>= 1.4.3)
74
+
75
+ BUNDLED WITH
76
+ 2.5.9
data/LICENSE.txt CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2010-2017 Solutious Inc, Delano Mandelbaum
1
+ MIT License
2
+
3
+ Copyright (c) 2010-2024 Delano Mandelbaum
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
6
  of this software and associated documentation files (the "Software"), to deal
@@ -7,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
9
  copies of the Software, and to permit persons to whom the Software is
8
10
  furnished to do so, subject to the following conditions:
9
11
 
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
12
14
 
13
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # Redis::Dump - v0.6
2
+
3
+ *Redis to JSON and back again. Dump and load Redis databases to/from JSON files.*
4
+
5
+
6
+ ## Installation
7
+
8
+ One of:
9
+ 1. Gemfile: `gem 'redis-dump', '~> 0.4.0'`
10
+ 2. Install manually: `gem install redis-dump`
11
+ 3. Clone with git: `git clone git@github.com:delano/redis-dump.git`
12
+
13
+
14
+
15
+ ## Usage
16
+
17
+ There are two executables: `redis-dump` and `redis-load`.
18
+
19
+ ```bash
20
+ $ redis-dump
21
+ $ redis-dump -u 127.0.0.1:6379 > db_full.json
22
+ $ redis-dump -u 127.0.0.1:6379 -d 15 > db_db15.json
23
+
24
+ $ < db_full.json redis-load
25
+ $ < db_db15.json redis-load -d 15
26
+ # OR
27
+ $ cat db_full | redis-load
28
+ $ cat db_db15.json | redis-load -d 15
29
+
30
+ # You can specify the redis URI via an environment variable
31
+ $ export REDIS_URI=127.0.0.1:6379
32
+ $ redis-dump
33
+
34
+ # If your instance uses a password (such as on RedisToGo), you
35
+ # can specify the Redis URL as such:
36
+ # :<password>@<domain>:<port>
37
+ # Note the leading colon is important for specifying no username.
38
+ $ redis-dump -u :234288a830f009980e08@example.redistogo.com:9055
39
+ ```
40
+
41
+ ### Output format
42
+
43
+ All redis datatypes are output to a simple JSON object. All objects have the following 5 fields:
44
+
45
+ * db (Integer)
46
+ * key (String)
47
+ * ttl (Integer): The amount of time in seconds that the key will live. If no expire is set, it's -1.
48
+ * type (String), one of: string, list, set, zset, hash, none.
49
+ * value (String): A JSON-encoded string. For keys of type list, set, zset, and hash, the data is given a specific structure (see below).
50
+
51
+ Here are examples of each datatype:
52
+
53
+ ```json
54
+ {"db":0,"key":"hashkey","ttl":-1,"type":"hash","value":{"field_a":"value_a","field_b":"value_b","field_c":"value_c"},"size":42}
55
+ {"db":0,"key":"listkey","ttl":-1,"type":"list","value":["value_0","value_1","value_2","value_0","value_1","value_2"],"size":42}
56
+ {"db":0,"key":"setkey","ttl":-1,"type":"set","value":["value_2","value_0","value_1","value_3"],"size":28}
57
+ {"db":0,"key":"zsetkey","ttl":-1,"type":"zset","value":[["value_0","100"],["value_1","100"],["value_2","200"],["value_3","300"],["value_4","400"]],"size":50}
58
+ {"db":0,"key":"stringkey","ttl":79,"type":"string","value":"stringvalue","size":11}
59
+ ```
60
+
61
+ ## Important notes
62
+
63
+ ### About TTLs
64
+
65
+ 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, *the expires are reset to their values at the time the dump was created*. This is different from restoring from Redis' native .rdb or .aof files (expires are stored relative to the actual time they were set).
66
+
67
+ ### Output directly to an encrypted file
68
+
69
+ 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:
70
+
71
+ ```bash
72
+ # Encrypt the data (interactive)
73
+ $ redis-dump -u 127.0.0.1:6379 -d 15 | gpg --force-mdc -v -c > path/2/backup-db1
74
+ ```
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/delano/redis-dump.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,59 +1,8 @@
1
- require "rubygems"
2
- require "rake"
3
- require "rake/clean"
4
- require "rdoc/task"
1
+ # frozen_string_literal: true
5
2
 
6
- task :default => ["build"]
7
- CLEAN.include [ 'pkg', 'rdoc' ]
8
- name = "redis-dump"
9
-
10
- $:.unshift File.join(File.dirname(__FILE__), 'lib')
11
- require "redis/dump"
12
- version = Redis::Dump::VERSION.to_s
13
-
14
- begin
15
- require "jeweler"
16
- Jeweler::Tasks.new do |s|
17
- s.version = version
18
- s.name = name
19
- s.summary = "Backup and restore your Redis data to and from JSON."
20
- s.description = s.summary
21
- s.email = "delano@solutious.com"
22
- s.homepage = "http://github.com/delano/redis-dump"
23
- s.authors = ["Delano Mandelbaum"]
24
-
25
- s.add_dependency("yajl-ruby", ">= 0.1")
26
- s.add_dependency("redis", ">= 4.0")
27
- s.add_dependency("uri-redis", ">= 0.4.0")
28
- s.add_dependency("drydock", ">= 0.6.9")
29
-
30
- s.license = "MIT"
31
-
32
- s.signing_key = File.join('/mnt/gem/', 'gem-private_key.pem')
33
- s.cert_chain = ['gem-public_cert.pem']
34
- end
35
- Jeweler::GemcutterTasks.new
36
- rescue LoadError
37
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
38
- end
39
-
40
- require 'rake/testtask'
41
- Rake::TestTask.new do |t|
42
- t.libs = ["lib", "test"]
43
- end
44
-
45
- extra_files = %w[LICENSE.txt THANKS.txt CHANGES.txt ]
46
- RDoc::Task.new do |rdoc|
47
- rdoc.rdoc_dir = "rdoc"
48
- rdoc.title = "#{name} #{version}"
49
- rdoc.generator = 'hanna' # gem install hanna-nouveau
50
- rdoc.main = 'README.rdoc'
51
- rdoc.rdoc_files.include("README*")
52
- rdoc.rdoc_files.include("bin/*.rb")
53
- rdoc.rdoc_files.include("lib/**/*.rb")
54
- extra_files.each { |file|
55
- rdoc.rdoc_files.include(file) if File.exists?(file)
56
- }
57
- end
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
58
5
 
6
+ RuboCop::RakeTask.new
59
7
 
8
+ task default: :rubocop
@@ -30,6 +30,9 @@ class Redis::Dump::CLI
30
30
  global :a, :password, String, "Redis password (e.g. -a 'my@pass/word')" do |v|
31
31
  Redis::Dump.password = v
32
32
  end
33
+ global :t, :timeout, Integer, "Configure connect, read, and write timeouts (ruby redis client)" do |t|
34
+ Redis::Dump.timeout = t
35
+ end
33
36
  global :s, :sleep, Integer, "Sleep for S seconds after dumping (for debugging)"
34
37
  global :c, :count, Integer, "Chunk size (default: #{Redis::Dump.chunk_size})"
35
38
  global :f, :filter, String, "Filter selected keys (passed directly to redis' KEYS command)"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Redis
4
+ class Dump
5
+ VERSION = "0.6.0"
6
+ end
7
+ end
data/lib/redis/dump.rb CHANGED
@@ -1,12 +1,17 @@
1
+
2
+
1
3
  unless defined?(RD_HOME)
2
4
  RD_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..') )
3
5
  end
4
6
 
5
7
  require 'redis'
6
- require 'uri/redis'
7
8
  require 'yajl'
8
9
  require 'base64'
9
10
 
11
+ require 'uri/redis'
12
+
13
+ require_relative "dump/version"
14
+
10
15
  class Redis
11
16
  class Dump
12
17
  unless defined?(Redis::Dump::VALID_TYPES)
@@ -21,7 +26,7 @@ class Redis
21
26
  @with_optimizations = true
22
27
  @with_base64 = false
23
28
  class << self
24
- attr_accessor :debug, :encoder, :parser, :safe, :host, :port, :password, :chunk_size, :with_optimizations, :with_base64
29
+ attr_accessor :debug, :encoder, :parser, :safe, :host, :port, :password, :timeout, :chunk_size, :with_optimizations, :with_base64
25
30
  def le(msg)
26
31
  STDERR.puts "#%.4f: %s" % [Time.now.utc.to_f, msg]
27
32
  end
@@ -57,6 +62,7 @@ class Redis
57
62
  :url => this_uri
58
63
  }
59
64
  opts[:password] = Redis::Dump.password if Redis::Dump.password
65
+ opts[:timeout] = Redis::Dump.timeout if Redis::Dump.timeout
60
66
  Redis.new **opts
61
67
  end
62
68
 
@@ -71,9 +77,10 @@ class Redis
71
77
  entries = []
72
78
  each_database do |redis|
73
79
  chunk_entries = []
80
+ Redis::Dump.ld "[db#{redis.connection[:db]}] Memory before: #{Redis::Dump.memory_usage}kb"
74
81
  dump_keys = redis.keys(filter)
75
82
  dump_keys_size = dump_keys.size
76
- Redis::Dump.ld "Memory after loading keys: #{Redis::Dump.memory_usage}kb"
83
+ Redis::Dump.ld "[db#{redis.connection[:db]}] Dumping #{dump_keys_size} keys: #{dump_keys.join(', ')}"
77
84
  dump_keys.each_with_index do |key,idx|
78
85
  entry, idxplus = key, idx+1
79
86
  if block_given?
@@ -103,6 +110,8 @@ class Redis
103
110
  entries << self.class.encoder.encode(Redis::Dump.dump(redis, entry))
104
111
  end
105
112
  end
113
+
114
+ Redis::Dump.ld "[db#{redis.connection[:db]}] Memory after: #{Redis::Dump.memory_usage}kb"
106
115
  end
107
116
  entries
108
117
  end
@@ -157,7 +166,9 @@ class Redis
157
166
  end
158
167
  begin
159
168
  val, type = obj['value'], obj['type']
169
+ Redis::Dump.ld " > load `#{val}`"
160
170
  if Redis::Dump.with_base64 && type === 'string'
171
+ Redis::Dump.ld " > load+decode64 for `#{val}`"
161
172
  val = Base64.decode64 val
162
173
  end
163
174
  ret = Redis::Dump.set_value this_redis, obj['key'], type, val, obj['ttl']
@@ -233,7 +244,7 @@ class Redis
233
244
  list.each { |value| this_redis.rpush key, value }
234
245
  end
235
246
  def set_value_set(this_redis, key, set)
236
- set.each { |value| this_redis.sadd key, value }
247
+ set.each { |value| this_redis.sadd? key, value }
237
248
  end
238
249
  def set_value_zset(this_redis, key, zset)
239
250
  zset.each { |pair| this_redis.zadd key, pair[1].to_f, pair[0] }
@@ -260,24 +271,6 @@ class Redis
260
271
  end
261
272
  extend Redis::Dump::ClassMethods
262
273
 
263
- module VERSION
264
- @path = File.join(RD_HOME, 'VERSION')
265
- class << self
266
- attr_reader :version, :path
267
- def version
268
- @version || read_version
269
- end
270
- def read_version
271
- return if @version
272
- @version = File.read(path).strip!
273
- end
274
- def prerelease?() false end
275
- def to_a() version.split('.') end
276
- def to_s() version end
277
- def inspect() version end
278
- end
279
- end
280
-
281
274
  class Problem < RuntimeError
282
275
  def initialize(*args)
283
276
  @args = args.flatten.compact
data/redis-dump.gemspec CHANGED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/redis/dump/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "redis-dump"
7
+ spec.version = Redis::Dump::VERSION
8
+ spec.authors = ["delano"]
9
+ spec.email = "gems@solutious.com"
10
+
11
+ spec.summary = "Backup and restore your Redis data to and from JSON."
12
+ spec.description = "Backup and restore your Redis data to and from JSON by database, key, or key pattern."
13
+ spec.homepage = "https://rubygems.org/gems/redis-dump"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.8")
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{\A(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,6 @@
1
+ module Redis
2
+ module Dump
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
@@ -1,9 +1,11 @@
1
- require 'redis/dump'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/redis/dump'
2
4
 
3
5
  # The test instance of redis must be running:
4
6
  # $ redis-server try/redis.conf
5
7
 
6
- @uri_base = "redis://127.0.0.1:6371"
8
+ @uri_base = "redis://127.0.0.1:6379"
7
9
 
8
10
  Redis::Dump.debug = false
9
11
  Redis::Dump.safe = true
@@ -21,7 +23,7 @@ Redis::Dump.safe = true
21
23
  @rdump.redis(0).hset 'hashkey', 'field_b', 'value_b'
22
24
  @rdump.redis(0).hset 'hashkey', 'field_c', 'value_c'
23
25
  3.times { |idx| @rdump.redis(0).rpush 'listkey', "value_#{idx}" }
24
- 4.times { |idx| @rdump.redis(0).sadd 'setkey', "value_#{idx}" }
26
+ 4.times { |idx| @rdump.redis(0).sadd? 'setkey', "value_#{idx}" }
25
27
  5.times { |idx| @rdump.redis(0).zadd 'zsetkey', idx.zero? ? 100 : 100*idx, "value_#{idx}" }
26
28
  @rdump.redis(0).keys.size
27
29
  #=> 5
@@ -31,12 +33,6 @@ Redis::Dump.safe = true
31
33
  @values.size
32
34
  #=> 5
33
35
 
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
36
  ## Can load data
41
37
  @rdump.load @values.join
42
38
  @rdump.redis(0).keys.size
@@ -56,7 +52,14 @@ Redis::Dump.safe = false
56
52
  @rdump.load @values.join
57
53
  #=> 5
58
54
 
59
- Redis::Dump.safe = true
55
+ ## Clear DB 0
60
56
  db0 = Redis::Dump.new 0, @uri_base
61
57
  db0.redis(0).flushdb
58
+ db0.redis(0).keys.size
59
+ #=> 0
62
60
 
61
+ ## Clear DB 0 in safe mode
62
+ Redis::Dump.safe = true
63
+ db0 = Redis::Dump.new 0, @uri_base
64
+ db0.redis(0).flushdb
65
+ #=> "OK"
@@ -1,9 +1,11 @@
1
- require 'redis/dump'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/redis/dump'
2
4
 
3
5
  # The test instance of redis must be running:
4
6
  # $ redis-server try/redis.conf
5
7
 
6
- @uri_base = "redis://127.0.0.1:6371"
8
+ @uri_base = "redis://127.0.0.1:6379"
7
9
 
8
10
  Redis::Dump.debug = false
9
11
  Redis::Dump.safe = true
@@ -31,13 +33,6 @@ Redis::Dump.safe = true
31
33
  @rdump.dump('*gloria*').sort
32
34
  #=> ['{"db":0,"key":"gloria:0","ttl":-1,"type":"string","value":"gloria_value[0]","size":15}','{"db":0,"key":"gloria:1","ttl":-1,"type":"string","value":"gloria_value[1]","size":15}','{"db":0,"key":"gloria:2","ttl":-1,"type":"string","value":"gloria_value[2]","size":15}']
33
35
 
34
-
35
- ## Dump none existent keys (NOT SUPPORTED AS OF 0.3.0)
36
- unknown_keys = [URI.parse("#{@uri_base}/0/unknownkey1"), URI.parse("#{@uri_base}/1/unknownkey2")]
37
- @rdump.dump(unknown_keys).sort
38
- ##=> ['{"db":0,"key":"unknownkey1","ttl":-1,"type":"none","value":"","size":0}', '{"db":1,"key":"unknownkey2","ttl":-1,"type":"none","value":"","size":0}']
39
-
40
-
41
36
  Redis::Dump.safe = true
42
37
  db0 = Redis::Dump.new 0..1, @uri_base
43
38
  db0.redis(0).flushdb
@@ -1,12 +1,14 @@
1
- require 'redis/dump'
2
- require 'pry'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/redis/dump'
4
+ # require 'pry-byebug'
3
5
 
4
6
  # The test instance of redis must be running:
5
7
  # $ redis-server try/redis.conf
6
8
 
7
- @uri_base = "redis://127.0.0.1:6371"
9
+ @uri_base = "redis://127.0.0.1:6379"
8
10
 
9
- Redis::Dump.debug = false
11
+ Redis::Dump.debug = true # leave enabled for CI workflow
10
12
  Redis::Dump.safe = true
11
13
  Redis::Dump.with_base64 = true
12
14
 
@@ -21,38 +23,30 @@ Redis::Dump.with_base64 = true
21
23
  @rdump.redis(0).keys.size
22
24
  #=> 2
23
25
 
24
- ## Is base64 encoded
26
+ ## Values are base64 encoded when with_base64=true
25
27
  @values = @rdump.dump
26
- @values[0]
27
- #=> "{\"db\":0,\"key\":\"stringkey1\",\"ttl\":-1,\"type\":\"string\",\"value\":\"c3RyaW5ndmFsdWUx\\n\",\"size\":12}"
28
+ # Check for values without relying on the order the keys were returned in
29
+ encoded_str = "{\"db\":0,\"key\":\"stringkey1\",\"ttl\":-1,\"type\":\"string\",\"value\":\"c3RyaW5ndmFsdWUx\\n\",\"size\":12}"
30
+ encoded_str2 = "{\"db\":0,\"key\":\"stringkey2\",\"ttl\":-1,\"type\":\"string\",\"value\":\"c3RyaW5ndmFsdWUy\\n\",\"size\":12}"
31
+ [@values.include?(encoded_str), @values.include?(encoded_str2)]
32
+ #=> [true, true]
28
33
 
29
34
  ## Can dump
30
35
  @values = @rdump.dump
31
36
  @values.size
32
37
  #=> 2
33
38
 
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
39
  ## Can load data
41
40
  @rdump.load @values.join
42
41
  @rdump.redis(0).keys.size
43
42
  #=> 2
44
43
 
45
- ## Is base64 decoded
46
- stringkey = @rdump.redis(0).get('stringkey1')
47
- #=> 'stringvalue1'
48
-
49
44
  # Clear DB 0
50
45
  db0 = Redis::Dump.new 0, @uri_base
51
46
  db0.redis(0).flushdb
52
47
  db0.redis(0).keys.size
53
- #=> 0
48
+ ##=> 0
54
49
 
55
50
  Redis::Dump.safe = true
56
51
  db0 = Redis::Dump.new 0, @uri_base
57
52
  db0.redis(0).flushdb
58
-
data/try/redis.conf CHANGED
@@ -9,7 +9,7 @@ dbfilename redisdump-test.rdb
9
9
  # requirepass @/
10
10
 
11
11
  bind 127.0.0.1
12
- port 6371
12
+ port 6379
13
13
  databases 16
14
14
 
15
15
  timeout 30
metadata CHANGED
@@ -1,125 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-dump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
- - Delano Mandelbaum
8
- autorequire:
7
+ - delano
8
+ autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZuZXRz
14
- c2gxGTAXBgoJkiaJk/IsZAEZFglzb2x1dGlvdXMxEzARBgoJkiaJk/IsZAEZFgNj
15
- b20wHhcNMTYxMjE1MTgwNTIyWhcNMTcxMjE1MTgwNTIyWjBBMQ8wDQYDVQQDDAZu
16
- ZXRzc2gxGTAXBgoJkiaJk/IsZAEZFglzb2x1dGlvdXMxEzARBgoJkiaJk/IsZAEZ
17
- FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDGJ4TbZ9H+qZ08
18
- pQfJhPJTHaDCyQvCsKTFrL5O9z3tllQ7B/zksMMM+qFBpNYu9HCcg4yBATacE/PB
19
- qVVyUrpr6lbH/XwoN5ljXm+bdCfmnjZvTCL2FTE6o+bcnaF0IsJyC0Q2B1fbWdXN
20
- 6Off1ZWoUk6We2BIM1bn6QJLxBpGyYhvOPXsYoqSuzDf2SJDDsWFZ8kV5ON13Ohm
21
- JbBzn0oD8HF8FuYOewwsC0C1q4w7E5GtvHcQ5juweS7+RKsyDcVcVrLuNzoGRttS
22
- KP4yMn+TzaXijyjRg7gECfJr3TGASaA4bQsILFGG5dAWcwO4OMrZedR7SHj/o0Kf
23
- 3gL7P0axAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
24
- BBQF8qLA7Z4zg0SJGtUbv3eoQ8tjIzAfBgNVHREEGDAWgRRuZXRzc2hAc29sdXRp
25
- b3VzLmNvbTAfBgNVHRIEGDAWgRRuZXRzc2hAc29sdXRpb3VzLmNvbTANBgkqhkiG
26
- 9w0BAQUFAAOCAQEATd8If+Ytmhf5lELy24j76ahGv64m518WTCdV2nIViGXB2BnV
27
- uLQylGRb1rcgUS3Eh9TE28hqrfhotKS6a96qF9kN0mY2H6UwPWswJ+tj3gA1vLW8
28
- wlZNlYGJ91Ig9zULPSbATyOOprUZyggy5p1260BaaI3LQYDeGJOSqpHCVu+TuMcy
29
- k00ofiLT1crDSUl2WE/OIFK8AXpmd798AMsef8okHeoo+Dj7zCXn0VSimN+MO1mE
30
- L4d54WIy4HkZCqQXoTSiK5HZMIdXkPk3F1bZdJ8Dy1sMRru0rUkkM5mW7TQ75mfW
31
- Zp0QrZyNZhtitrXFbZneGRrIA/8G2Krft5Ly/A==
32
- -----END CERTIFICATE-----
33
- date: 2017-11-24 00:00:00.000000000 Z
34
- dependencies:
35
- - !ruby/object:Gem::Dependency
36
- name: yajl-ruby
37
- requirement: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0.1'
42
- type: :runtime
43
- prerelease: false
44
- version_requirements: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0.1'
49
- - !ruby/object:Gem::Dependency
50
- name: redis
51
- requirement: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '4.0'
56
- type: :runtime
57
- prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '4.0'
63
- - !ruby/object:Gem::Dependency
64
- name: uri-redis
65
- requirement: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 0.4.0
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 0.4.0
77
- - !ruby/object:Gem::Dependency
78
- name: drydock
79
- requirement: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: 0.6.9
84
- type: :runtime
85
- prerelease: false
86
- version_requirements: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: 0.6.9
91
- description: Backup and restore your Redis data to and from JSON.
92
- email: delano@solutious.com
93
- executables:
94
- - redis-dump
95
- - redis-load
96
- - redis-report
10
+ cert_chain: []
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Backup and restore your Redis data to and from JSON by database, key,
14
+ or key pattern.
15
+ email: gems@solutious.com
16
+ executables: []
97
17
  extensions: []
98
- extra_rdoc_files:
99
- - LICENSE.txt
100
- - README.rdoc
18
+ extra_rdoc_files: []
101
19
  files:
20
+ - ".pre-commit-config.yaml"
21
+ - ".rubocop.yml"
102
22
  - CHANGES.txt
23
+ - Gemfile
24
+ - Gemfile.lock
103
25
  - LICENSE.txt
104
- - README.rdoc
26
+ - README.md
105
27
  - Rakefile
106
- - VERSION
107
- - bin/redis-dump
108
- - bin/redis-load
109
- - bin/redis-report
28
+ - exe/redis-dump
29
+ - exe/redis-load
30
+ - exe/redis-report
110
31
  - gem-public_cert.pem
111
32
  - lib/redis/dump.rb
33
+ - lib/redis/dump/version.rb
112
34
  - redis-dump.gemspec
35
+ - sig/redis/dump.rbs
113
36
  - try/10_redis_dump_try.rb
114
37
  - try/20_dump_specific_keys_try.rb
115
38
  - try/30_dump_base64_try.rb
116
39
  - try/db0.json
117
40
  - try/redis.conf
118
- homepage: http://github.com/delano/redis-dump
41
+ homepage: https://rubygems.org/gems/redis-dump
119
42
  licenses:
120
43
  - MIT
121
44
  metadata: {}
122
- post_install_message:
45
+ post_install_message:
123
46
  rdoc_options: []
124
47
  require_paths:
125
48
  - lib
@@ -127,16 +50,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
50
  requirements:
128
51
  - - ">="
129
52
  - !ruby/object:Gem::Version
130
- version: '0'
53
+ version: 2.7.8
131
54
  required_rubygems_version: !ruby/object:Gem::Requirement
132
55
  requirements:
133
56
  - - ">="
134
57
  - !ruby/object:Gem::Version
135
58
  version: '0'
136
59
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.5.1
139
- signing_key:
60
+ rubygems_version: 3.5.7
61
+ signing_key:
140
62
  specification_version: 4
141
63
  summary: Backup and restore your Redis data to and from JSON.
142
64
  test_files: []
checksums.yaml.gz.sig DELETED
@@ -1 +0,0 @@
1
- �hY��Y��Ů]t�ۯ�x�r��%&&��y���U�4���ѵ���"��0 ���Y����#��y�~ab��{���I�v%~^�m/�E��Zyz�y&y���� �R�N�x��R"`�K@z�{%M3�c(sh�I��TD� ���'´Nv}k�s>�=C�A��9�kf�^pD�_�l���$�1�C�:�l��K|��ꛥ�1� ��u��܍�ˆ���8�:�����5�y`-c^�},~P�T��T�.�G�A��
data/README.rdoc DELETED
@@ -1,107 +0,0 @@
1
- = Redis-Dump v0.4 BETA
2
-
3
- <i>Backup and restore your Redis data to and from JSON.</i>
4
-
5
- <b>NOTE: This is beta software. TEST IT BEFORE RELYING ON IT.</b>
6
-
7
-
8
- == Usage
9
-
10
- There are two executables: <tt>redis-dump</tt> and <tt>redis-load</tt>.
11
-
12
- $ redis-dump
13
- $ redis-dump -u 127.0.0.1:6371 > db_full.json
14
- $ redis-dump -u 127.0.0.1:6371 -d 15 > db_db15.json
15
-
16
- $ < db_full.json redis-load
17
- $ < db_db15.json redis-load -d 15
18
- # OR
19
- $ cat db_full | redis-load
20
- $ cat db_db15.json | redis-load -d 15
21
-
22
- # You can specify the redis URI via an environment variable
23
- $ export REDIS_URI=127.0.0.1:6371
24
- $ redis-dump
25
-
26
- # If your instance uses a password (such as on RedisToGo), you
27
- # can specify the Redis URL as such:
28
- # :<password>@<domain>:<port>
29
- # Note the leading colon is important for specifying no username.
30
- $ redis-dump -u :234288a830f009980e08@example.redistogo.com:9055
31
-
32
- == Output format
33
-
34
- All redis datatypes are output to a simple JSON object. All objects have the following 5 fields:
35
-
36
- * db (Integer)
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).
41
-
42
- Here are examples of each datatype:
43
-
44
- {"db":0,"key":"hashkey","ttl":-1,"type":"hash","value":{"field_a":"value_a","field_b":"value_b","field_c":"value_c"},"size":42}
45
- {"db":0,"key":"listkey","ttl":-1,"type":"list","value":["value_0","value_1","value_2","value_0","value_1","value_2"],"size":42}
46
- {"db":0,"key":"setkey","ttl":-1,"type":"set","value":["value_2","value_0","value_1","value_3"],"size":28}
47
- {"db":0,"key":"zsetkey","ttl":-1,"type":"zset","value":[["value_0","100"],["value_1","100"],["value_2","200"],["value_3","300"],["value_4","400"]],"size":50}
48
- {"db":0,"key":"stringkey","ttl":79,"type":"string","value":"stringvalue","size":11}
49
-
50
- === Important note about TTLs
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).
53
-
54
-
55
- == Output directly to an encrypted file
56
-
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
-
59
- # Encrypt the data (interactive)
60
- $ redis-dump -u 127.0.0.1:6371 -d 15 | gpg --force-mdc -v -c > path/2/backup-db15.json.gpg
61
-
62
- # Encrypt the data (automated)
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
-
65
- # Decrypt the file (interactive)
66
- $ gpg path/2/backup-db15.json.gpg
67
- Enter passphrase: *******
68
-
69
- # Decrypt the file (automated)
70
- $ 3</path/2/passphrase.txt gpg --passphrase-fd 3 path/2/backup-db15.json.gpg
71
-
72
-
73
- == Loading data with binary strings
74
-
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
-
77
- == Installation
78
-
79
- $ gem install redis-dump
80
-
81
- Or of you want to run it directly:
82
-
83
- $ git clone https://github.com/delano/redis-dump.git
84
- $ cd redis-dump
85
- $ gem install redis
86
- $ gem install uri-redis
87
- $ gem install yajl-ruby
88
- $ gem install drydock
89
- $ ruby -rubygems bin/redis-dump
90
-
91
-
92
- == More Info
93
-
94
- * Codes[http://github.com/delano/redis-dump]
95
- * Docs[http://goldensword.ca/redis-dump/]
96
-
97
-
98
- == Credits
99
-
100
- * delano[http://github.com/delano]
101
-
102
-
103
- == Thanks
104
-
105
- * antirez and the funky redis bunch!
106
-
107
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.4.0
data.tar.gz.sig DELETED
@@ -1,3 +0,0 @@
1
- _���;F���NDC��Q$�=��$[s��Uz��oٻ�
2
- "�Ȁ�.o��V
3
- %���$�
metadata.gz.sig DELETED
Binary file
File without changes
File without changes