redis-store 1.0.0.1 → 1.1.0.rc

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of redis-store might be problematic. Click here for more details.

Files changed (53) hide show
  1. data/Gemfile +2 -34
  2. data/README.md +17 -220
  3. data/Rakefile +7 -54
  4. data/lib/redis-store.rb +11 -44
  5. data/lib/redis/distributed_store.rb +8 -1
  6. data/lib/redis/factory.rb +17 -21
  7. data/lib/redis/store.rb +3 -8
  8. data/lib/redis/store/interface.rb +4 -0
  9. data/lib/redis/store/marshalling.rb +4 -0
  10. data/lib/redis/store/version.rb +1 -8
  11. data/lib/tasks/redis.tasks.rb +167 -0
  12. data/redis-store.gemspec +22 -97
  13. data/{spec → test}/config/node-one.conf +2 -2
  14. data/{spec → test}/config/node-two.conf +2 -2
  15. data/{spec → test}/config/redis.conf +3 -2
  16. data/{spec/redis/distributed_store_spec.rb → test/redis/distributed_store_test.rb} +13 -15
  17. data/test/redis/factory_test.rb +98 -0
  18. data/test/redis/store/interface_test.rb +27 -0
  19. data/test/redis/store/marshalling_test.rb +127 -0
  20. data/test/redis/store/namespace_test.rb +86 -0
  21. data/test/redis/store/version_test.rb +7 -0
  22. data/test/redis/store_test.rb +17 -0
  23. data/test/test_helper.rb +22 -0
  24. metadata +85 -97
  25. data/.travis.yml +0 -7
  26. data/CHANGELOG +0 -311
  27. data/VERSION +0 -1
  28. data/lib/action_controller/session/redis_session_store.rb +0 -81
  29. data/lib/active_support/cache/redis_store.rb +0 -254
  30. data/lib/cache/merb/redis_store.rb +0 -79
  31. data/lib/cache/sinatra/redis_store.rb +0 -131
  32. data/lib/i18n/backend/redis.rb +0 -67
  33. data/lib/rack/cache/redis_entitystore.rb +0 -48
  34. data/lib/rack/cache/redis_metastore.rb +0 -40
  35. data/lib/rack/session/merb.rb +0 -32
  36. data/lib/rack/session/redis.rb +0 -88
  37. data/spec/action_controller/session/redis_session_store_spec.rb +0 -126
  38. data/spec/active_support/cache/redis_store_spec.rb +0 -426
  39. data/spec/cache/merb/redis_store_spec.rb +0 -143
  40. data/spec/cache/sinatra/redis_store_spec.rb +0 -192
  41. data/spec/i18n/backend/redis_spec.rb +0 -72
  42. data/spec/rack/cache/entitystore/pony.jpg +0 -0
  43. data/spec/rack/cache/entitystore/redis_spec.rb +0 -124
  44. data/spec/rack/cache/metastore/redis_spec.rb +0 -259
  45. data/spec/rack/session/redis_spec.rb +0 -234
  46. data/spec/redis/factory_spec.rb +0 -110
  47. data/spec/redis/store/interface_spec.rb +0 -23
  48. data/spec/redis/store/marshalling_spec.rb +0 -119
  49. data/spec/redis/store/namespace_spec.rb +0 -76
  50. data/spec/redis/store/version_spec.rb +0 -7
  51. data/spec/redis/store_spec.rb +0 -13
  52. data/spec/spec_helper.rb +0 -43
  53. data/tasks/redis.tasks.rb +0 -235
