redis-activesupport 4.0.0 → 4.1.0
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -4
- data/.travis.yml +15 -0
- data/Gemfile +3 -11
- data/README.md +22 -12
- data/Rakefile +2 -6
- data/lib/active_support/cache/redis_store.rb +79 -20
- data/lib/redis/activesupport/version.rb +1 -1
- data/redis-activesupport.gemspec +13 -10
- data/test/active_support/cache/redis_store_test.rb +131 -16
- metadata +51 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbde1fe9e22083ceba3ff74535d88465a7097434
|
4
|
+
data.tar.gz: e807712d514c1f5361ef005cd04a028fa802d19f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de702e1868ba3090390e4c52cc82e9d7ad89e9252cdf45aebf85dd5c5d46a20c917ce8385cd7bcd424e6e4efa1fdeb7b7b106145597bd57dc9a944808264a457
|
7
|
+
data.tar.gz: f0cbe5961a33c63a1b4985ea0415f4391de07dc4e7137fbe898100a2eec96d38d1846c89a80ad31587c3814b705c664f0e5f64d303638dfdf0b0c632cbe80711
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,16 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
|
5
|
-
gem '
|
6
|
-
|
7
|
-
version = ENV["RAILS_VERSION"] || "4"
|
8
|
-
|
9
|
-
rails = case version
|
10
|
-
when "master"
|
11
|
-
{:github => "rails/rails"}
|
12
|
-
else
|
13
|
-
"~> #{version}.0"
|
4
|
+
if ::File.directory?(gem_path = '../redis-store')
|
5
|
+
gem 'redis-store', '~> 1.1.0', path: gem_path
|
14
6
|
end
|
15
7
|
|
16
|
-
gem
|
8
|
+
gem 'i18n'
|
data/README.md
CHANGED
@@ -1,28 +1,38 @@
|
|
1
1
|
# Redis stores for ActiveSupport
|
2
2
|
|
3
|
-
__`redis-activesupport`__ provides a cache for __ActiveSupport__. See the main [redis-store readme](https://github.com/
|
3
|
+
__`redis-activesupport`__ provides a cache for __ActiveSupport__. See the main [redis-store readme](https://github.com/redis-store/redis-store) for general guidelines.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
```ruby
|
8
|
+
# Gemfile
|
9
|
+
gem 'redis-activesupport'
|
10
|
+
```
|
9
11
|
|
10
|
-
|
12
|
+
## Usage
|
11
13
|
|
12
|
-
If you are using redis-store with Rails, consider using the [redis-rails gem](https://github.com/
|
14
|
+
If you are using redis-store with Rails, consider using the [redis-rails gem](https://github.com/redis-store/redis-rails) instead. For standalone usage:
|
13
15
|
|
14
|
-
|
16
|
+
```ruby
|
17
|
+
ActiveSupport::Cache.lookup_store :redis_store # { ... optional configuration ... }
|
18
|
+
```
|
15
19
|
|
16
20
|
## Running tests
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
```shell
|
23
|
+
gem install bundler
|
24
|
+
git clone git://github.com/redis-store/redis-activesupport.git
|
25
|
+
cd redis-activesupport
|
26
|
+
bundle install
|
27
|
+
bundle exec rake
|
28
|
+
```
|
23
29
|
|
24
30
|
If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle exec rake`
|
25
31
|
|
32
|
+
## Status
|
33
|
+
|
34
|
+
[](http://badge.fury.io/rb/redis-activesupport) [](http://travis-ci.org/jodosha/redis-activesupport?branch=master) [](https://codeclimate.com/github/redis-store/redis-activesupport)
|
35
|
+
|
26
36
|
## Copyright
|
27
37
|
|
28
|
-
|
38
|
+
2009 - 2013 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
|
data/Rakefile
CHANGED
@@ -4,6 +4,8 @@ require 'redis-store'
|
|
4
4
|
module ActiveSupport
|
5
5
|
module Cache
|
6
6
|
class RedisStore < Store
|
7
|
+
attr_reader :data
|
8
|
+
|
7
9
|
# Instantiate the store.
|
8
10
|
#
|
9
11
|
# Example:
|
@@ -24,9 +26,31 @@ module ActiveSupport
|
|
24
26
|
#
|
25
27
|
# RedisStore.new "localhost:6379/0", "localhost:6380/0"
|
26
28
|
# # => instantiate a cluster
|
29
|
+
#
|
30
|
+
# RedisStore.new "localhost:6379/0", "localhost:6380/0", pool_size: 5, pool_timeout: 10
|
31
|
+
# # => use a ConnectionPool
|
32
|
+
#
|
33
|
+
# RedisStore.new "localhost:6379/0", "localhost:6380/0",
|
34
|
+
# pool: ::ConnectionPool.new(size: 1, timeout: 1) { ::Redis::Store::Factory.create("localhost:6379/0") })
|
35
|
+
# # => supply an existing connection pool (e.g. for use with redis-sentinel or redis-failover)
|
27
36
|
def initialize(*addresses)
|
28
|
-
@
|
29
|
-
|
37
|
+
@options = addresses.extract_options!
|
38
|
+
|
39
|
+
@data = if @options[:pool]
|
40
|
+
raise "pool must be an instance of ConnectionPool" unless @options[:pool].is_a?(ConnectionPool)
|
41
|
+
@pooled = true
|
42
|
+
@options[:pool]
|
43
|
+
elsif [:pool_size, :pool_timeout].any? { |key| @options.has_key?(key) }
|
44
|
+
pool_options = {}
|
45
|
+
pool_options[:size] = options[:pool_size] if options[:pool_size]
|
46
|
+
pool_options[:timeout] = options[:pool_timeout] if options[:pool_timeout]
|
47
|
+
@pooled = true
|
48
|
+
::ConnectionPool.new(pool_options) { ::Redis::Store::Factory.create(addresses) }
|
49
|
+
else
|
50
|
+
::Redis::Store::Factory.create(addresses)
|
51
|
+
end
|
52
|
+
|
53
|
+
super(@options)
|
30
54
|
end
|
31
55
|
|
32
56
|
def write(name, value, options = nil)
|
@@ -45,14 +69,16 @@ module ActiveSupport
|
|
45
69
|
# avoid this method.
|
46
70
|
#
|
47
71
|
# Example:
|
48
|
-
# cache.
|
72
|
+
# cache.delete_matched "rab*"
|
49
73
|
def delete_matched(matcher, options = nil)
|
50
74
|
options = merged_options(options)
|
51
75
|
instrument(:delete_matched, matcher.inspect) do
|
52
76
|
matcher = key_matcher(matcher, options)
|
53
77
|
begin
|
54
|
-
|
55
|
-
|
78
|
+
with do |store|
|
79
|
+
!(keys = store.keys(matcher)).empty? && store.del(*keys)
|
80
|
+
end
|
81
|
+
rescue Errno::ECONNREFUSED, Redis::CannotConnectError
|
56
82
|
false
|
57
83
|
end
|
58
84
|
end
|
@@ -65,17 +91,42 @@ module ActiveSupport
|
|
65
91
|
# cache.read_multi "rabbit", "white-rabbit"
|
66
92
|
# cache.read_multi "rabbit", "white-rabbit", :raw => true
|
67
93
|
def read_multi(*names)
|
68
|
-
|
94
|
+
options = names.extract_options!
|
95
|
+
keys = names.map{|name| namespaced_key(name, options)}
|
96
|
+
values = with { |c| c.mget(*keys) }
|
69
97
|
values.map! { |v| v.is_a?(ActiveSupport::Cache::Entry) ? v.value : v }
|
70
98
|
|
71
99
|
# Remove the options hash before mapping keys to values
|
72
100
|
names.extract_options!
|
73
101
|
|
74
|
-
result = Hash[
|
102
|
+
result = Hash[keys.zip(values)]
|
75
103
|
result.reject!{ |k,v| v.nil? }
|
76
104
|
result
|
77
105
|
end
|
78
106
|
|
107
|
+
def fetch_multi(*names)
|
108
|
+
results = read_multi(*names)
|
109
|
+
options = names.extract_options!
|
110
|
+
fetched = {}
|
111
|
+
|
112
|
+
with do |c|
|
113
|
+
c.multi do
|
114
|
+
fetched = names.inject({}) do |memo, (name, _)|
|
115
|
+
key = namespaced_key(name, options)
|
116
|
+
memo[key] = results.fetch(key) do
|
117
|
+
value = yield name
|
118
|
+
write(name, value, options)
|
119
|
+
value
|
120
|
+
end
|
121
|
+
|
122
|
+
memo
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
fetched
|
128
|
+
end
|
129
|
+
|
79
130
|
# Increment a key in the store.
|
80
131
|
#
|
81
132
|
# If the key doesn't exist it will be initialized on 0.
|
@@ -99,7 +150,7 @@ module ActiveSupport
|
|
99
150
|
# cache.read "rabbit", :raw => true # => "1"
|
100
151
|
def increment(key, amount = 1)
|
101
152
|
instrument(:increment, key, :amount => amount) do
|
102
|
-
|
153
|
+
with{|c| c.incrby key, amount}
|
103
154
|
end
|
104
155
|
end
|
105
156
|
|
@@ -126,18 +177,19 @@ module ActiveSupport
|
|
126
177
|
# cache.read "rabbit", :raw => true # => "-1"
|
127
178
|
def decrement(key, amount = 1)
|
128
179
|
instrument(:decrement, key, :amount => amount) do
|
129
|
-
|
180
|
+
with{|c| c.decrby key, amount}
|
181
|
+
|
130
182
|
end
|
131
183
|
end
|
132
184
|
|
133
185
|
def expire(key, ttl)
|
134
|
-
|
186
|
+
with { |c| c.expire key, ttl }
|
135
187
|
end
|
136
188
|
|
137
189
|
# Clear all the data from the store.
|
138
190
|
def clear
|
139
191
|
instrument(:clear, nil, nil) do
|
140
|
-
|
192
|
+
with(&:flushdb)
|
141
193
|
end
|
142
194
|
end
|
143
195
|
|
@@ -149,28 +201,35 @@ module ActiveSupport
|
|
149
201
|
end
|
150
202
|
|
151
203
|
def stats
|
152
|
-
|
204
|
+
with(&:info)
|
205
|
+
end
|
206
|
+
|
207
|
+
def with(&block)
|
208
|
+
if @pooled
|
209
|
+
@data.with(&block)
|
210
|
+
else
|
211
|
+
block.call(@data)
|
212
|
+
end
|
153
213
|
end
|
154
214
|
|
155
|
-
# Force client reconnection, useful Unicorn deployed apps.
|
156
215
|
def reconnect
|
157
|
-
@data.reconnect
|
216
|
+
@data.reconnect if @data.respond_to?(:reconnect)
|
158
217
|
end
|
159
218
|
|
160
219
|
protected
|
161
220
|
def write_entry(key, entry, options)
|
162
221
|
method = options && options[:unless_exist] ? :setnx : :set
|
163
|
-
|
164
|
-
rescue Errno::ECONNREFUSED
|
222
|
+
with { |client| client.send method, key, entry, options }
|
223
|
+
rescue Errno::ECONNREFUSED, Redis::CannotConnectError
|
165
224
|
false
|
166
225
|
end
|
167
226
|
|
168
227
|
def read_entry(key, options)
|
169
|
-
entry =
|
228
|
+
entry = with { |c| c.get key, options }
|
170
229
|
if entry
|
171
230
|
entry.is_a?(ActiveSupport::Cache::Entry) ? entry : ActiveSupport::Cache::Entry.new(entry)
|
172
231
|
end
|
173
|
-
rescue Errno::ECONNREFUSED
|
232
|
+
rescue Errno::ECONNREFUSED, Redis::CannotConnectError
|
174
233
|
nil
|
175
234
|
end
|
176
235
|
|
@@ -180,8 +239,8 @@ module ActiveSupport
|
|
180
239
|
# It's really needed and use
|
181
240
|
#
|
182
241
|
def delete_entry(key, options)
|
183
|
-
|
184
|
-
rescue Errno::ECONNREFUSED
|
242
|
+
entry = with { |c| c.del key }
|
243
|
+
rescue Errno::ECONNREFUSED, Redis::CannotConnectError
|
185
244
|
false
|
186
245
|
end
|
187
246
|
|
data/redis-activesupport.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
3
|
-
require
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'redis/activesupport/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
6
|
+
s.name = 'redis-activesupport'
|
7
7
|
s.version = Redis::ActiveSupport::VERSION
|
8
|
-
s.authors = [
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
11
|
-
s.summary = %q{Redis store for ActiveSupport
|
12
|
-
s.description = %q{Redis store for ActiveSupport
|
8
|
+
s.authors = ['Luca Guidi']
|
9
|
+
s.email = ['me@lucaguidi.com']
|
10
|
+
s.homepage = 'http://redis-store.org/redis-activesupport'
|
11
|
+
s.summary = %q{Redis store for ActiveSupport}
|
12
|
+
s.description = %q{Redis store for ActiveSupport}
|
13
|
+
s.license = 'MIT'
|
13
14
|
|
14
|
-
s.rubyforge_project =
|
15
|
+
s.rubyforge_project = 'redis-activesupport'
|
15
16
|
|
16
17
|
s.files = `git ls-files`.split("\n")
|
17
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = [
|
20
|
+
s.require_paths = ['lib']
|
20
21
|
|
21
22
|
s.add_runtime_dependency 'redis-store', '~> 1.1.0'
|
22
23
|
s.add_runtime_dependency 'activesupport', '~> 4'
|
@@ -25,5 +26,7 @@ Gem::Specification.new do |s|
|
|
25
26
|
s.add_development_dependency 'bundler', '~> 1.3'
|
26
27
|
s.add_development_dependency 'mocha', '~> 0.14.0'
|
27
28
|
s.add_development_dependency 'minitest', '~> 4.2'
|
29
|
+
s.add_development_dependency 'connection_pool', '~> 1.2.0'
|
30
|
+
s.add_development_dependency 'redis-store-testing'
|
28
31
|
end
|
29
32
|
|
@@ -1,9 +1,20 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'connection_pool'
|
2
4
|
|
3
5
|
describe ActiveSupport::Cache::RedisStore do
|
4
6
|
def setup
|
5
7
|
@store = ActiveSupport::Cache::RedisStore.new
|
6
|
-
@dstore = ActiveSupport::Cache::RedisStore.new "redis://127.0.0.1:
|
8
|
+
@dstore = ActiveSupport::Cache::RedisStore.new "redis://127.0.0.1:6379/5", "redis://127.0.0.1:6379/6"
|
9
|
+
@pool_store = ActiveSupport::Cache::RedisStore.new("redis://127.0.0.1:6379/2", pool_size: 5, pool_timeout: 10)
|
10
|
+
@external_pool_store = ActiveSupport::Cache::RedisStore.new(pool: ::ConnectionPool.new(size: 1, timeout: 1) { ::Redis::Store::Factory.create("redis://127.0.0.1:6379/3") })
|
11
|
+
|
12
|
+
@pool_store.data.class.must_equal ::ConnectionPool
|
13
|
+
@pool_store.data.instance_variable_get(:@size).must_equal 5
|
14
|
+
@external_pool_store.data.class.must_equal ::ConnectionPool
|
15
|
+
@external_pool_store.data.instance_variable_get(:@size).must_equal 1
|
16
|
+
|
17
|
+
|
7
18
|
@rabbit = OpenStruct.new :name => "bunny"
|
8
19
|
@white_rabbit = OpenStruct.new :color => "white"
|
9
20
|
|
@@ -14,6 +25,56 @@ describe ActiveSupport::Cache::RedisStore do
|
|
14
25
|
end
|
15
26
|
end
|
16
27
|
|
28
|
+
it "raises an error if :pool isn't a pool" do
|
29
|
+
assert_raises(RuntimeError, 'pool must be an instance of ConnectionPool') do
|
30
|
+
ActiveSupport::Cache::RedisStore.new(pool: 'poolio')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "namespaces all operations" do
|
35
|
+
address = "redis://127.0.0.1:6380/1/cache-namespace"
|
36
|
+
store = ActiveSupport::Cache::RedisStore.new(address)
|
37
|
+
redis = Redis.new(url: address)
|
38
|
+
|
39
|
+
store.write("white-rabbit", 0)
|
40
|
+
|
41
|
+
redis.exists('cache-namespace:white-rabbit').must_equal(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "creates a normal store when given no addresses" do
|
45
|
+
underlying_store = instantiate_store
|
46
|
+
underlying_store.must_be_instance_of(::Redis::Store)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "creates a normal store when given options only" do
|
50
|
+
underlying_store = instantiate_store(:expires_in => 1.second)
|
51
|
+
underlying_store.must_be_instance_of(::Redis::Store)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "creates a normal store when given a single address" do
|
55
|
+
underlying_store = instantiate_store("redis://127.0.0.1:6380/1")
|
56
|
+
underlying_store.must_be_instance_of(::Redis::Store)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "creates a normal store when given a single address and options" do
|
60
|
+
underlying_store = instantiate_store("redis://127.0.0.1:6380/1",
|
61
|
+
{ :expires_in => 1.second})
|
62
|
+
underlying_store.must_be_instance_of(::Redis::Store)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "creates a distributed store when given multiple addresses" do
|
66
|
+
underlying_store = instantiate_store("redis://127.0.0.1:6380/1",
|
67
|
+
"redis://127.0.0.1:6381/1")
|
68
|
+
underlying_store.must_be_instance_of(::Redis::DistributedStore)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "creates a distributed store when given multiple address and options" do
|
72
|
+
underlying_store = instantiate_store("redis://127.0.0.1:6380/1",
|
73
|
+
"redis://127.0.0.1:6381/1",
|
74
|
+
:expires_in => 1.second)
|
75
|
+
underlying_store.must_be_instance_of(::Redis::DistributedStore)
|
76
|
+
end
|
77
|
+
|
17
78
|
it "reads the data" do
|
18
79
|
with_store_management do |store|
|
19
80
|
store.read("rabbit").must_equal(@rabbit)
|
@@ -27,31 +88,28 @@ describe ActiveSupport::Cache::RedisStore do
|
|
27
88
|
end
|
28
89
|
end
|
29
90
|
|
30
|
-
it "writes the data with
|
91
|
+
it "writes the data with specified namespace" do
|
31
92
|
with_store_management do |store|
|
32
|
-
store.write "rabbit", @white_rabbit, :
|
33
|
-
store.read("rabbit").must_equal(@white_rabbit)
|
34
|
-
sleep 2
|
35
|
-
store.read("rabbit").must_be_nil
|
93
|
+
store.write "rabbit", @white_rabbit, namespace:'namespaced'
|
94
|
+
store.read("namespaced:rabbit").must_equal(@white_rabbit)
|
36
95
|
end
|
37
96
|
end
|
38
97
|
|
39
|
-
it "
|
98
|
+
it "writes the data with expiration time" do
|
40
99
|
with_store_management do |store|
|
41
|
-
store.write "rabbit", @white_rabbit
|
100
|
+
store.write "rabbit", @white_rabbit, :expires_in => 1.second
|
42
101
|
store.read("rabbit").must_equal(@white_rabbit)
|
43
|
-
store.expire "rabbit", 1.seconds
|
44
102
|
sleep 2
|
45
103
|
store.read("rabbit").must_be_nil
|
46
104
|
end
|
47
105
|
end
|
48
106
|
|
49
|
-
it "respects expiration time in
|
107
|
+
it "respects expiration time in seconds" do
|
50
108
|
with_store_management do |store|
|
51
109
|
store.write "rabbit", @white_rabbit
|
52
110
|
store.read("rabbit").must_equal(@white_rabbit)
|
53
|
-
store.expire "rabbit", 1.
|
54
|
-
sleep
|
111
|
+
store.expire "rabbit", 1.second
|
112
|
+
sleep 2
|
55
113
|
store.read("rabbit").must_be_nil
|
56
114
|
end
|
57
115
|
end
|
@@ -95,6 +153,14 @@ describe ActiveSupport::Cache::RedisStore do
|
|
95
153
|
end
|
96
154
|
end
|
97
155
|
|
156
|
+
it "deletes namespaced data" do
|
157
|
+
with_store_management do |store|
|
158
|
+
store.write "rabbit", @white_rabbit, namespace:'namespaced'
|
159
|
+
store.delete "rabbit", namespace:'namespaced'
|
160
|
+
store.read("namespaced:rabbit").must_be_nil
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
98
164
|
it "deletes matched data" do
|
99
165
|
with_store_management do |store|
|
100
166
|
store.delete_matched "rabb*"
|
@@ -158,7 +224,7 @@ describe ActiveSupport::Cache::RedisStore do
|
|
158
224
|
it "clears the store" do
|
159
225
|
with_store_management do |store|
|
160
226
|
store.clear
|
161
|
-
store.
|
227
|
+
store.with { |client| client.keys("*") }.flatten.must_be_empty
|
162
228
|
end
|
163
229
|
end
|
164
230
|
|
@@ -174,14 +240,27 @@ describe ActiveSupport::Cache::RedisStore do
|
|
174
240
|
store.fetch("rub-a-dub").must_be_nil
|
175
241
|
store.fetch("rub-a-dub") { "Flora de Cana" }
|
176
242
|
store.fetch("rub-a-dub").must_equal("Flora de Cana")
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
it "fetches data with expiration time" do
|
247
|
+
with_store_management do |store|
|
177
248
|
store.fetch("rabbit", :force => true) # force cache miss
|
178
249
|
store.fetch("rabbit", :force => true, :expires_in => 1.second) { @white_rabbit }
|
179
|
-
|
250
|
+
store.fetch("rabbit").must_equal(@white_rabbit)
|
180
251
|
sleep 2
|
181
252
|
store.fetch("rabbit").must_be_nil
|
182
253
|
end
|
183
254
|
end
|
184
255
|
|
256
|
+
it "fetches namespaced data" do
|
257
|
+
with_store_management do |store|
|
258
|
+
store.delete("rabbit", namespace:'namespaced')
|
259
|
+
store.fetch("rabbit", namespace:'namespaced'){@rabbit}.must_equal(@rabbit)
|
260
|
+
store.read("rabbit", namespace:'namespaced').must_equal(@rabbit)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
185
264
|
it "reads multiple keys" do
|
186
265
|
@store.write "irish whisky", "Jameson"
|
187
266
|
result = @store.read_multi "rabbit", "irish whisky"
|
@@ -196,6 +275,40 @@ describe ActiveSupport::Cache::RedisStore do
|
|
196
275
|
result.must_include('rabbit')
|
197
276
|
end
|
198
277
|
|
278
|
+
it "reads multiple namespaced keys" do
|
279
|
+
@store.write "rub-a-dub", "Flora de Cana", namespace:'namespaced'
|
280
|
+
@store.write "irish whisky", "Jameson", namespace:'namespaced'
|
281
|
+
result = @store.read_multi "rub-a-dub", "irish whisky", namespace:'namespaced'
|
282
|
+
result['namespaced:rub-a-dub'].must_equal("Flora de Cana")
|
283
|
+
result['namespaced:irish whisky'].must_equal("Jameson")
|
284
|
+
end
|
285
|
+
|
286
|
+
describe "fetch_multi" do
|
287
|
+
it "reads existing keys and fills in anything missing" do
|
288
|
+
@store.write "bourbon", "makers"
|
289
|
+
|
290
|
+
result = @store.fetch_multi("bourbon", "rye") do |key|
|
291
|
+
"#{key}-was-missing"
|
292
|
+
end
|
293
|
+
|
294
|
+
result.must_equal({ "bourbon" => "makers", "rye" => "rye-was-missing" })
|
295
|
+
@store.read("rye").must_equal("rye-was-missing")
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
describe "fetch_multi namespaced keys" do
|
300
|
+
it "reads existing keys and fills in anything missing" do
|
301
|
+
@store.write "bourbon", "makers", namespace:'namespaced'
|
302
|
+
|
303
|
+
result = @store.fetch_multi("bourbon", "rye", namespace:'namespaced') do |key|
|
304
|
+
"#{key}-was-missing"
|
305
|
+
end
|
306
|
+
|
307
|
+
result.must_equal({ "namespaced:bourbon" => "makers", "namespaced:rye" => "rye-was-missing" })
|
308
|
+
@store.read("namespaced:rye").must_equal("rye-was-missing")
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
199
312
|
describe "notifications" do
|
200
313
|
it "notifies on #fetch" do
|
201
314
|
with_notifications do
|
@@ -298,13 +411,15 @@ describe ActiveSupport::Cache::RedisStore do
|
|
298
411
|
end
|
299
412
|
|
300
413
|
private
|
301
|
-
def instantiate_store(addresses
|
302
|
-
ActiveSupport::Cache::RedisStore.new(addresses).instance_variable_get(:@data)
|
414
|
+
def instantiate_store(*addresses)
|
415
|
+
ActiveSupport::Cache::RedisStore.new(*addresses).instance_variable_get(:@data)
|
303
416
|
end
|
304
417
|
|
305
418
|
def with_store_management
|
306
419
|
yield @store
|
307
420
|
yield @dstore
|
421
|
+
yield @pool_store
|
422
|
+
yield @external_pool_store
|
308
423
|
end
|
309
424
|
|
310
425
|
def with_notifications
|
metadata
CHANGED
@@ -1,107 +1,136 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-store
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.14.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.14.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: minitest
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '4.2'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '4.2'
|
97
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: connection_pool
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.2.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.2.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: redis-store-testing
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Redis store for ActiveSupport
|
98
126
|
email:
|
99
127
|
- me@lucaguidi.com
|
100
128
|
executables: []
|
101
129
|
extensions: []
|
102
130
|
extra_rdoc_files: []
|
103
131
|
files:
|
104
|
-
- .gitignore
|
132
|
+
- ".gitignore"
|
133
|
+
- ".travis.yml"
|
105
134
|
- Gemfile
|
106
135
|
- MIT-LICENSE
|
107
136
|
- README.md
|
@@ -114,7 +143,8 @@ files:
|
|
114
143
|
- test/redis/activesupport/version_test.rb
|
115
144
|
- test/test_helper.rb
|
116
145
|
homepage: http://redis-store.org/redis-activesupport
|
117
|
-
licenses:
|
146
|
+
licenses:
|
147
|
+
- MIT
|
118
148
|
metadata: {}
|
119
149
|
post_install_message:
|
120
150
|
rdoc_options: []
|
@@ -122,20 +152,20 @@ require_paths:
|
|
122
152
|
- lib
|
123
153
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
154
|
requirements:
|
125
|
-
- -
|
155
|
+
- - ">="
|
126
156
|
- !ruby/object:Gem::Version
|
127
157
|
version: '0'
|
128
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
159
|
requirements:
|
130
|
-
- -
|
160
|
+
- - ">="
|
131
161
|
- !ruby/object:Gem::Version
|
132
162
|
version: '0'
|
133
163
|
requirements: []
|
134
164
|
rubyforge_project: redis-activesupport
|
135
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.4.8
|
136
166
|
signing_key:
|
137
167
|
specification_version: 4
|
138
|
-
summary: Redis store for ActiveSupport
|
168
|
+
summary: Redis store for ActiveSupport
|
139
169
|
test_files:
|
140
170
|
- test/active_support/cache/redis_store_test.rb
|
141
171
|
- test/redis/activesupport/version_test.rb
|