redis-dump 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.txt +4 -0
- data/README.rdoc +5 -2
- data/VERSION.yml +1 -1
- data/bin/redis-load +1 -1
- data/bin/redis-report +86 -0
- data/lib/redis/dump.rb +11 -13
- metadata +5 -3
data/CHANGES.txt
CHANGED
data/README.rdoc
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
<b>NOTE: This is alpha software. DO NOT RELY ON IT FOR PRECIOUS THINGS!!</b>
|
6
6
|
|
7
|
+
<b>ALSO: This is an unofficial tool.</b>
|
8
|
+
|
7
9
|
|
8
10
|
== Usage
|
9
11
|
|
@@ -31,12 +33,12 @@ Here are examples of each datatype:
|
|
31
33
|
{"db":0,"key":"hashkey","ttl":-1,"type":"hash","value":{"field_a":"value_a","field_b":"value_b","field_c":"value_c"},"size":42}
|
32
34
|
{"db":0,"key":"listkey","ttl":-1,"type":"list","value":["value_0","value_1","value_2","value_0","value_1","value_2"],"size":42}
|
33
35
|
{"db":0,"key":"setkey","ttl":-1,"type":"set","value":["value_2","value_0","value_1","value_3"],"size":28}
|
34
|
-
|
36
|
+
{"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}
|
35
37
|
{"db":0,"key":"stringkey","ttl":79,"type":"string","value":"stringvalue","size":11}
|
36
38
|
|
37
39
|
=== Important note about TTLs
|
38
40
|
|
39
|
-
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>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).
|
41
|
+
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).
|
40
42
|
|
41
43
|
|
42
44
|
== Installation
|
@@ -49,6 +51,7 @@ One of:
|
|
49
51
|
== More Info
|
50
52
|
|
51
53
|
* Codes[http://github.com/delano/redis-dump]
|
54
|
+
* Docs[http://goldensword.ca/redis-dump/]
|
52
55
|
|
53
56
|
|
54
57
|
== Credits
|
data/VERSION.yml
CHANGED
data/bin/redis-load
CHANGED
@@ -37,7 +37,7 @@ class Redis::Dump::CLI
|
|
37
37
|
global :nosafe do
|
38
38
|
Redis::Dump.safe = false
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
before do |obj|
|
42
42
|
obj.global.uri ||= 'redis://%s:%s' % [Redis::Dump.host, Redis::Dump.port]
|
43
43
|
obj.global.uri = 'redis://' << obj.global.uri unless obj.global.uri.match(/^redis:\/\//)
|
data/bin/redis-report
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# = Redis-Dump
|
4
|
+
#
|
5
|
+
#
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# $ redis-report -h
|
9
|
+
# $ redis-report
|
10
|
+
# $ redis-report -d 15
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
|
14
|
+
RD_HOME = File.expand_path File.join(File.dirname(__FILE__), '..')
|
15
|
+
lib_dir = File.join(RD_HOME, 'lib')
|
16
|
+
$:.unshift lib_dir
|
17
|
+
|
18
|
+
require 'redis/dump'
|
19
|
+
require 'drydock'
|
20
|
+
|
21
|
+
# Command-line interface for bin/redis-dump
|
22
|
+
class Redis::Dump::CLI
|
23
|
+
extend Drydock
|
24
|
+
|
25
|
+
default :report
|
26
|
+
trawler :report
|
27
|
+
|
28
|
+
global :u, :uri, String, "Redis URI (e.g. redis://hostname[:port])"
|
29
|
+
global :d, :database, Integer, "Redis database (e.g. -d 15)"
|
30
|
+
global :v, :verbose, "Increase output" do
|
31
|
+
@verbose ||= 0
|
32
|
+
@verbose += 1
|
33
|
+
end
|
34
|
+
global :V, :version, "Display version" do
|
35
|
+
puts "Version: #{Redis::Dump::VERSION.to_s}"
|
36
|
+
exit 0
|
37
|
+
end
|
38
|
+
global :D, :debug do
|
39
|
+
Redis::Dump.debug = true
|
40
|
+
end
|
41
|
+
global :nosafe do
|
42
|
+
Redis::Dump.safe = false
|
43
|
+
end
|
44
|
+
|
45
|
+
before do |obj|
|
46
|
+
obj.global.uri ||= 'redis://%s:%s' % [Redis::Dump.host, Redis::Dump.port]
|
47
|
+
obj.global.uri = 'redis://' << obj.global.uri unless obj.global.uri.match(/^redis:\/\//)
|
48
|
+
obj.global.database &&= obj.global.database.to_i
|
49
|
+
obj.global.database ||= (0..15)
|
50
|
+
Redis::Dump.ld " redis_uri: #{obj.global.uri} (#{obj.global.database})"
|
51
|
+
end
|
52
|
+
|
53
|
+
usage "<dumpfile_full.json redis-load"
|
54
|
+
usage "<dumpfile_db15.json redis-load -d 15"
|
55
|
+
command :report do |obj|
|
56
|
+
rd = Redis::Dump.new obj.global.database, obj.global.uri
|
57
|
+
total_size, dbs = 0, {}
|
58
|
+
rd.report do |record|
|
59
|
+
puts record if obj.global.verbose >= 1
|
60
|
+
dbs[record['db']] ||= 0
|
61
|
+
dbs[record['db']] += record['size']
|
62
|
+
total_size += record['size']
|
63
|
+
end
|
64
|
+
puts dbs.keys.sort.collect { |db| " db#{db}: #{dbs[db].to_bytes}" }
|
65
|
+
puts "total: #{total_size.to_bytes}"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
begin
|
72
|
+
Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
|
73
|
+
rescue Drydock::ArgError, Drydock::OptError => ex
|
74
|
+
STDERR.puts ex.message
|
75
|
+
STDERR.puts ex.usage
|
76
|
+
rescue Drydock::InvalidArgument => ex
|
77
|
+
STDERR.puts ex.message
|
78
|
+
rescue Drydock::UnknownCommand => ex
|
79
|
+
STDERR.puts "Unknown command: %s" % ex.name
|
80
|
+
rescue Interrupt
|
81
|
+
puts $/, "Exiting... "
|
82
|
+
exit 1
|
83
|
+
rescue => ex
|
84
|
+
STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
|
85
|
+
STDERR.puts ex.backtrace if Redis::Dump.debug
|
86
|
+
end
|
data/lib/redis/dump.rb
CHANGED
@@ -147,20 +147,18 @@ class Redis
|
|
147
147
|
this_redis.set key, str
|
148
148
|
end
|
149
149
|
|
150
|
-
def value_string(this_redis, key) this_redis.get key
|
151
|
-
def value_list (this_redis, key) this_redis.lrange key, 0, -1
|
152
|
-
def value_set (this_redis, key) this_redis.smembers key
|
153
|
-
def value_zset (this_redis, key)
|
154
|
-
|
155
|
-
end
|
156
|
-
def
|
157
|
-
def
|
158
|
-
def
|
159
|
-
def
|
160
|
-
def stringify_set (this_redis, key, v=nil) (v || value_set(this_redis, key)).join end
|
161
|
-
def stringify_zset (this_redis, key, v=nil) (v || value_zset(this_redis, key)).flatten.compact.join end
|
150
|
+
def value_string(this_redis, key) this_redis.get key end
|
151
|
+
def value_list (this_redis, key) this_redis.lrange key, 0, -1 end
|
152
|
+
def value_set (this_redis, key) this_redis.smembers key end
|
153
|
+
def value_zset (this_redis, key) this_redis.zrange(key, 0, -1, :with_scores => true).tuple end
|
154
|
+
def value_hash (this_redis, key) this_redis.hgetall(key) end
|
155
|
+
def value_none (this_redis, key) '' end
|
156
|
+
def stringify_string(this_redis, key, v=nil) (v || value_string(this_redis, key)) end
|
157
|
+
def stringify_list (this_redis, key, v=nil) (v || value_list(this_redis, key)).join end
|
158
|
+
def stringify_set (this_redis, key, v=nil) (v || value_set(this_redis, key)).join end
|
159
|
+
def stringify_zset (this_redis, key, v=nil) (v || value_zset(this_redis, key)).flatten.compact.join end
|
162
160
|
def stringify_hash (this_redis, key, v=nil) (v || value_hash(this_redis, key)).to_a.flatten.compact.join end
|
163
|
-
def stringify_none (this_redis, key, v=nil) (v || '')
|
161
|
+
def stringify_none (this_redis, key, v=nil) (v || '') end
|
164
162
|
end
|
165
163
|
extend Redis::Dump::ClassMethods
|
166
164
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Delano Mandelbaum
|
@@ -53,6 +53,7 @@ email: delano@solutious.com
|
|
53
53
|
executables:
|
54
54
|
- redis-dump
|
55
55
|
- redis-load
|
56
|
+
- redis-report
|
56
57
|
extensions: []
|
57
58
|
|
58
59
|
extra_rdoc_files:
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
- VERSION.yml
|
67
68
|
- bin/redis-dump
|
68
69
|
- bin/redis-load
|
70
|
+
- bin/redis-report
|
69
71
|
- lib/redis/dump.rb
|
70
72
|
- try/10_redis_dump_try.rb
|
71
73
|
- try/db0.json
|