@@ -1,143 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Merb
4
- module Cache
5
- describe "Merb::Cache::RedisStore" do
6
- before(:each) do
7
- @store = Merb::Cache::RedisStore.new
8
- @dstore = Merb::Cache::RedisStore.new :servers => ["redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"]
9
- @rabbit = OpenStruct.new :name => "bunny"
10
- @white_rabbit = OpenStruct.new :color => "white"
11
- with_store_management do |store|
12
- store.write "rabbit", @rabbit
13
- store.delete "rub-a-dub"
14
- end
15
- end
16
-
17
- it "should accept connection params" do
18
- redis = instantiate_store
19
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
20
-
21
- redis = instantiate_store "redis://127.0.0.1"
22
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
23
-
24
- redis = instantiate_store "redis://127.0.0.1:6380"
25
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 0"
26
-
27
- redis = instantiate_store "redis://127.0.0.1:6380/13"
28
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 13"
29
-
30
- redis = instantiate_store "redis://127.0.0.1:6380/13/theplaylist"
31
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 13 with namespace theplaylist"
32
- end
33
-
34
- it "should instantiate a ring" do
35
- store = instantiate_store
36
- store.should be_kind_of(Redis::Store)
37
- store = instantiate_store ["redis://127.0.0.1:6379/0", "redis://127.0.0.1:6379/1"]
38
- store.should be_kind_of(Redis::DistributedStore)
39
- end
40
-
41
- it "should verify if writable" do
42
- with_store_management do |store|
43
- store.writable?("rabbit").should be_true
44
- end
45
- end
46
-
47
- it "should read the data" do
48
- with_store_management do |store|
49
- store.read("rabbit").should === @rabbit
50
- end
51
- end
52
-
53
- it "should read raw data" do
54
- with_store_management do |store|
55
- store.read("rabbit", {}, :raw => true).should == Marshal.dump(@rabbit)
56
- end
57
- end
58
-
59
- it "should write the data" do
60
- with_store_management do |store|
61
- store.write "rabbit", @white_rabbit
62
- store.read("rabbit").should === @white_rabbit
63
- end
64
- end
65
-
66
- it "should write raw data" do
67
- with_store_management do |store|
68
- store.write "rabbit", @white_rabbit, {}, :raw => true
69
- store.read("rabbit", {}, :raw => true).should == %(#<OpenStruct color="white">)
70
- end
71
- end
72
-
73
- it "should write the data with expiration time" do
74
- with_store_management do |store|
75
- store.write "rabbit", @white_rabbit, {}, :expires_in => 1.second
76
- store.read("rabbit").should === @white_rabbit ; sleep 2
77
- store.read("rabbit").should be_nil
78
- end
79
- end
80
-
81
- it "should not write data if :unless_exist option is true" do
82
- with_store_management do |store|
83
- store.write "rabbit", @white_rabbit, {}, :unless_exist => true
84
- store.read("rabbit").should === @rabbit
85
- end
86
- end
87
-
88
- it "should write all the data" do
89
- with_store_management do |store|
90
- store.write_all "rabbit", @white_rabbit
91
- store.read("rabbit").should === @white_rabbit
92
- end
93
- end
94
-
95
- it "should fetch data" do
96
- with_store_management do |store|
97
- store.fetch("rabbit").should == @rabbit
98
- store.fetch("rub-a-dub").should be_nil
99
- store.fetch("rub-a-dub") { "Flora de Cana" }.should == "Flora de Cana"
100
- store.fetch("rub-a-dub").should === "Flora de Cana"
101
- end
102
- end
103
-
104
- it "should verify existence" do
105
- with_store_management do |store|
106
- store.exists?("rabbit").should be_true
107
- store.exists?("rab-a-dub").should be_false
108
- end
109
- end
110
-
111
- it "should delete data" do
112
- with_store_management do |store|
113
- store.delete "rabbit"
114
- store.read("rabbit").should be_nil
115
- end
116
- end
117
-
118
- it "should delete all the data" do
119
- with_store_management do |store|
120
- store.delete_all
121
- store.instance_variable_get(:@data).keys("*").flatten.should be_empty
122
- end
123
- end
124
-
125
- it "should delete all the data with bang method" do
126
- with_store_management do |store|
127
- store.delete_all!
128
- store.instance_variable_get(:@data).keys("*").flatten.should be_empty
129
- end
130
- end
131
-
132
- private
133
- def instantiate_store(addresses = nil)
134
- Merb::Cache::RedisStore.new(:servers => [addresses].flatten).instance_variable_get(:@data)
135
- end
136
-
137
- def with_store_management
138
- yield @store
139
- yield @dstore
140
- end
141
- end
142
- end
143
- end
@@ -1,192 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class App
4
- def initialize
5
- @values = {}
6
- end
7
-
8
- def set(key, value)
9
- @values[key] = value
10
- end
11
-
12
- def get(key)
13
- @values[key]
14
- end
15
- end
16
-
17
- module Sinatra
18
- module Cache
19
- describe "Sinatra::Cache::RedisStore" do
20
- before(:each) do
21
- @store = Sinatra::Cache::RedisStore.new
22
- @dstore = Sinatra::Cache::RedisStore.new "redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"
23
- @rabbit = OpenStruct.new :name => "bunny"
24
- @white_rabbit = OpenStruct.new :color => "white"
25
- with_store_management do |store|
26
- store.write "rabbit", @rabbit
27
- store.delete "counter"
28
- store.delete "rub-a-dub"
29
- end
30
- end
31
-
32
- it "should register as extension" do
33
- app = App.new
34
- Sinatra::Cache.register(app)
35
- store = app.get(:cache)
36
- store.should be_kind_of(RedisStore)
37
- end
38
-
39
- it "should accept connection params" do
40
- redis = instantiate_store
41
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
42
-
43
- redis = instantiate_store "redis://127.0.0.1"
44
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
45
-
46
- redis = instantiate_store "redis://127.0.0.1:6380"
47
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 0"
48
-
49
- redis = instantiate_store "redis://127.0.0.1:6380/13"
50
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 13"
51
-
52
- redis = instantiate_store "redis://127.0.0.1:6380/13/theplaylist"
53
- redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 13 with namespace theplaylist"
54
- end
55
-
56
- it "should instantiate a ring" do
57
- store = instantiate_store
58
- store.should be_kind_of(Redis::Store)
59
- store = instantiate_store ["redis://127.0.0.1:6379/0", "redis://127.0.0.1:6379/1"]
60
- store.should be_kind_of(Redis::DistributedStore)
61
- end
62
-
63
- it "should read the data" do
64
- with_store_management do |store|
65
- store.read("rabbit").should === @rabbit
66
- end
67
- end
68
-
69
- it "should write the data" do
70
- with_store_management do |store|
71
- store.write "rabbit", @white_rabbit
72
- store.read("rabbit").should === @white_rabbit
73
- end
74
- end
75
-
76
- it "should write the data with expiration time" do
77
- with_store_management do |store|
78
- store.write "rabbit", @white_rabbit, :expires_in => 1.second
79
- store.read("rabbit").should === @white_rabbit ; sleep 2
80
- store.read("rabbit").should be_nil
81
- end
82
- end
83
-
84
- it "should not write data if :unless_exist option is true" do
85
- with_store_management do |store|
86
- store.write "rabbit", @white_rabbit, :unless_exist => true
87
- store.read("rabbit").should === @rabbit
88
- end
89
- end
90
-
91
- it "should read raw data" do
92
- with_store_management do |store|
93
- store.read("rabbit", :raw => true).should == Marshal.dump(@rabbit)
94
- end
95
- end
96
-
97
- it "should write raw data" do
98
- with_store_management do |store|
99
- store.write "rabbit", @white_rabbit, :raw => true
100
- store.read("rabbit", :raw => true).should == %(#<OpenStruct color="white">)
101
- end
102
- end
103
-
104
- it "should delete data" do
105
- with_store_management do |store|
106
- store.delete "rabbit"
107
- store.read("rabbit").should be_nil
108
- end
109
- end
110
-
111
- it "should delete matched data" do
112
- with_store_management do |store|
113
- store.delete_matched "rabb*"
114
- store.read("rabbit").should be_nil
115
- end
116
- end
117
-
118
- it "should verify existence of an object in the store" do
119
- with_store_management do |store|
120
- store.exist?("rabbit").should be_true
121
- store.exist?("rab-a-dub").should be_false
122
- end
123
- end
124
-
125
- it "should increment a key" do
126
- with_store_management do |store|
127
- 3.times { store.increment "counter" }
128
- store.read("counter", :raw => true).to_i.should == 3
129
- end
130
- end
131
-
132
- it "should decrement a key" do
133
- with_store_management do |store|
134
- 3.times { store.increment "counter" }
135
- 2.times { store.decrement "counter" }
136
- store.read("counter", :raw => true).to_i.should == 1
137
- end
138
- end
139
-
140
- it "should increment a key by given value" do
141
- with_store_management do |store|
142
- store.increment "counter", 3
143
- store.read("counter", :raw => true).to_i.should == 3
144
- end
145
- end
146
-
147
- it "should decrement a key by given value" do
148
- with_store_management do |store|
149
- 3.times { store.increment "counter" }
150
- store.decrement "counter", 2
151
- store.read("counter", :raw => true).to_i.should == 1
152
- end
153
- end
154
-
155
- it "should clear the store" do
156
- with_store_management do |store|
157
- store.clear
158
- store.instance_variable_get(:@data).keys("*").flatten.should be_empty
159
- end
160
- end
161
-
162
- it "should return store stats" do
163
- with_store_management do |store|
164
- store.stats.should_not be_empty
165
- end
166
- end
167
-
168
- it "should fetch data" do
169
- with_store_management do |store|
170
- store.fetch("rabbit").should == @rabbit
171
- store.fetch("rub-a-dub").should be_nil
172
- store.fetch("rub-a-dub") { "Flora de Cana" }.should == "Flora de Cana"
173
- store.fetch("rub-a-dub").should === "Flora de Cana"
174
- store.fetch("rabbit", :force => true).should be_nil # force cache miss
175
- store.fetch("rabbit", :force => true, :expires_in => 1.second) { @white_rabbit }
176
- store.fetch("rabbit").should === @white_rabbit ; sleep 2
177
- store.fetch("rabbit").should be_nil
178
- end
179
- end
180
-
181
- private
182
- def instantiate_store(addresses = nil)
183
- Sinatra::Cache::RedisStore.new(addresses).instance_variable_get(:@data)
184
- end
185
-
186
- def with_store_management
187
- yield @store
188
- yield @dstore
189
- end
190
- end
191
- end
192
- end
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "I18n::Backend::Redis" do
4
- before :each do
5
- @backend = I18n::Backend::Redis.new
6
- @store = @backend.store
7
- I18n.backend = @backend
8
- end
9
-
10
- it "should instantiate a store" do
11
- @store.should be_kind_of(Redis::Store)
12
- end
13
-
14
- it "should instantiate a distributed store" do
15
- store = I18n::Backend::Redis.new([ "redis://127.0.0.1:6379", "redis://127.0.0.1:6380" ]).store
16
- store.should be_kind_of(Redis::DistributedStore)
17
- end
18
-
19
- it "should accept string uri" do
20
- store = I18n::Backend::Redis.new("redis://127.0.0.1:6380/13/theplaylist").store
21
- store.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 13 with namespace theplaylist"
22
- end
23
-
24
- it "should accept hash params" do
25
- store = I18n::Backend::Redis.new(:host => "127.0.0.1", :port => "6380", :db =>"13", :namespace => "theplaylist").store
26
- store.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 13 with namespace theplaylist"
27
- end
28
-
29
- it "should store translations" do
30
- I18n.backend.store_translations :en, :foo => { :bar => :baz }
31
- I18n.t(:"foo.bar").should == :baz
32
-
33
- I18n.backend.store_translations :en, "foo" => { "bar" => "baz" }
34
- I18n.t(:"foo.bar").should == "baz"
35
- end
36
-
37
- it "should get translations" do
38
- I18n.backend.store_translations :en, :foo => { :bar => { :baz => :bang } }
39
- I18n.t(:"foo.bar.baz").should == :bang
40
- I18n.t(:"baz", :scope => :"foo.bar").should == :bang
41
- end
42
-
43
- it "should not store proc translations" do
44
- lambda { I18n.backend.store_translations :en, :foo => lambda {|| } }.should raise_error("Key-value stores cannot handle procs")
45
- end
46
-
47
- describe "available locales" do
48
- before :each do
49
- @locales = [ :en, :it, :es, :fr, :de ]
50
- end
51
-
52
- it "should list" do
53
- @locales.each { |locale| I18n.backend.store_translations locale, :foo => "bar" }
54
- available_locales = I18n.backend.available_locales
55
-
56
- @locales.each do |locale|
57
- available_locales.should include(locale)
58
- end
59
- end
60
-
61
- it "should list when namespaced" do
62
- I18n.backend = I18n::Backend::Redis.new :namespace => 'foo'
63
-
64
- @locales.each { |locale| I18n.backend.store_translations locale, :foo => "bar" }
65
- available_locales = I18n.backend.available_locales
66
-
67
- @locales.each do |locale|
68
- available_locales.should include(locale)
69
- end
70
- end
71
- end
72
- end
Binary file
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class Object
4
- def sha_like?
5
- length == 40 && self =~ /^[0-9a-z]+$/
6
- end
7
- end
8
-
9
- module Rack
10
- module Cache
11
- class EntityStore
12
- # courtesy of http://github.com/rtomayko/rack-cache team
13
- describe "Rack::Cache::EntityStore::Redis" do
14
- before(:each) do
15
- @store = Rack::Cache::EntityStore::Redis.new :host => "localhost"
16
- end
17
-
18
- # Redis store specific examples ===========================================
19
-
20
- it "should have the class referenced by homonym constant" do
21
- Rack::Cache::EntityStore::REDIS.should be(Rack::Cache::EntityStore::Redis)
22
- end
23
-
24
- it "should resolve the connection uri" do
25
- cache = Rack::Cache::EntityStore::Redis.resolve(uri("redis://127.0.0.1")).cache
26
- cache.should be_kind_of(::Redis)
27
- cache.id.should == "redis://127.0.0.1:6379/0"
28
-
29
- cache = Rack::Cache::EntityStore::Redis.resolve(uri("redis://127.0.0.1:6380")).cache
30
- cache.id.should == "redis://127.0.0.1:6380/0"
31
-
32
- cache = Rack::Cache::EntityStore::Redis.resolve(uri("redis://127.0.0.1/13")).cache
33
- cache.id.should == "redis://127.0.0.1:6379/13"
34
-
35
- cache = Rack::Cache::EntityStore::Redis.resolve(uri("redis://:secret@127.0.0.1")).cache
36
- cache.id.should == "redis://127.0.0.1:6379/0"
37
- cache.client.password.should == 'secret'
38
- end
39
-
40
- # Entity store shared examples ===========================================
41
-
42
- it 'responds to all required messages' do
43
- %w[read open write exist?].each do |message|
44
- @store.should respond_to(message)
45
- end
46
- end
47
-
48
- it 'stores bodies with #write' do
49
- key, size = @store.write(['My wild love went riding,'])
50
- key.should_not be_nil
51
- key.should be_sha_like
52
-
53
- data = @store.read(key)
54
- data.should == 'My wild love went riding,'
55
- end
56
-
57
- it 'correctly determines whether cached body exists for key with #exist?' do
58
- key, size = @store.write(['She rode to the devil,'])
59
- @store.should be_exist(key)
60
- @store.should_not be_exist('938jasddj83jasdh4438021ksdfjsdfjsdsf')
61
- end
62
-
63
- it 'can read data written with #write' do
64
- key, size = @store.write(['And asked him to pay.'])
65
- data = @store.read(key)
66
- data.should == 'And asked him to pay.'
67
- end
68
-
69
- it 'gives a 40 character SHA1 hex digest from #write' do
70
- key, size = @store.write(['she rode to the sea;'])
71
- key.should_not be_nil
72
- key.length.should == 40
73
- key.should =~ /^[0-9a-z]+$/
74
- key.should == '90a4c84d51a277f3dafc34693ca264531b9f51b6'
75
- end
76
-
77
- it 'returns the entire body as a String from #read' do
78
- key, size = @store.write(['She gathered together'])
79
- @store.read(key).should == 'She gathered together'
80
- end
81
-
82
- it 'returns nil from #read when key does not exist' do
83
- @store.read('87fe0a1ae82a518592f6b12b0183e950b4541c62').should be_nil
84
- end
85
-
86
- it 'returns a Rack compatible body from #open' do
87
- key, size = @store.write(['Some shells for her hair.'])
88
- body = @store.open(key)
89
- body.should respond_to(:each)
90
- buf = ''
91
- body.each { |part| buf << part }
92
- buf.should == 'Some shells for her hair.'
93
- end
94
-
95
- it 'returns nil from #open when key does not exist' do
96
- @store.open('87fe0a1ae82a518592f6b12b0183e950b4541c62').should be_nil
97
- end
98
-
99
- if RUBY_VERSION < '1.9'
100
- it 'can store largish bodies with binary data' do
101
- pony = ::File.open(::File.dirname(__FILE__) + '/pony.jpg', 'rb') { |f| f.read }
102
- key, size = @store.write([pony])
103
- key.should == 'd0f30d8659b4d268c5c64385d9790024c2d78deb'
104
- data = @store.read(key)
105
- data.length.should == pony.length
106
- data.hash.should == pony.hash
107
- end
108
- end
109
-
110
- it 'deletes stored entries with #purge' do
111
- key, size = @store.write(['My wild love went riding,'])
112
- @store.purge(key).should be_nil
113
- @store.read(key).should be_nil
114
- end
115
-
116
- # Helper Methods =============================================================
117
-
118
- define_method :uri do |uri|
119
- URI.parse uri
120
- end
121
- end
122
- end
123
- end
124
- end