redis-dump 0.1.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +10 -0
- data/README.rdoc +3 -5
- data/Rakefile +1 -19
- data/VERSION.yml +2 -2
- data/bin/redis-dump +16 -2
- data/bin/redis-load +54 -0
- data/bin/redis-report +12 -10
- data/lib/redis/dump.rb +101 -51
- data/redis-dump.gemspec +63 -0
- data/try/20_dump_specific_keys_try.rb +4 -4
- metadata +6 -7
data/CHANGES.txt
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
REDIS-DUMP, CHANGES
|
2
2
|
|
3
|
+
#### 0.3.0 (2012-01-05) ###############################
|
4
|
+
|
5
|
+
* ADDED: Redis::Dump.dump_strings
|
6
|
+
* ADDED: New global options for redis-dump: -c, -O
|
7
|
+
* CHANGED: memory optimizations for Redis::Dump#dump
|
8
|
+
|
9
|
+
#### 0.2.0 (unreleased) ###############################
|
10
|
+
|
11
|
+
* ADDED: Redis::Dump.chunk_size support for dump and report
|
12
|
+
|
3
13
|
#### 0.1.5 (2011-06-04) ###############################
|
4
14
|
|
5
15
|
* FIXED: Added drydock dependency to gemspec [Mike Dupont]
|
data/README.rdoc
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
= Redis-Dump v0.
|
1
|
+
= Redis-Dump v0.3 ALPHA
|
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.
|
6
|
-
|
7
|
-
<b>ALSO: This is an unofficial tool.</b>
|
5
|
+
<b>NOTE: This is alpha software. TEST IT BEFORE RELYING ON IT.</b>
|
8
6
|
|
9
7
|
|
10
8
|
== Usage
|
@@ -24,7 +22,7 @@ All redis datatypes are output to a simple JSON object. All objects have the fol
|
|
24
22
|
|
25
23
|
* db (Integer)
|
26
24
|
* key (String)
|
27
|
-
* ttl (Integer): The amount of time in seconds that the key will live
|
25
|
+
* ttl (Integer): The amount of time in seconds that the key will live. If no expire is set, it's -1.
|
28
26
|
* type (String), one of: string, list, set, zset, hash, none.
|
29
27
|
* value (String): A JSON-encoded string. For keys of type list, set, zset, and hash, the data is given a specific structure (see below).
|
30
28
|
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ end
|
|
11
11
|
|
12
12
|
config = YAML.load_file("VERSION.yml")
|
13
13
|
task :default => ["build"]
|
14
|
-
CLEAN.include [ 'pkg', 'doc'
|
14
|
+
CLEAN.include [ 'pkg', 'doc' ]
|
15
15
|
name = "redis-dump"
|
16
16
|
|
17
17
|
begin
|
@@ -46,21 +46,3 @@ Rake::RDocTask.new do |rdoc|
|
|
46
46
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
# Rubyforge Release / Publish Tasks ==================================
|
51
|
-
|
52
|
-
#about 'Publish website to rubyforge'
|
53
|
-
task 'publish:rdoc' => 'doc/index.html' do
|
54
|
-
sh "scp -rp doc/* rubyforge.org:/var/www/gforge-projects/#{name}/"
|
55
|
-
end
|
56
|
-
|
57
|
-
#about 'Public release to rubyforge'
|
58
|
-
task 'publish:gem' => [:package] do |t|
|
59
|
-
sh <<-end
|
60
|
-
rubyforge add_release -o Any -a CHANGES.txt -f -n README.md #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.gem &&
|
61
|
-
rubyforge add_file -o Any -a CHANGES.txt -f -n README.md #{name} #{name} #{@spec.version} pkg/#{name}-#{@spec.version}.tgz
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
|
data/VERSION.yml
CHANGED
data/bin/redis-dump
CHANGED
@@ -27,6 +27,9 @@ class Redis::Dump::CLI
|
|
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 :s, :sleep, Integer, "Sleep for S seconds after dumping (for debugging)"
|
31
|
+
global :c, :count, Integer, "Chunk size (default: #{Redis::Dump.chunk_size})"
|
32
|
+
global :O, :without_optimizations, "Disable run time optimizations"
|
30
33
|
global :V, :version, "Display version" do
|
31
34
|
puts "Version: #{Redis::Dump::VERSION.to_s}"
|
32
35
|
exit 0
|
@@ -43,15 +46,24 @@ class Redis::Dump::CLI
|
|
43
46
|
obj.global.uri = 'redis://' << obj.global.uri unless obj.global.uri.match(/^redis:\/\//)
|
44
47
|
obj.global.database &&= obj.global.database.to_i
|
45
48
|
obj.global.database ||= (0..15)
|
49
|
+
Redis::Dump.with_optimizations = false if obj.global.without_optimizations
|
50
|
+
Redis::Dump.chunk_size = obj.global.count if obj.global.count
|
46
51
|
Redis::Dump.ld " redis_uri: #{obj.global.uri} (#{obj.global.database})"
|
52
|
+
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
53
|
+
end
|
54
|
+
|
55
|
+
after do |obj|
|
56
|
+
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
57
|
+
sleep obj.global.sleep.to_i if obj.global.sleep
|
47
58
|
end
|
48
59
|
|
49
60
|
usage "redis-dump > dumpfile_full.json"
|
50
61
|
usage "redis-dump -d 15 > dumpfile_db15.json"
|
62
|
+
usage "redis-dump -d 15 -c 100_000 > dumpfile_db15.json"
|
51
63
|
command :dump do |obj|
|
52
64
|
rd = Redis::Dump.new obj.global.database, obj.global.uri
|
53
|
-
rd.dump do |
|
54
|
-
puts
|
65
|
+
rd.dump do |records|
|
66
|
+
puts records
|
55
67
|
end
|
56
68
|
end
|
57
69
|
|
@@ -60,6 +72,8 @@ end
|
|
60
72
|
|
61
73
|
begin
|
62
74
|
Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
|
75
|
+
rescue RuntimeError => ex
|
76
|
+
STDERR.puts ex.message
|
63
77
|
rescue Drydock::ArgError, Drydock::OptError => ex
|
64
78
|
STDERR.puts ex.message
|
65
79
|
STDERR.puts ex.usage
|
data/bin/redis-load
CHANGED
@@ -27,6 +27,7 @@ class Redis::Dump::CLI
|
|
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 :s, :sleep, Integer, "Sleep for S seconds after dumping (for debugging)"
|
30
31
|
global :V, :version, "Display version" do
|
31
32
|
puts "Version: #{Redis::Dump::VERSION.to_s}"
|
32
33
|
exit 0
|
@@ -44,20 +45,73 @@ class Redis::Dump::CLI
|
|
44
45
|
obj.global.database &&= obj.global.database.to_i
|
45
46
|
obj.global.database ||= (0..15)
|
46
47
|
Redis::Dump.ld " redis_uri: #{obj.global.uri} (#{obj.global.database})"
|
48
|
+
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
49
|
+
end
|
50
|
+
|
51
|
+
after do |obj|
|
52
|
+
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
53
|
+
sleep obj.global.sleep.to_i if obj.global.sleep
|
47
54
|
end
|
48
55
|
|
49
56
|
usage "<dumpfile_full.json redis-load"
|
50
57
|
usage "<dumpfile_db15.json redis-load -d 15"
|
51
58
|
command :load do |obj|
|
52
59
|
rd = Redis::Dump.new obj.global.database, obj.global.uri
|
60
|
+
raise "Usage: cat dumpfile_db15.json | redis-load -d 15" if STDIN.tty?
|
53
61
|
rd.load STDIN
|
54
62
|
end
|
55
63
|
|
64
|
+
about "Add test data to redis"
|
65
|
+
usage "redis-load populate -c 1000"
|
66
|
+
usage "redis-load -d 1 populate -c 1000"
|
67
|
+
option :c, :count, Integer, "Populate the redis db with <count> keys"
|
68
|
+
option :FLUSH, "Flush the redis db before populating. THIS WILL DESTROY DATA."
|
69
|
+
command :populate do |obj|
|
70
|
+
require 'benchmark'
|
71
|
+
obj.option.count ||= 100_000
|
72
|
+
obj.global.database ||= 0
|
73
|
+
rd = Redis::Dump.new obj.global.database, obj.global.uri
|
74
|
+
rd.each_database do |redis|
|
75
|
+
now = Time.now.utc.to_i
|
76
|
+
if obj.option.FLUSH
|
77
|
+
puts "Flushing db #{redis.client.id}..."
|
78
|
+
redis.flushdb
|
79
|
+
end
|
80
|
+
puts "Generating..."
|
81
|
+
time = Benchmark.measure do
|
82
|
+
redis.pipelined do
|
83
|
+
obj.option.count.times do |idx|
|
84
|
+
grp = (idx % 10)+1
|
85
|
+
val = '0' * (grp*100).to_i
|
86
|
+
redis.set 'rdtemp:%d:idx-%d:group-%d' % [now, idx, grp], val
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
info = redis.info
|
91
|
+
puts '%s: %s' % [redis.client.id, info["db#{redis.client.db}"]]
|
92
|
+
puts 'Total used memory: %s' % [info['used_memory_human']]
|
93
|
+
puts time.to_s
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
command :info do |obj|
|
98
|
+
rd = Redis::Dump.new obj.global.database, obj.global.uri
|
99
|
+
memory = nil
|
100
|
+
rd.each_database do |redis|
|
101
|
+
info = redis.info
|
102
|
+
memory ||= info['used_memory_human']
|
103
|
+
next unless info["db#{redis.client.db}"]
|
104
|
+
puts '%s: %s' % [redis.client.id, info["db#{redis.client.db}"]]
|
105
|
+
end
|
106
|
+
puts 'Total used memory: %s' % [memory]
|
107
|
+
end
|
56
108
|
end
|
57
109
|
|
58
110
|
|
59
111
|
begin
|
60
112
|
Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
|
113
|
+
rescue RuntimeError => ex
|
114
|
+
STDERR.puts ex.message
|
61
115
|
rescue Drydock::ArgError, Drydock::OptError => ex
|
62
116
|
STDERR.puts ex.message
|
63
117
|
STDERR.puts ex.usage
|
data/bin/redis-report
CHANGED
@@ -27,6 +27,7 @@ class Redis::Dump::CLI
|
|
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 :s, :sleep, Integer, "Sleep for S seconds after dumping (for debugging)"
|
30
31
|
global :v, :verbose, "Increase output" do
|
31
32
|
@verbose ||= 0
|
32
33
|
@verbose += 1
|
@@ -48,21 +49,20 @@ class Redis::Dump::CLI
|
|
48
49
|
obj.global.database &&= obj.global.database.to_i
|
49
50
|
obj.global.database ||= (0..15)
|
50
51
|
Redis::Dump.ld " redis_uri: #{obj.global.uri} (#{obj.global.database})"
|
52
|
+
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
51
53
|
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
+
after do |obj|
|
56
|
+
Redis::Dump.ld "Process: #{$$}; Memory: #{Redis::Dump.memory_usage}" if Redis::Dump.debug
|
57
|
+
sleep obj.global.sleep.to_i if obj.global.sleep
|
58
|
+
end
|
59
|
+
|
60
|
+
usage "redis-report"
|
61
|
+
usage "redis-report -d 15"
|
55
62
|
command :report do |obj|
|
56
63
|
rd = Redis::Dump.new obj.global.database, obj.global.uri
|
57
64
|
total_size, dbs = 0, {}
|
58
|
-
rd.report
|
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}"
|
65
|
+
report = rd.report
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
@@ -70,6 +70,8 @@ end
|
|
70
70
|
|
71
71
|
begin
|
72
72
|
Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run?
|
73
|
+
rescue RuntimeError => ex
|
74
|
+
STDERR.puts ex.message
|
73
75
|
rescue Drydock::ArgError, Drydock::OptError => ex
|
74
76
|
STDERR.puts ex.message
|
75
77
|
STDERR.puts ex.usage
|
data/lib/redis/dump.rb
CHANGED
@@ -17,10 +17,15 @@ class Redis
|
|
17
17
|
@encoder = Yajl::Encoder.new
|
18
18
|
@parser = Yajl::Parser.new
|
19
19
|
@safe = true
|
20
|
+
@chunk_size = 10000
|
21
|
+
@with_optimizations = true
|
20
22
|
class << self
|
21
|
-
attr_accessor :debug, :encoder, :parser, :safe, :host, :port
|
23
|
+
attr_accessor :debug, :encoder, :parser, :safe, :host, :port, :chunk_size, :with_optimizations
|
22
24
|
def ld(msg)
|
23
|
-
STDERR.puts "
|
25
|
+
STDERR.puts "#%.4f: %s" % [Time.now.utc.to_f, msg] if debug
|
26
|
+
end
|
27
|
+
def memory_usage
|
28
|
+
`ps -o rss= -p #{Process.pid}`.to_i # in kb
|
24
29
|
end
|
25
30
|
end
|
26
31
|
attr_accessor :dbs, :uri
|
@@ -31,66 +36,99 @@ class Redis
|
|
31
36
|
unless dbs.nil?
|
32
37
|
@dbs = Range === dbs ? dbs : (dbs..dbs)
|
33
38
|
@dbs = (@dbs.first.to_i..@dbs.last.to_i) # enforce integers
|
34
|
-
open_all_connections
|
39
|
+
@dbs.to_a.each { |db| redis(db) } # open_all_connections
|
35
40
|
end
|
36
41
|
end
|
37
|
-
def open_all_connections
|
38
|
-
dbs.to_a.each { |db| redis(db) } unless dbs.nil?
|
39
|
-
end
|
40
42
|
def redis(db)
|
41
43
|
redis_connections["#{uri}/#{db}"] ||= connect("#{uri}/#{db}")
|
42
44
|
end
|
43
45
|
def connect(this_uri)
|
44
|
-
self.class.ld 'CONNECT: ' << this_uri
|
46
|
+
#self.class.ld 'CONNECT: ' << this_uri
|
45
47
|
Redis.connect :url => this_uri
|
46
48
|
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
def each_key(keys=nil, &blk)
|
52
|
-
if keys.nil?
|
53
|
-
@redis_connections.keys.sort.each do |redis_uri|
|
54
|
-
self.class.ld ['---', "DB: #{redis_connections[redis_uri].client.db}", '---'].join($/)
|
55
|
-
keys = redis_connections[redis_uri].keys
|
56
|
-
keys.each do |key|
|
57
|
-
blk.call redis_connections[redis_uri], key
|
58
|
-
end
|
59
|
-
end
|
60
|
-
else
|
61
|
-
keys.each do |key|
|
62
|
-
unless URI::Redis === key
|
63
|
-
raise Redis::Dump::Problem, "#{key} must be a URI::Redis object"
|
64
|
-
end
|
65
|
-
redis_uri = key.serverid
|
66
|
-
if redis_connections[redis_uri].nil?
|
67
|
-
raise Redis::Dump::Problem, "Not connected to #{redis_uri}"
|
68
|
-
end
|
69
|
-
blk.call redis_connections[redis_uri], key.key
|
70
|
-
end
|
50
|
+
def each_database
|
51
|
+
@redis_connections.keys.sort.each do |redis_uri|
|
52
|
+
yield redis_connections[redis_uri]
|
71
53
|
end
|
72
54
|
end
|
73
55
|
|
74
56
|
# See each_key
|
75
|
-
def dump
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
57
|
+
def dump filter='*'
|
58
|
+
entries = []
|
59
|
+
each_database do |redis|
|
60
|
+
chunk_entries = []
|
61
|
+
dump_keys = redis.keys(filter)
|
62
|
+
dump_keys_size = dump_keys.size
|
63
|
+
Redis::Dump.ld "Memory after loading keys: #{Redis::Dump.memory_usage}kb"
|
64
|
+
dump_keys.each_with_index do |key,idx|
|
65
|
+
entry, idxplus = key, idx+1
|
66
|
+
#self.class.ld " #{key} (#{key_dump['type']}): #{key_dump['size'].to_bytes}"
|
67
|
+
#entry_enc = self.class.encoder.encode entry
|
68
|
+
if block_given?
|
69
|
+
chunk_entries << entry
|
70
|
+
process_chunk idx, dump_keys_size do |count|
|
71
|
+
Redis::Dump.ld " dumping #{chunk_entries.size} (#{count}) from #{redis.client.id}"
|
72
|
+
output_buffer = []
|
73
|
+
chunk_entries.select! do |key|
|
74
|
+
type = Redis::Dump.type(redis, key)
|
75
|
+
if self.class.with_optimizations && type == 'string'
|
76
|
+
true
|
77
|
+
else
|
78
|
+
output_buffer.push self.class.encoder.encode(Redis::Dump.dump(redis, key, type))
|
79
|
+
false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
unless output_buffer.empty?
|
83
|
+
yield output_buffer
|
84
|
+
end
|
85
|
+
unless chunk_entries.empty?
|
86
|
+
yield Redis::Dump.dump_strings(redis, chunk_entries) { |obj| self.class.encoder.encode(obj) }
|
87
|
+
end
|
88
|
+
output_buffer.clear
|
89
|
+
chunk_entries.clear
|
90
|
+
end
|
91
|
+
else
|
92
|
+
entries << self.class.encoder.encode(Redis::Dump.dump(redis, entry))
|
93
|
+
end
|
94
|
+
end
|
82
95
|
end
|
83
|
-
|
96
|
+
entries
|
84
97
|
end
|
85
|
-
|
98
|
+
|
99
|
+
def process_chunk idx, total_size
|
100
|
+
idxplus = idx+1
|
101
|
+
yield idxplus if (idxplus % self.class.chunk_size).zero? || idxplus >= total_size
|
102
|
+
end
|
103
|
+
private :process_chunk
|
104
|
+
|
105
|
+
def report filter='*'
|
86
106
|
values = []
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
107
|
+
total_size, dbs = 0, {}
|
108
|
+
each_database do |redis|
|
109
|
+
chunk_entries = []
|
110
|
+
dump_keys = redis.keys(filter)
|
111
|
+
dump_keys_size = dump_keys.size
|
112
|
+
dump_keys.each_with_index do |key,idx|
|
113
|
+
entry, idxplus = Redis::Dump.report(redis, key), idx+1
|
114
|
+
chunk_entries << entry
|
115
|
+
process_chunk idx, dump_keys_size do |count|
|
116
|
+
Redis::Dump.ld " reporting on #{chunk_entries.size} (#{idxplus}) from #{redis.client.id}"
|
117
|
+
chunk_entries.each do |e|
|
118
|
+
#puts record if obj.global.verbose >= 1
|
119
|
+
dbs[e['db']] ||= 0
|
120
|
+
dbs[e['db']] += e['size']
|
121
|
+
total_size += e['size']
|
122
|
+
end
|
123
|
+
chunk_entries.clear
|
124
|
+
end
|
125
|
+
end
|
91
126
|
end
|
127
|
+
puts dbs.keys.sort.collect { |db| " db#{db}: #{dbs[db].to_bytes}" }
|
128
|
+
puts "total: #{total_size.to_bytes}"
|
92
129
|
values
|
93
130
|
end
|
131
|
+
|
94
132
|
def load(string_or_stream, &each_record)
|
95
133
|
count = 0
|
96
134
|
Redis::Dump.ld " LOAD SOURCE: #{string_or_stream}"
|
@@ -100,10 +138,10 @@ class Redis
|
|
100
138
|
next
|
101
139
|
end
|
102
140
|
this_redis = redis(obj["db"])
|
103
|
-
Redis::Dump.ld "load[#{this_redis.hash}, #{obj}]"
|
141
|
+
#Redis::Dump.ld "load[#{this_redis.hash}, #{obj}]"
|
104
142
|
if each_record.nil?
|
105
143
|
if Redis::Dump.safe && this_redis.exists(obj['key'])
|
106
|
-
Redis::Dump.ld " record exists (no change)"
|
144
|
+
#Redis::Dump.ld " record exists (no change)"
|
107
145
|
next
|
108
146
|
end
|
109
147
|
Redis::Dump.set_value this_redis, obj['key'], obj['type'], obj['value'], obj['ttl']
|
@@ -125,29 +163,41 @@ class Redis
|
|
125
163
|
info['type'] = type(this_redis, key)
|
126
164
|
info['size'] = stringify(this_redis, key, info['type'], info['value']).size
|
127
165
|
info['bytes'] = info['size'].to_bytes
|
128
|
-
ld "report[#{this_redis.hash}, #{info}]"
|
166
|
+
#ld "report[#{this_redis.hash}, #{info}]"
|
129
167
|
info
|
130
168
|
end
|
131
|
-
def dump(this_redis, key)
|
169
|
+
def dump(this_redis, key, type=nil)
|
170
|
+
type ||= type(this_redis, key)
|
132
171
|
info = { 'db' => this_redis.client.db, 'key' => key }
|
133
172
|
info['ttl'] = this_redis.ttl key
|
134
|
-
info['type'] = type
|
173
|
+
info['type'] = type
|
135
174
|
info['value'] = value(this_redis, key, info['type'])
|
136
175
|
info['size'] = stringify(this_redis, key, info['type'], info['value']).size
|
137
|
-
ld "dump[#{this_redis.hash}, #{info}]"
|
176
|
+
#ld "dump[#{this_redis.hash}, #{info}]"
|
138
177
|
info
|
139
178
|
end
|
179
|
+
def dump_strings(this_redis, keys)
|
180
|
+
vals = this_redis.mget *keys
|
181
|
+
idx = -1
|
182
|
+
keys.collect { |key|
|
183
|
+
idx += 1
|
184
|
+
info = {
|
185
|
+
'db' => this_redis.client.db, 'key' => key,
|
186
|
+
'ttl' => this_redis.ttl(key), 'type' => 'string',
|
187
|
+
'value' => vals[idx].to_s, 'size' => vals[idx].to_s.size
|
188
|
+
}
|
189
|
+
block_given? ? yield(info) : info
|
190
|
+
}
|
191
|
+
end
|
140
192
|
def set_value(this_redis, key, type, value, expire=nil)
|
141
193
|
t ||= type
|
142
194
|
send("set_value_#{t}", this_redis, key, value)
|
143
195
|
this_redis.expire key, expire if expire.to_s.to_i > 0
|
144
196
|
end
|
145
197
|
def value(this_redis, key, t=nil)
|
146
|
-
t ||= type
|
147
198
|
send("value_#{t}", this_redis, key)
|
148
199
|
end
|
149
200
|
def stringify(this_redis, key, t=nil, v=nil)
|
150
|
-
t ||= type
|
151
201
|
send("stringify_#{t}", this_redis, key, v)
|
152
202
|
end
|
153
203
|
|
data/redis-dump.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "redis-dump"
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Delano Mandelbaum"]
|
12
|
+
s.date = "2012-01-05"
|
13
|
+
s.description = "Backup and restore your Redis data to and from JSON."
|
14
|
+
s.email = "delano@solutious.com"
|
15
|
+
s.executables = ["redis-dump", "redis-load", "redis-report"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
"CHANGES.txt",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION.yml",
|
26
|
+
"bin/redis-dump",
|
27
|
+
"bin/redis-load",
|
28
|
+
"bin/redis-report",
|
29
|
+
"lib/redis/dump.rb",
|
30
|
+
"redis-dump.gemspec",
|
31
|
+
"try/10_redis_dump_try.rb",
|
32
|
+
"try/20_dump_specific_keys_try.rb",
|
33
|
+
"try/db0.json",
|
34
|
+
"try/redis-server.conf"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/delano/redis-dump"
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubyforge_project = "redis-dump"
|
39
|
+
s.rubygems_version = "1.8.10"
|
40
|
+
s.summary = "Backup and restore your Redis data to and from JSON."
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<yajl-ruby>, [">= 0.1"])
|
47
|
+
s.add_runtime_dependency(%q<redis>, [">= 2.0"])
|
48
|
+
s.add_runtime_dependency(%q<uri-redis>, [">= 0.4.0"])
|
49
|
+
s.add_runtime_dependency(%q<drydock>, [">= 0.6.9"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0.1"])
|
52
|
+
s.add_dependency(%q<redis>, [">= 2.0"])
|
53
|
+
s.add_dependency(%q<uri-redis>, [">= 0.4.0"])
|
54
|
+
s.add_dependency(%q<drydock>, [">= 0.6.9"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0.1"])
|
58
|
+
s.add_dependency(%q<redis>, [">= 2.0"])
|
59
|
+
s.add_dependency(%q<uri-redis>, [">= 0.4.0"])
|
60
|
+
s.add_dependency(%q<drydock>, [">= 0.6.9"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -27,14 +27,14 @@ Redis::Dump.safe = true
|
|
27
27
|
#=> 5
|
28
28
|
|
29
29
|
## Dump these specific keys
|
30
|
-
@rdump.dump(
|
31
|
-
#=> ['{"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}'
|
30
|
+
@rdump.dump('*gloria*').sort
|
31
|
+
#=> ['{"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}']
|
32
32
|
|
33
33
|
|
34
|
-
## Dump none existent keys
|
34
|
+
## Dump none existent keys (NOT SUPPORTED AS OF 0.3.0)
|
35
35
|
unknown_keys = [URI.parse("#{@uri_base}/0/unknownkey1"), URI.parse("#{@uri_base}/1/unknownkey2")]
|
36
36
|
@rdump.dump(unknown_keys).sort
|
37
|
-
|
37
|
+
##=> ['{"db":0,"key":"unknownkey1","ttl":-1,"type":"none","value":"","size":0}', '{"db":1,"key":"unknownkey2","ttl":-1,"type":"none","value":"","size":0}']
|
38
38
|
|
39
39
|
|
40
40
|
Redis::Dump.safe = true
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: redis-dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Delano Mandelbaum
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
14
|
-
default_executable:
|
13
|
+
date: 2012-01-05 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: yajl-ruby
|
@@ -78,17 +77,17 @@ files:
|
|
78
77
|
- bin/redis-load
|
79
78
|
- bin/redis-report
|
80
79
|
- lib/redis/dump.rb
|
80
|
+
- redis-dump.gemspec
|
81
81
|
- try/10_redis_dump_try.rb
|
82
82
|
- try/20_dump_specific_keys_try.rb
|
83
83
|
- try/db0.json
|
84
84
|
- try/redis-server.conf
|
85
|
-
has_rdoc: true
|
86
85
|
homepage: http://github.com/delano/redis-dump
|
87
86
|
licenses: []
|
88
87
|
|
89
88
|
post_install_message:
|
90
|
-
rdoc_options:
|
91
|
-
|
89
|
+
rdoc_options: []
|
90
|
+
|
92
91
|
require_paths:
|
93
92
|
- lib
|
94
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -106,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
105
|
requirements: []
|
107
106
|
|
108
107
|
rubyforge_project: redis-dump
|
109
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 1.8.10
|
110
109
|
signing_key:
|
111
110
|
specification_version: 3
|
112
111
|
summary: Backup and restore your Redis data to and from JSON.
|