redis-dump 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +5 -0
- data/Rakefile +2 -1
- data/VERSION.yml +1 -1
- data/lib/redis/dump.rb +29 -9
- data/try/10_redis_dump_try.rb +3 -0
- data/try/20_dump_specific_keys_try.rb +43 -0
- metadata +21 -4
data/CHANGES.txt
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
REDIS-DUMP, CHANGES
|
2
2
|
|
3
|
+
#### 0.1.3 (2010-11-16) ###############################
|
4
|
+
|
5
|
+
* ADDED: Support for dumping a specific subset of keys
|
6
|
+
* CHANGE: Now dependent on uri-redis 0.4+
|
7
|
+
|
3
8
|
#### 0.1.2 (2010-11-15) ###############################
|
4
9
|
|
5
10
|
* ADDED: redis-report
|
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', '*gemspec' ]
|
15
15
|
name = "redis-dump"
|
16
16
|
|
17
17
|
begin
|
@@ -27,6 +27,7 @@ begin
|
|
27
27
|
gem.authors = ["Delano Mandelbaum"]
|
28
28
|
gem.add_dependency("yajl-ruby", ">= 0.1")
|
29
29
|
gem.add_dependency("redis", ">= 2.0")
|
30
|
+
gem.add_dependency("uri-redis", ">= 0.4.0")
|
30
31
|
end
|
31
32
|
Jeweler::GemcutterTasks.new
|
32
33
|
rescue LoadError
|
data/VERSION.yml
CHANGED
data/lib/redis/dump.rb
CHANGED
@@ -3,6 +3,7 @@ unless defined?(RD_HOME)
|
|
3
3
|
end
|
4
4
|
|
5
5
|
require 'redis'
|
6
|
+
require 'uri/redis'
|
6
7
|
require 'yajl'
|
7
8
|
|
8
9
|
class Redis
|
@@ -43,20 +44,39 @@ class Redis
|
|
43
44
|
self.class.ld 'CONNECT: ' << this_uri
|
44
45
|
Redis.connect :url => this_uri
|
45
46
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
|
48
|
+
# Calls blk for each key. If keys is nil, this will iterate over
|
49
|
+
# every key in every open redis connection.
|
50
|
+
# * keys (Array, optional). If keys is provided it must contain URI::Redis objects.
|
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
|
50
61
|
keys.each do |key|
|
51
|
-
|
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
|
52
70
|
end
|
53
71
|
end
|
54
72
|
end
|
55
|
-
|
73
|
+
|
74
|
+
# See each_key
|
75
|
+
def dump(keys=nil, &each_record)
|
56
76
|
values = []
|
57
|
-
each_key do |this_redis,key|
|
77
|
+
each_key(keys) do |this_redis,key|
|
58
78
|
info = Redis::Dump.dump this_redis, key
|
59
|
-
|
79
|
+
self.class.ld " #{key} (#{info['type']}): #{info['size'].to_bytes}"
|
60
80
|
encoded = self.class.encoder.encode info
|
61
81
|
each_record.nil? ? (values << encoded) : each_record.call(encoded)
|
62
82
|
end
|
@@ -66,7 +86,7 @@ class Redis
|
|
66
86
|
values = []
|
67
87
|
each_key do |this_redis,key|
|
68
88
|
info = Redis::Dump.report this_redis, key
|
69
|
-
|
89
|
+
self.class.ld " #{key} (#{info['type']}): #{info['size'].to_bytes}"
|
70
90
|
each_record.nil? ? (values << info) : each_record.call(info)
|
71
91
|
end
|
72
92
|
values
|
data/try/10_redis_dump_try.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'redis/dump'
|
2
|
+
|
3
|
+
# The test instance of redis must be running:
|
4
|
+
# $ redis-server try/redis-server.conf
|
5
|
+
|
6
|
+
@uri_base = "redis://127.0.0.1:6371"
|
7
|
+
|
8
|
+
Redis::Dump.debug = false
|
9
|
+
Redis::Dump.safe = true
|
10
|
+
|
11
|
+
## Connect to DB
|
12
|
+
@rdump = Redis::Dump.new 0..1, @uri_base
|
13
|
+
@rdump.redis_connections.size
|
14
|
+
#=> 2
|
15
|
+
|
16
|
+
## Populate
|
17
|
+
3.times { |idx| @rdump.redis(0).set "gloria:#{idx}", "gloria_value[#{idx}]" } # yp.ca
|
18
|
+
4.times { |idx| @rdump.redis(0).set "pamela:#{idx}", "pamela_value[#{idx}]" } # soap web service
|
19
|
+
2.times { |idx| @rdump.redis(1).set "nikola:#{idx}", "nikola_value[#{idx}]" } # m.yp.ca log analyzer
|
20
|
+
[@rdump.redis(0).keys.size, @rdump.redis(1).keys.size]
|
21
|
+
#=> [7, 2]
|
22
|
+
|
23
|
+
## Generate a list of keys
|
24
|
+
@keys = @rdump.redis(0).keys('*gloria*').collect { |key| URI.parse "#{@uri_base}/0/#{key}" }
|
25
|
+
@keys.push *@rdump.redis(1).keys('*nikola*').collect { |key| URI.parse "#{@uri_base}/1/#{key}" }
|
26
|
+
@keys.size
|
27
|
+
#=> 5
|
28
|
+
|
29
|
+
## Dump these specific keys
|
30
|
+
@rdump.dump(@keys).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}','{"db":1,"key":"nikola:0","ttl":-1,"type":"string","value":"nikola_value[0]","size":15}', '{"db":1,"key":"nikola:1","ttl":-1,"type":"string","value":"nikola_value[1]","size":15}']
|
32
|
+
|
33
|
+
|
34
|
+
## Dump none existent keys
|
35
|
+
unknown_keys = [URI.parse("#{@uri_base}/0/unknownkey1"), URI.parse("#{@uri_base}/1/unknownkey2")]
|
36
|
+
@rdump.dump(unknown_keys).sort
|
37
|
+
#=> ['{"db":0,"key":"unknownkey1","ttl":-1,"type":"none","value":"","size":0}', '{"db":1,"key":"unknownkey2","ttl":-1,"type":"none","value":"","size":0}']
|
38
|
+
|
39
|
+
|
40
|
+
Redis::Dump.safe = true
|
41
|
+
db0 = Redis::Dump.new 0..1, @uri_base
|
42
|
+
db0.redis(0).flushdb
|
43
|
+
db0.redis(1).flushdb
|
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: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Delano Mandelbaum
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-16 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,6 +48,22 @@ dependencies:
|
|
48
48
|
version: "2.0"
|
49
49
|
type: :runtime
|
50
50
|
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: uri-redis
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 15
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 4
|
63
|
+
- 0
|
64
|
+
version: 0.4.0
|
65
|
+
type: :runtime
|
66
|
+
version_requirements: *id003
|
51
67
|
description: Backup and restore your Redis data to and from JSON.
|
52
68
|
email: delano@solutious.com
|
53
69
|
executables:
|
@@ -70,6 +86,7 @@ files:
|
|
70
86
|
- bin/redis-report
|
71
87
|
- lib/redis/dump.rb
|
72
88
|
- try/10_redis_dump_try.rb
|
89
|
+
- try/20_dump_specific_keys_try.rb
|
73
90
|
- try/db0.json
|
74
91
|
- try/redis-server.conf
|
75
92
|
has_rdoc: true
|