redis-store 1.0.0.beta2 → 1.0.0.beta3

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 (51) hide show
  1. data/CHANGELOG +74 -23
  2. data/Gemfile +12 -7
  3. data/Gemfile.lock +183 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +49 -14
  6. data/Rakefile +8 -4
  7. data/VERSION +1 -1
  8. data/lib/{rack/session/rails.rb → action_controller/session/redis_session_store.rb} +24 -20
  9. data/lib/{cache/rails → active_support/cache}/redis_store.rb +64 -22
  10. data/lib/cache/merb/redis_store.rb +20 -8
  11. data/lib/cache/sinatra/redis_store.rb +20 -8
  12. data/lib/i18n/backend/redis.rb +67 -0
  13. data/lib/rack/cache/redis_metastore.rb +4 -4
  14. data/lib/rack/session/redis.rb +7 -7
  15. data/lib/redis-store.rb +16 -14
  16. data/lib/redis/distributed_store.rb +35 -0
  17. data/lib/redis/factory.rb +29 -10
  18. data/lib/redis/store.rb +30 -0
  19. data/lib/redis/store/interface.rb +17 -0
  20. data/lib/redis/store/marshalling.rb +41 -0
  21. data/lib/redis/store/namespace.rb +54 -0
  22. data/lib/redis/store/ttl.rb +37 -0
  23. data/lib/redis/store/version.rb +12 -0
  24. data/redis-store.gemspec +32 -20
  25. data/spec/action_controller/session/redis_session_store_spec.rb +121 -0
  26. data/spec/{cache/rails → active_support/cache}/redis_store_spec.rb +93 -19
  27. data/spec/cache/merb/redis_store_spec.rb +14 -11
  28. data/spec/cache/sinatra/redis_store_spec.rb +14 -11
  29. data/spec/config/master.conf +1 -1
  30. data/spec/config/single.conf +1 -1
  31. data/spec/config/slave.conf +1 -1
  32. data/spec/i18n/backend/redis_spec.rb +56 -0
  33. data/spec/rack/cache/entitystore/redis_spec.rb +10 -8
  34. data/spec/rack/cache/metastore/redis_spec.rb +2 -2
  35. data/spec/rack/session/redis_spec.rb +6 -6
  36. data/spec/redis/distributed_store_spec.rb +47 -0
  37. data/spec/redis/factory_spec.rb +58 -16
  38. data/spec/redis/store/interface_spec.rb +23 -0
  39. data/spec/redis/store/marshalling_spec.rb +83 -0
  40. data/spec/redis/store/namespace_spec.rb +76 -0
  41. data/spec/redis/store/version_spec.rb +7 -0
  42. data/spec/spec_helper.rb +16 -5
  43. data/tasks/redis.tasks.rb +19 -12
  44. metadata +33 -21
  45. data/lib/redis/distributed_marshaled.rb +0 -28
  46. data/lib/redis/marshaled_client.rb +0 -65
  47. data/lib/redis_store/version.rb +0 -10
  48. data/spec/rack/session/redis_session_store_spec.rb +0 -75
  49. data/spec/redis/distributed_marshaled_redis_spec.rb +0 -33
  50. data/spec/redis/marshaled_client_spec.rb +0 -83
  51. data/spec/redis_store/version_spec.rb +0 -7
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+ RAILS_SESSION_STORE_CLASS = ::Redis::Store.rails3? ? ActionDispatch::Session::RedisSessionStore : ActionController::Session::RedisSessionStore
3
+
4
+ describe RAILS_SESSION_STORE_CLASS do
5
+ attr_reader :app
6
+
7
+ before :each do
8
+ @app = Object.new
9
+ @store = RAILS_SESSION_STORE_CLASS.new(app)
10
+ @dstore = RAILS_SESSION_STORE_CLASS.new app, :servers => ["redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"]
11
+ @rabbit = OpenStruct.new :name => "bunny"
12
+ @white_rabbit = OpenStruct.new :color => "white"
13
+ @sid = "rabbit"
14
+ @env = {'rack.session.options' => {:id => @sid}}
15
+ with_store_management do |store|
16
+ class << store
17
+ attr_reader :pool
18
+ public :get_session, :set_session, :destroy
19
+ end
20
+ store.set_session(@env, @sid, @rabbit)
21
+ store.pool.del "counter"
22
+ store.pool.del "rub-a-dub"
23
+ end
24
+ end
25
+
26
+ it "should accept string connection params" do
27
+ redis = instantiate_store
28
+ redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
29
+
30
+ redis = instantiate_store :servers => "redis://localhost"
31
+ redis.to_s.should == "Redis Client connected to localhost:6379 against DB 0"
32
+
33
+ redis = instantiate_store :servers => "redis://localhost:6380"
34
+ redis.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
35
+
36
+ redis = instantiate_store :servers => "redis://localhost:6380/13"
37
+ redis.to_s.should == "Redis Client connected to localhost:6380 against DB 13"
38
+
39
+ redis = instantiate_store :servers => "redis://localhost:6380/13/theplaylist"
40
+ redis.to_s.should == "Redis Client connected to localhost:6380 against DB 13 with namespace theplaylist"
41
+ end
42
+
43
+ it "should accept hash connection params" do
44
+ redis = instantiate_store :servers => [{ :host => "192.168.0.1" }]
45
+ redis.to_s.should == "Redis Client connected to 192.168.0.1:6379 against DB 0"
46
+
47
+ redis = instantiate_store :servers => [{ :port => "6380" }]
48
+ redis.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
49
+
50
+ redis = instantiate_store :servers => [{ :db => 13 }]
51
+ redis.to_s.should == "Redis Client connected to localhost:6379 against DB 13"
52
+
53
+ redis = instantiate_store :servers => [{ :key_prefix => "theplaylist" }]
54
+ redis.to_s.should == "Redis Client connected to localhost:6379 against DB 0 with namespace theplaylist"
55
+ end
56
+
57
+ it "should instantiate a ring" do
58
+ store = instantiate_store
59
+ store.should be_kind_of(Redis::Store)
60
+ store = instantiate_store :servers => ["redis://127.0.0.1:6379/0", "redis://127.0.0.1:6379/1"]
61
+ store.should be_kind_of(Redis::DistributedStore)
62
+ end
63
+
64
+ it "should read the data" do
65
+ with_store_management do |store|
66
+ store.get_session(@env, @sid).should === [@sid, @rabbit]
67
+ end
68
+ end
69
+
70
+ it "should write the data" do
71
+ with_store_management do |store|
72
+ store.set_session(@env, @sid, @white_rabbit)
73
+ store.get_session(@env, @sid).should === [@sid, @white_rabbit]
74
+ end
75
+ end
76
+
77
+ it "should delete the data" do
78
+ with_store_management do |store|
79
+ store.destroy(@env)
80
+ store.get_session(@env, @sid).should === [@sid, {}]
81
+ end
82
+ end
83
+
84
+ it "should write the data with expiration time" do
85
+ with_store_management do |store|
86
+ @env['rack.session.options'].merge!(:expires_in => 1.second)
87
+ store.set_session(@env, @sid, @white_rabbit)
88
+ store.get_session(@env, @sid).should === [@sid, @white_rabbit]; sleep 2
89
+ store.get_session(@env, @sid).should === [@sid, {}]
90
+ end
91
+ end
92
+
93
+ describe "namespace" do
94
+ before :each do
95
+ @namespace = "theplaylist"
96
+ @store = RAILS_SESSION_STORE_CLASS.new(lambda {|| }, :servers => [{ :namespace => @namespace }])
97
+ @pool = @store.instance_variable_get(:@pool)
98
+ @client = @pool.instance_variable_get(:@client)
99
+ end
100
+
101
+ it "should read the data" do
102
+ @client.should_receive(:call).with(:get, "#{@namespace}:#{@sid}")
103
+ @store.send :get_session, @env, @sid
104
+ end
105
+
106
+ it "should write the data" do
107
+ @client.should_receive(:call).with(:set, "#{@namespace}:#{@sid}", Marshal.dump(@white_rabbit))
108
+ @store.send :set_session, @env, @sid, @white_rabbit
109
+ end
110
+ end
111
+
112
+ private
113
+ def instantiate_store(params = { })
114
+ RAILS_SESSION_STORE_CLASS.new(app, params).instance_variable_get(:@pool)
115
+ end
116
+
117
+ def with_store_management
118
+ yield @store
119
+ yield @dstore
120
+ end
121
+ end
@@ -1,11 +1,11 @@
1
- require File.join(File.dirname(__FILE__), "/../../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  module ActiveSupport
4
4
  module Cache
5
5
  describe RedisStore do
6
6
  before :each do
7
7
  @store = ActiveSupport::Cache::RedisStore.new
8
- @dstore = ActiveSupport::Cache::RedisStore.new "localhost:6380/1", "localhost:6381/1"
8
+ @dstore = ActiveSupport::Cache::RedisStore.new "redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"
9
9
  @rabbit = OpenStruct.new :name => "bunny"
10
10
  @white_rabbit = OpenStruct.new :color => "white"
11
11
  with_store_management do |store|
@@ -19,21 +19,24 @@ module ActiveSupport
19
19
  redis = instantiate_store
20
20
  redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
21
21
 
22
- redis = instantiate_store "localhost"
23
- redis.to_s.should == "Redis Client connected to localhost:6379 against DB 0"
22
+ redis = instantiate_store "redis://127.0.0.1"
23
+ redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
24
+
25
+ redis = instantiate_store "redis://127.0.0.1:6380"
26
+ redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 0"
24
27
 
25
- redis = instantiate_store "localhost:6380"
26
- redis.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
28
+ redis = instantiate_store "redis://127.0.0.1:6380/13"
29
+ redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 13"
27
30
 
28
- redis = instantiate_store "localhost:6380/13"
29
- redis.to_s.should == "Redis Client connected to localhost:6380 against DB 13"
31
+ redis = instantiate_store "redis://127.0.0.1:6380/13/theplaylist"
32
+ redis.to_s.should == "Redis Client connected to 127.0.0.1:6380 against DB 13 with namespace theplaylist"
30
33
  end
31
34
 
32
35
  it "should instantiate a ring" do
33
36
  store = instantiate_store
34
- store.should be_kind_of(Redis::MarshaledClient)
35
- store = instantiate_store ["localhost:6379/0", "localhost:6379/1"]
36
- store.should be_kind_of(Redis::DistributedMarshaled)
37
+ store.should be_kind_of(Redis::Store)
38
+ store = instantiate_store ["redis://127.0.0.1:6379/0", "redis://127.0.0.1:6379/1"]
39
+ store.should be_kind_of(Redis::DistributedStore)
37
40
  end
38
41
 
39
42
  it "should read the data" do
@@ -64,13 +67,13 @@ module ActiveSupport
64
67
  end
65
68
  end
66
69
 
67
- if ::RedisStore.rails3?
70
+ if ::Redis::Store.rails3?
68
71
  if RUBY_VERSION.match /1\.9/
69
72
  it "should read raw data" do
70
73
  with_store_management do |store|
71
74
  result = store.read("rabbit", :raw => true)
72
75
  result.should include("ActiveSupport::Cache::Entry")
73
- result.should include("\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\rencoding\"\rUS-ASCII")
76
+ result.should include("\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\x06EF")
74
77
  end
75
78
  end
76
79
  else
@@ -174,7 +177,7 @@ module ActiveSupport
174
177
  store.fetch("rub-a-dub").should be_nil
175
178
  store.fetch("rub-a-dub") { "Flora de Cana" }
176
179
  store.fetch("rub-a-dub").should === "Flora de Cana"
177
- store.fetch("rabbit", :force => true).should be_nil # force cache miss
180
+ store.fetch("rabbit", :force => true) # force cache miss
178
181
  store.fetch("rabbit", :force => true, :expires_in => 1.second) { @white_rabbit }
179
182
  store.fetch("rabbit").should == @white_rabbit
180
183
  sleep 2
@@ -182,7 +185,7 @@ module ActiveSupport
182
185
  end
183
186
  end
184
187
 
185
- if ::RedisStore.rails3?
188
+ if ::Redis::Store.rails3?
186
189
  it "should read multiple keys" do
187
190
  @store.write "irish whisky", "Jameson"
188
191
  rabbit, whisky = @store.read_multi "rabbit", "irish whisky"
@@ -198,7 +201,78 @@ module ActiveSupport
198
201
  end
199
202
  end
200
203
 
201
- if ::RedisStore.rails3?
204
+ describe "namespace" do
205
+ before :each do
206
+ @namespace = "theplaylist"
207
+ @store = ActiveSupport::Cache::RedisStore.new :namespace => @namespace
208
+ @data = @store.instance_variable_get(:@data)
209
+ @client = @data.instance_variable_get(:@client)
210
+ end
211
+
212
+ it "should read the data" do
213
+ @client.should_receive(:call).with(:get, "#{@namespace}:rabbit")
214
+ @store.read("rabbit")
215
+ end
216
+
217
+ if ::Redis::Store.rails3?
218
+ # it "should write the data"
219
+ # it "should write the data" do
220
+ # @data.should_receive(:set).with("#{@namespace}:rabbit"), Marshal.dump(ActiveSupport::Cache::Entry.new(@white_rabbit)))
221
+ # @store.write "rabbit", @white_rabbit
222
+ # end
223
+ else
224
+ it "should write the data" do
225
+ @client.should_receive(:call).with(:set, "#{@namespace}:rabbit", Marshal.dump(@white_rabbit))
226
+ @store.write "rabbit", @white_rabbit
227
+ end
228
+ end
229
+
230
+ it "should delete the data" do
231
+ @client.should_receive(:call).with(:del, "#{@namespace}:rabbit")
232
+ @store.delete "rabbit"
233
+ end
234
+
235
+ it "should delete matched data" do
236
+ @client.should_receive(:call).with(:del, "#{@namespace}:rabbit")
237
+ @client.should_receive(:call).with(:keys, "theplaylist:rabb*").and_return [ "#{@namespace}:rabbit" ]
238
+ @store.delete_matched "rabb*"
239
+ end
240
+
241
+ if ::Redis::Store.rails3?
242
+ it "should verify existence of an object in the store" do
243
+ @client.should_receive(:call).with(:get, "#{@namespace}:rabbit")
244
+ @store.exist?("rabbit")
245
+ end
246
+ else
247
+ it "should verify existence of an object in the store" do
248
+ @client.should_receive(:call).with(:exists, "#{@namespace}:rabbit")
249
+ @store.exist?("rabbit")
250
+ end
251
+ end
252
+
253
+ it "should increment a key" do
254
+ @client.should_receive(:call).with(:incrby, "#{@namespace}:counter", 1)
255
+ @store.increment "counter"
256
+ end
257
+
258
+ it "should decrement a key" do
259
+ @client.should_receive(:call).with(:decrby, "#{@namespace}:counter", 1)
260
+ @store.decrement "counter"
261
+ end
262
+
263
+ it "should fetch data" do
264
+ @client.should_receive(:call).with(:get, "#{@namespace}:rabbit")
265
+ @store.fetch "rabbit"
266
+ end
267
+
268
+ it "should read multiple keys" do
269
+ rabbits = [ Marshal.dump(@rabbit), Marshal.dump(@white_rabbit) ]
270
+ @client.should_receive(:call).with(:mget, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit").and_return rabbits
271
+ @store.read_multi "rabbit", "white_rabbit"
272
+ end
273
+ end
274
+
275
+ if ::Redis::Store.rails3?
202
276
  describe "notifications" do
203
277
  it "should notify on #fetch" do
204
278
  with_notifications do
@@ -207,7 +281,7 @@ module ActiveSupport
207
281
 
208
282
  read, generate, write = @events
209
283
  read.name.should == "cache_read.active_support"
210
- read.payload.should == { :key => "radiohead" }
284
+ read.payload.should == { :key => "radiohead", :super_operation => :fetch }
211
285
  generate.name.should == "cache_generate.active_support"
212
286
  generate.payload.should == { :key => "radiohead" }
213
287
  write.name.should == "cache_write.active_support"
@@ -221,7 +295,7 @@ module ActiveSupport
221
295
 
222
296
  read = @events.first
223
297
  read.name.should == "cache_read.active_support"
224
- read.payload.should == { :key => "metallica" }
298
+ read.payload.should == { :key => "metallica", :hit => false }
225
299
  end
226
300
 
227
301
  # it "should notify on #read_multi" # Not supported in Rails 3
@@ -263,7 +337,7 @@ module ActiveSupport
263
337
 
264
338
  delete_matched = @events.first
265
339
  delete_matched.name.should == "cache_delete_matched.active_support"
266
- delete_matched.payload.should == { :key => "afterhours*" }
340
+ delete_matched.payload.should == { :key => %("afterhours*") }
267
341
  end
268
342
 
269
343
  it "should notify on #increment" do
@@ -1,11 +1,11 @@
1
- require File.join(File.dirname(__FILE__), "/../../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  module Merb
4
4
  module Cache
5
5
  describe "Merb::Cache::RedisStore" do
6
6
  before(:each) do
7
7
  @store = Merb::Cache::RedisStore.new
8
- @dstore = Merb::Cache::RedisStore.new :servers => ["localhost:6380/1", "localhost:6381/1"]
8
+ @dstore = Merb::Cache::RedisStore.new :servers => ["redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"]
9
9
  @rabbit = OpenStruct.new :name => "bunny"
10
10
  @white_rabbit = OpenStruct.new :color => "white"
11
11
  with_store_management do |store|
@@ -18,21 +18,24 @@ module Merb
18
18
  redis = instantiate_store
19
19
  redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
20
20
 
21
- redis = instantiate_store "localhost"
22
- redis.to_s.should == "Redis Client connected to localhost:6379 against DB 0"
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"
23
26
 
24
- redis = instantiate_store "localhost:6380"
25
- redis.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
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"
26
29
 
27
- redis = instantiate_store "localhost:6380/13"
28
- redis.to_s.should == "Redis Client connected to localhost:6380 against DB 13"
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"
29
32
  end
30
33
 
31
34
  it "should instantiate a ring" do
32
35
  store = instantiate_store
33
- store.should be_kind_of(Redis::MarshaledClient)
34
- store = instantiate_store ["localhost:6379/0", "localhost:6379/1"]
35
- store.should be_kind_of(Redis::DistributedMarshaled)
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)
36
39
  end
37
40
 
38
41
  it "should verify if writable" do
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "/../../spec_helper")
1
+ require 'spec_helper'
2
2
 
3
3
  class App
4
4
  def initialize
@@ -19,7 +19,7 @@ module Sinatra
19
19
  describe "Sinatra::Cache::RedisStore" do
20
20
  before(:each) do
21
21
  @store = Sinatra::Cache::RedisStore.new
22
- @dstore = Sinatra::Cache::RedisStore.new "localhost:6380/1", "localhost:6381/1"
22
+ @dstore = Sinatra::Cache::RedisStore.new "redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"
23
23
  @rabbit = OpenStruct.new :name => "bunny"
24
24
  @white_rabbit = OpenStruct.new :color => "white"
25
25
  with_store_management do |store|
@@ -40,21 +40,24 @@ module Sinatra
40
40
  redis = instantiate_store
41
41
  redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
42
42
 
43
- redis = instantiate_store "localhost"
44
- redis.to_s.should == "Redis Client connected to localhost:6379 against DB 0"
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"
45
48
 
46
- redis = instantiate_store "localhost:6380"
47
- redis.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
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"
48
51
 
49
- redis = instantiate_store "localhost:6380/13"
50
- redis.to_s.should == "Redis Client connected to localhost:6380 against DB 13"
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"
51
54
  end
52
55
 
53
56
  it "should instantiate a ring" do
54
57
  store = instantiate_store
55
- store.should be_kind_of(Redis::MarshaledClient)
56
- store = instantiate_store ["localhost:6379/0", "localhost:6379/1"]
57
- store.should be_kind_of(Redis::DistributedMarshaled)
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)
58
61
  end
59
62
 
60
63
  it "should read the data" do
@@ -76,7 +76,7 @@ save 60 10000
76
76
  rdbcompression yes
77
77
 
78
78
  # The filename where to dump the DB
79
- dbfilename master-dump.rdb
79
+ dbfilename tmp/master-dump.rdb
80
80
 
81
81
  # The working directory.
82
82
  #
@@ -76,7 +76,7 @@ save 60 10000
76
76
  rdbcompression yes
77
77
 
78
78
  # The filename where to dump the DB
79
- dbfilename dump.rdb
79
+ dbfilename tmp/dump.rdb
80
80
 
81
81
  # The working directory.
82
82
  #
@@ -76,7 +76,7 @@ save 60 10000
76
76
  rdbcompression yes
77
77
 
78
78
  # The filename where to dump the DB
79
- dbfilename slave-dump.rdb
79
+ dbfilename tmp/slave-dump.rdb
80
80
 
81
81
  # The working directory.
82
82
  #
@@ -0,0 +1,56 @@
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
+ it "should list available locales" do
48
+ locales = [ :en, :it, :es, :fr, :de ]
49
+ locales.each { |locale| I18n.backend.store_translations locale, :foo => "bar" }
50
+ available_locales = I18n.backend.available_locales
51
+
52
+ locales.each do |locale|
53
+ available_locales.should include(locale)
54
+ end
55
+ end
56
+ end