redis-activesupport 5.0.4 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/auto-assign-issues.yml +2 -0
- data/.gitignore +1 -0
- data/.travis.yml +42 -19
- data/Appraisals +19 -0
- data/CODEOWNERS +1 -0
- data/README.md +16 -1
- data/gemfiles/activesupport_3.gemfile +8 -0
- data/gemfiles/activesupport_4.gemfile +8 -0
- data/gemfiles/activesupport_50.gemfile +8 -0
- data/gemfiles/activesupport_51.gemfile +8 -0
- data/gemfiles/activesupport_52.gemfile +8 -0
- data/lib/active_support/cache/redis_store.rb +103 -58
- data/lib/redis/active_support/version.rb +1 -1
- data/redis-activesupport.gemspec +6 -6
- data/test/active_support/cache/redis_store_test.rb +33 -3
- data/test/test_helper.rb +1 -1
- metadata +56 -24
- data/gemfiles/Gemfile.activesupport-3.x +0 -13
- data/gemfiles/Gemfile.activesupport-4.x +0 -13
- data/gemfiles/Gemfile.activesupport-5.x +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 97eb2a5bdf33332f087f0f23209184624afa1800baf44ed0cbae6c1b8da90ed4
|
4
|
+
data.tar.gz: 349ad4d2542eb8a0d92ead51e26415a18e7a918587d5104f1439b983cbdaf7ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfe500173fb4d0633c0efb04e9e0841532f61dfd47d57865c2acb8eb03e102eab0283b6ad245b5b44fbe1270712143348d2b613d800d3c648ceac51dd1e49ddc
|
7
|
+
data.tar.gz: 5a7656320765a145c2f2bcde246a9a54e14cc6bba5488704f8ff10a9503f4218385a4743f3b215af50375d202a17ae6efeee41cf68fa4bcb0206bd280954891e
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,24 +1,47 @@
|
|
1
1
|
language: ruby
|
2
|
-
script:
|
3
|
-
gemfile:
|
4
|
-
- gemfiles/Gemfile.activesupport-3.x
|
5
|
-
- gemfiles/Gemfile.activesupport-4.x
|
6
|
-
- gemfiles/Gemfile.activesupport-5.x
|
2
|
+
script: bundle exec rake
|
7
3
|
rvm:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
- 2.0
|
5
|
+
- 2.1
|
6
|
+
- 2.3
|
7
|
+
- 2.4
|
8
|
+
- 2.5
|
9
|
+
- 2.6
|
10
|
+
- ruby-head
|
11
|
+
- jruby-head
|
15
12
|
services:
|
16
|
-
|
13
|
+
- redis-server
|
17
14
|
matrix:
|
18
15
|
allow_failures:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
- rvm: jruby-head
|
17
|
+
- rvm: ruby-head
|
18
|
+
exclude:
|
19
|
+
- rvm: 2.0
|
20
|
+
gemfile: gemfiles/activesupport_50.gemfile
|
21
|
+
- rvm: 2.1
|
22
|
+
gemfile: gemfiles/activesupport_50.gemfile
|
23
|
+
- rvm: 2.0
|
24
|
+
gemfile: gemfiles/activesupport_51.gemfile
|
25
|
+
- rvm: 2.1
|
26
|
+
gemfile: gemfiles/activesupport_51.gemfile
|
27
|
+
- rvm: 2.0
|
28
|
+
gemfile: gemfiles/activesupport_52.gemfile
|
29
|
+
- rvm: 2.1
|
30
|
+
gemfile: gemfiles/activesupport_52.gemfile
|
31
|
+
notifications:
|
32
|
+
webhooks: https://www.travisbuddy.com/
|
33
|
+
on_success: never
|
34
|
+
gemfile:
|
35
|
+
- gemfiles/activesupport_3.gemfile
|
36
|
+
- gemfiles/activesupport_4.gemfile
|
37
|
+
- gemfiles/activesupport_50.gemfile
|
38
|
+
- gemfiles/activesupport_51.gemfile
|
39
|
+
- gemfiles/activesupport_52.gemfile
|
40
|
+
deploy:
|
41
|
+
provider: rubygems
|
42
|
+
api_key:
|
43
|
+
secure: VHWLUgCtqlKjeS5uGOxS4tnEUSPiapyvBvgSpr+FUeQnjAE9jgJvz+rAmiNy/pp8fAhjH5FdyIUXuh2rE2sWcBYrOa1rCvrc7eBHdnpZ4U7ULJwQKhC/4dOE33ClaZX2pex4pv12I2218ZH5TsqdmQ0Ci0ccfNZJv0vs+IFP+kQ=
|
44
|
+
gem: redis-activesupport
|
45
|
+
on:
|
46
|
+
tags: true
|
47
|
+
repo: redis-store/redis-activesupport
|
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
appraise 'activesupport_3' do
|
2
|
+
gem 'activesupport', '~> 3'
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise 'activesupport_4' do
|
6
|
+
gem 'activesupport', '~> 4'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'activesupport_50' do
|
10
|
+
gem 'activesupport', '~> 5.0.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'activesupport_51' do
|
14
|
+
gem 'activesupport', '~> 5.1.0'
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise 'activesupport_52' do
|
18
|
+
gem 'activesupport', '~> 5.2.0'
|
19
|
+
end
|
data/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @tubbo
|
data/README.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
# Redis stores for ActiveSupport
|
2
2
|
|
3
|
-
__`redis-activesupport`__ provides a cache for __ActiveSupport__.
|
3
|
+
__`redis-activesupport`__ provides a cache for __ActiveSupport__.
|
4
|
+
|
5
|
+
|
6
|
+
For guidelines on using our underlying cache store, see the main [redis-store readme](https://github.com/redis-store/redis-store).
|
7
|
+
|
8
|
+
For information on how to use this library in a Rails app, see the [documentation for redis-rails](https://github.com/redis-store/redis-rails).
|
9
|
+
|
10
|
+
If, for some reason, you're using `ActiveSupport::Cache` and not in a Rails app, read on to learn how to install/use this gem by itself!
|
11
|
+
|
12
|
+
## A quick note about Rails 5.2
|
13
|
+
|
14
|
+
Rails 5.2.0 [includes a Redis cache store out of the
|
15
|
+
box](https://github.com/rails/rails/pull/31134), so you don't really
|
16
|
+
need this anymore if you're generating a new Rails application. We
|
17
|
+
are no longer accepting new features for this gem, only pull requests
|
18
|
+
for security and compatibility fixes will be accepted.
|
4
19
|
|
5
20
|
## Installation
|
6
21
|
|
@@ -8,10 +8,17 @@ module ActiveSupport
|
|
8
8
|
ERRORS_TO_RESCUE = [
|
9
9
|
Errno::ECONNREFUSED,
|
10
10
|
Errno::EHOSTUNREACH,
|
11
|
-
|
12
|
-
|
11
|
+
# This is what rails' redis cache store rescues
|
12
|
+
# https://github.com/rails/rails/blob/5-2-stable/activesupport/lib/active_support/cache/redis_cache_store.rb#L447
|
13
|
+
Redis::BaseConnectionError
|
13
14
|
].freeze
|
14
15
|
|
16
|
+
DEFAULT_ERROR_HANDLER = -> (method: nil, returning: nil, exception: nil) do
|
17
|
+
if logger
|
18
|
+
logger.error { "RedisStore: #{method} failed, returned #{returning.inspect}: #{exception.class}: #{exception.message}" }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
15
22
|
attr_reader :data
|
16
23
|
|
17
24
|
# Instantiate the store.
|
@@ -20,30 +27,33 @@ module ActiveSupport
|
|
20
27
|
# RedisStore.new
|
21
28
|
# # => host: localhost, port: 6379, db: 0
|
22
29
|
#
|
23
|
-
# RedisStore.new "
|
30
|
+
# RedisStore.new client: Redis.new(url: "redis://127.0.0.1:6380/1")
|
31
|
+
# # => host: localhost, port: 6379, db: 0
|
32
|
+
#
|
33
|
+
# RedisStore.new "redis://example.com"
|
24
34
|
# # => host: example.com, port: 6379, db: 0
|
25
35
|
#
|
26
|
-
# RedisStore.new "example.com:23682"
|
36
|
+
# RedisStore.new "redis://example.com:23682"
|
27
37
|
# # => host: example.com, port: 23682, db: 0
|
28
38
|
#
|
29
|
-
# RedisStore.new "example.com:23682/1"
|
39
|
+
# RedisStore.new "redis://example.com:23682/1"
|
30
40
|
# # => host: example.com, port: 23682, db: 1
|
31
41
|
#
|
32
|
-
# RedisStore.new "example.com:23682/1/theplaylist"
|
42
|
+
# RedisStore.new "redis://example.com:23682/1/theplaylist"
|
33
43
|
# # => host: example.com, port: 23682, db: 1, namespace: theplaylist
|
34
44
|
#
|
35
|
-
# RedisStore.new "localhost:6379/0", "localhost:6380/0"
|
45
|
+
# RedisStore.new "redis://localhost:6379/0", "redis://localhost:6380/0"
|
36
46
|
# # => instantiate a cluster
|
37
47
|
#
|
38
|
-
# RedisStore.new "localhost:6379/0", "localhost:6380/0", pool_size: 5, pool_timeout: 10
|
48
|
+
# RedisStore.new "redis://localhost:6379/0", "redis://localhost:6380/0", pool_size: 5, pool_timeout: 10
|
39
49
|
# # => use a ConnectionPool
|
40
50
|
#
|
41
|
-
# RedisStore.new "localhost:6379/0", "localhost:6380/0",
|
51
|
+
# RedisStore.new "redis://localhost:6379/0", "redis://localhost:6380/0",
|
42
52
|
# pool: ::ConnectionPool.new(size: 1, timeout: 1) { ::Redis::Store::Factory.create("localhost:6379/0") })
|
43
53
|
# # => supply an existing connection pool (e.g. for use with redis-sentinel or redis-failover)
|
44
54
|
def initialize(*addresses)
|
45
|
-
@options = addresses.
|
46
|
-
addresses = addresses.map(&:dup)
|
55
|
+
@options = addresses.extract_options!
|
56
|
+
addresses = addresses.compact.map(&:dup)
|
47
57
|
|
48
58
|
@data = if @options[:pool]
|
49
59
|
raise "pool must be an instance of ConnectionPool" unless @options[:pool].is_a?(ConnectionPool)
|
@@ -54,21 +64,25 @@ module ActiveSupport
|
|
54
64
|
pool_options[:size] = options[:pool_size] if options[:pool_size]
|
55
65
|
pool_options[:timeout] = options[:pool_timeout] if options[:pool_timeout]
|
56
66
|
@pooled = true
|
57
|
-
::ConnectionPool.new(pool_options) { ::Redis::Store::Factory.create(*addresses) }
|
67
|
+
::ConnectionPool.new(pool_options) { ::Redis::Store::Factory.create(*addresses, @options) }
|
68
|
+
elsif @options[:client]
|
69
|
+
@options[:client]
|
58
70
|
else
|
59
|
-
::Redis::Store::Factory.create(*addresses)
|
71
|
+
::Redis::Store::Factory.create(*addresses, @options)
|
60
72
|
end
|
61
73
|
|
74
|
+
@error_handler = @options[:error_handler] || DEFAULT_ERROR_HANDLER
|
75
|
+
|
62
76
|
super(@options)
|
63
77
|
end
|
64
78
|
|
65
79
|
def write(name, value, options = nil)
|
66
|
-
options = merged_options(options)
|
67
|
-
instrument(:write, name, options) do |
|
68
|
-
entry = options[:raw].present? ? value : Entry.new(value, options)
|
80
|
+
options = merged_options(options.to_h.symbolize_keys)
|
81
|
+
instrument(:write, name, options) do |_payload|
|
69
82
|
if options[:expires_in].present? && options[:race_condition_ttl].present? && options[:raw].blank?
|
70
83
|
options[:expires_in] = options[:expires_in].to_f + options[:race_condition_ttl].to_f
|
71
84
|
end
|
85
|
+
entry = options[:raw].present? ? value : Entry.new(value, **options)
|
72
86
|
write_entry(normalize_key(name, options), entry, options)
|
73
87
|
end
|
74
88
|
end
|
@@ -85,14 +99,13 @@ module ActiveSupport
|
|
85
99
|
def delete_matched(matcher, options = nil)
|
86
100
|
options = merged_options(options)
|
87
101
|
instrument(:delete_matched, matcher.inspect) do
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
102
|
+
failsafe(:read_multi, returning: false) do
|
103
|
+
matcher = key_matcher(matcher, options)
|
104
|
+
begin
|
105
|
+
with do |store|
|
106
|
+
!(keys = store.keys(matcher)).empty? && store.del(*keys)
|
107
|
+
end
|
92
108
|
end
|
93
|
-
rescue *ERRORS_TO_RESCUE
|
94
|
-
raise if raise_errors?
|
95
|
-
false
|
96
109
|
end
|
97
110
|
end
|
98
111
|
end
|
@@ -112,16 +125,15 @@ module ActiveSupport
|
|
112
125
|
args.flatten!
|
113
126
|
|
114
127
|
instrument(:read_multi, names) do |payload|
|
115
|
-
|
116
|
-
|
128
|
+
failsafe(:read_multi, returning: {}) do
|
129
|
+
values = with { |c| c.mget(*args) }
|
130
|
+
values.map! { |v| v.is_a?(ActiveSupport::Cache::Entry) ? v.value : v }
|
117
131
|
|
118
|
-
|
119
|
-
|
132
|
+
Hash[names.zip(values)].reject{|k,v| v.nil?}.tap do |result|
|
133
|
+
payload[:hits] = result.keys if payload
|
134
|
+
end
|
120
135
|
end
|
121
136
|
end
|
122
|
-
rescue *ERRORS_TO_RESCUE
|
123
|
-
raise if raise_errors?
|
124
|
-
{}
|
125
137
|
end
|
126
138
|
|
127
139
|
def fetch_multi(*names)
|
@@ -141,7 +153,7 @@ module ActiveSupport
|
|
141
153
|
memo
|
142
154
|
end
|
143
155
|
|
144
|
-
|
156
|
+
failsafe(:fetch_multi_write) do
|
145
157
|
with do |c|
|
146
158
|
c.multi do
|
147
159
|
need_writes.each do |name, value|
|
@@ -149,8 +161,6 @@ module ActiveSupport
|
|
149
161
|
end
|
150
162
|
end
|
151
163
|
end
|
152
|
-
rescue *ERRORS_TO_RESCUE
|
153
|
-
raise if raise_errors?
|
154
164
|
end
|
155
165
|
|
156
166
|
fetched
|
@@ -177,10 +187,18 @@ module ActiveSupport
|
|
177
187
|
#
|
178
188
|
# cache.increment "rabbit"
|
179
189
|
# cache.read "rabbit", :raw => true # => "1"
|
180
|
-
def increment(
|
181
|
-
|
182
|
-
|
183
|
-
|
190
|
+
def increment(name, amount = 1, options = {})
|
191
|
+
instrument :increment, name, amount: amount do
|
192
|
+
failsafe :increment do
|
193
|
+
options = merged_options(options)
|
194
|
+
key = normalize_key(name, options)
|
195
|
+
|
196
|
+
with do |c|
|
197
|
+
c.incrby(key, amount).tap do
|
198
|
+
write_key_expiry(c, key, options)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
184
202
|
end
|
185
203
|
end
|
186
204
|
|
@@ -205,10 +223,18 @@ module ActiveSupport
|
|
205
223
|
#
|
206
224
|
# cache.decrement "rabbit"
|
207
225
|
# cache.read "rabbit", :raw => true # => "-1"
|
208
|
-
def decrement(
|
209
|
-
|
210
|
-
|
211
|
-
|
226
|
+
def decrement(name, amount = 1, options = {})
|
227
|
+
instrument :decrement, name, amount: amount do
|
228
|
+
failsafe :decrement do
|
229
|
+
options = merged_options(options)
|
230
|
+
key = normalize_key(name, options)
|
231
|
+
|
232
|
+
with do |c|
|
233
|
+
c.decrby(key, amount).tap do
|
234
|
+
write_key_expiry(c, key, options)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
212
238
|
end
|
213
239
|
end
|
214
240
|
|
@@ -220,7 +246,9 @@ module ActiveSupport
|
|
220
246
|
# Clear all the data from the store.
|
221
247
|
def clear
|
222
248
|
instrument(:clear, nil, nil) do
|
223
|
-
|
249
|
+
failsafe(:clear) do
|
250
|
+
with(&:flushdb)
|
251
|
+
end
|
224
252
|
end
|
225
253
|
end
|
226
254
|
|
@@ -249,21 +277,24 @@ module ActiveSupport
|
|
249
277
|
|
250
278
|
protected
|
251
279
|
def write_entry(key, entry, options)
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
false
|
280
|
+
failsafe(:write_entry, returning: false) do
|
281
|
+
method = options && options[:unless_exist] ? :setnx : :set
|
282
|
+
with { |client| client.send method, key, entry, options }
|
283
|
+
end
|
257
284
|
end
|
258
285
|
|
259
286
|
def read_entry(key, options)
|
260
|
-
|
261
|
-
|
262
|
-
|
287
|
+
failsafe(:read_entry) do
|
288
|
+
entry = with { |c| c.get key, options }
|
289
|
+
return unless entry
|
290
|
+
entry.is_a?(Entry) ? entry : Entry.new(entry)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def write_key_expiry(client, key, options)
|
295
|
+
if options[:expires_in] && client.ttl(key) < 0
|
296
|
+
client.expire key, options[:expires_in].to_i
|
263
297
|
end
|
264
|
-
rescue *ERRORS_TO_RESCUE
|
265
|
-
raise if raise_errors?
|
266
|
-
nil
|
267
298
|
end
|
268
299
|
|
269
300
|
##
|
@@ -272,10 +303,9 @@ module ActiveSupport
|
|
272
303
|
# It's really needed and use
|
273
304
|
#
|
274
305
|
def delete_entry(key, options)
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
false
|
306
|
+
failsafe(:delete_entry, returning: false) do
|
307
|
+
with { |c| c.del key }
|
308
|
+
end
|
279
309
|
end
|
280
310
|
|
281
311
|
def raise_errors?
|
@@ -300,12 +330,27 @@ module ActiveSupport
|
|
300
330
|
end
|
301
331
|
|
302
332
|
private
|
303
|
-
|
304
333
|
if ActiveSupport::VERSION::MAJOR < 5
|
305
334
|
def normalize_key(*args)
|
306
335
|
namespaced_key(*args)
|
307
336
|
end
|
308
337
|
end
|
338
|
+
|
339
|
+
def failsafe(method, returning: nil)
|
340
|
+
yield
|
341
|
+
rescue ::Redis::BaseConnectionError => e
|
342
|
+
raise if raise_errors?
|
343
|
+
handle_exception(exception: e, method: method, returning: returning)
|
344
|
+
returning
|
345
|
+
end
|
346
|
+
|
347
|
+
def handle_exception(exception: nil, method: nil, returning: nil)
|
348
|
+
if @error_handler
|
349
|
+
@error_handler.(method: method, exception: exception, returning: returning)
|
350
|
+
end
|
351
|
+
rescue => failsafe
|
352
|
+
warn("RedisStore ignored exception in handle_exception: #{failsafe.class}: #{failsafe.message}\n #{failsafe.backtrace.join("\n ")}")
|
353
|
+
end
|
309
354
|
end
|
310
355
|
end
|
311
356
|
end
|
data/redis-activesupport.gemspec
CHANGED
@@ -13,20 +13,20 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{Redis store for ActiveSupport}
|
14
14
|
s.license = 'MIT'
|
15
15
|
|
16
|
-
s.rubyforge_project = 'redis-activesupport'
|
17
|
-
|
18
16
|
s.files = `git ls-files`.split("\n")
|
19
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
19
|
s.require_paths = ['lib']
|
22
20
|
|
23
21
|
s.add_runtime_dependency "redis-store", '>= 1.3', '< 2'
|
24
|
-
s.add_runtime_dependency 'activesupport', '>= 3', '<
|
22
|
+
s.add_runtime_dependency 'activesupport', '>= 3', '< 7'
|
25
23
|
|
26
|
-
s.add_development_dependency 'rake', '
|
27
|
-
s.add_development_dependency 'bundler'
|
24
|
+
s.add_development_dependency 'rake', '>= 12.3.3'
|
25
|
+
s.add_development_dependency 'bundler'
|
28
26
|
s.add_development_dependency 'mocha', '~> 0.14.0'
|
29
27
|
s.add_development_dependency 'minitest', '>= 4.2', '< 6'
|
30
|
-
s.add_development_dependency 'connection_pool', '
|
28
|
+
s.add_development_dependency 'connection_pool', '= 2.2.2'
|
31
29
|
s.add_development_dependency 'redis-store-testing'
|
30
|
+
s.add_development_dependency 'appraisal', '~> 2.0'
|
31
|
+
s.add_development_dependency 'pry-byebug', '~> 3'
|
32
32
|
end
|
@@ -26,6 +26,13 @@ describe ActiveSupport::Cache::RedisStore do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
it "uses redis client passed as an option" do
|
30
|
+
redis = Redis.new(url: "redis://127.0.0.1:6380/1")
|
31
|
+
store = ActiveSupport::Cache::RedisStore.new(client: redis)
|
32
|
+
|
33
|
+
store.data.must_equal(redis)
|
34
|
+
end
|
35
|
+
|
29
36
|
it "connects using an hash of options" do
|
30
37
|
address = { host: '127.0.0.1', port: '6380', db: '1' }
|
31
38
|
store = ActiveSupport::Cache::RedisStore.new(address.merge(pool_size: 5, pool_timeout: 10))
|
@@ -91,6 +98,11 @@ describe ActiveSupport::Cache::RedisStore do
|
|
91
98
|
underlying_store.must_be_instance_of(::Redis::Store)
|
92
99
|
end
|
93
100
|
|
101
|
+
it "creates a normal store when given nil" do
|
102
|
+
underlying_store = instantiate_store nil
|
103
|
+
underlying_store.must_be_instance_of(::Redis::Store)
|
104
|
+
end
|
105
|
+
|
94
106
|
it "creates a normal store when given options only" do
|
95
107
|
underlying_store = instantiate_store(:expires_in => 1.second)
|
96
108
|
underlying_store.must_be_instance_of(::Redis::Store)
|
@@ -323,6 +335,24 @@ describe ActiveSupport::Cache::RedisStore do
|
|
323
335
|
end
|
324
336
|
end
|
325
337
|
|
338
|
+
it "increments a key with expiration time" do
|
339
|
+
with_store_management do |store|
|
340
|
+
store.increment "counter", 1, :expires_in => 1.second
|
341
|
+
store.read("counter", :raw => true).to_i.must_equal(1)
|
342
|
+
sleep 2
|
343
|
+
store.read("counter", :raw => true).must_be_nil
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
it "decrements a key with expiration time" do
|
348
|
+
with_store_management do |store|
|
349
|
+
store.decrement "counter", 1, :expires_in => 1.second
|
350
|
+
store.read("counter", :raw => true).to_i.must_equal(-1)
|
351
|
+
sleep 2
|
352
|
+
store.read("counter", :raw => true).must_be_nil
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
326
356
|
it "clears the store" do
|
327
357
|
with_store_management do |store|
|
328
358
|
store.clear
|
@@ -365,7 +395,7 @@ describe ActiveSupport::Cache::RedisStore do
|
|
365
395
|
|
366
396
|
describe "race_condition_ttl on fetch" do
|
367
397
|
it "persist entry for longer than given ttl" do
|
368
|
-
options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds }
|
398
|
+
options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds, version: Time.now.to_i }
|
369
399
|
@store.fetch("rabbit", options) { @rabbit }
|
370
400
|
sleep 1.1
|
371
401
|
@store.delete("rabbit").must_equal(1)
|
@@ -373,12 +403,12 @@ describe ActiveSupport::Cache::RedisStore do
|
|
373
403
|
|
374
404
|
it "limits stampede time to read-write duration" do
|
375
405
|
first_rabbit = second_rabbit = nil
|
376
|
-
options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds }
|
406
|
+
options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds, version: Time.now.to_i }
|
377
407
|
@store.fetch("rabbit", options) { @rabbit }
|
378
408
|
sleep 1
|
379
409
|
|
380
410
|
th1 = Thread.new do
|
381
|
-
first_rabbit = @store.fetch("rabbit",
|
411
|
+
first_rabbit = @store.fetch("rabbit", options) do
|
382
412
|
sleep 1
|
383
413
|
@white_rabbit
|
384
414
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
- Ryan Bigg
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis-store
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version: '3'
|
41
41
|
- - "<"
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '7'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
46
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -50,35 +50,35 @@ dependencies:
|
|
50
50
|
version: '3'
|
51
51
|
- - "<"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '7'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: rake
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 12.3.3
|
61
61
|
type: :development
|
62
62
|
prerelease: false
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: 12.3.3
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: bundler
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '0'
|
75
75
|
type: :development
|
76
76
|
prerelease: false
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '0'
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: mocha
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,16 +117,16 @@ dependencies:
|
|
117
117
|
name: connection_pool
|
118
118
|
requirement: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
|
-
- -
|
120
|
+
- - '='
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: 2.2.
|
122
|
+
version: 2.2.2
|
123
123
|
type: :development
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
|
-
- -
|
127
|
+
- - '='
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: 2.2.
|
129
|
+
version: 2.2.2
|
130
130
|
- !ruby/object:Gem::Dependency
|
131
131
|
name: redis-store-testing
|
132
132
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,6 +141,34 @@ dependencies:
|
|
141
141
|
- - ">="
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
|
+
- !ruby/object:Gem::Dependency
|
145
|
+
name: appraisal
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - "~>"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '2.0'
|
151
|
+
type: :development
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - "~>"
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '2.0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: pry-byebug
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - "~>"
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '3'
|
165
|
+
type: :development
|
166
|
+
prerelease: false
|
167
|
+
version_requirements: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - "~>"
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '3'
|
144
172
|
description: Redis store for ActiveSupport
|
145
173
|
email:
|
146
174
|
- me@lucaguidi.com
|
@@ -149,15 +177,20 @@ executables: []
|
|
149
177
|
extensions: []
|
150
178
|
extra_rdoc_files: []
|
151
179
|
files:
|
180
|
+
- ".github/auto-assign-issues.yml"
|
152
181
|
- ".gitignore"
|
153
182
|
- ".travis.yml"
|
183
|
+
- Appraisals
|
184
|
+
- CODEOWNERS
|
154
185
|
- Gemfile
|
155
186
|
- MIT-LICENSE
|
156
187
|
- README.md
|
157
188
|
- Rakefile
|
158
|
-
- gemfiles/
|
159
|
-
- gemfiles/
|
160
|
-
- gemfiles/
|
189
|
+
- gemfiles/activesupport_3.gemfile
|
190
|
+
- gemfiles/activesupport_4.gemfile
|
191
|
+
- gemfiles/activesupport_50.gemfile
|
192
|
+
- gemfiles/activesupport_51.gemfile
|
193
|
+
- gemfiles/activesupport_52.gemfile
|
161
194
|
- lib/active_support/cache/redis_store.rb
|
162
195
|
- lib/redis-activesupport.rb
|
163
196
|
- lib/redis/active_support/version.rb
|
@@ -168,7 +201,7 @@ homepage: http://redis-store.org/redis-activesupport
|
|
168
201
|
licenses:
|
169
202
|
- MIT
|
170
203
|
metadata: {}
|
171
|
-
post_install_message:
|
204
|
+
post_install_message:
|
172
205
|
rdoc_options: []
|
173
206
|
require_paths:
|
174
207
|
- lib
|
@@ -183,9 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
216
|
- !ruby/object:Gem::Version
|
184
217
|
version: '0'
|
185
218
|
requirements: []
|
186
|
-
|
187
|
-
|
188
|
-
signing_key:
|
219
|
+
rubygems_version: 3.1.2
|
220
|
+
signing_key:
|
189
221
|
specification_version: 4
|
190
222
|
summary: Redis store for ActiveSupport
|
191
223
|
test_files:
|
@@ -1,13 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gem 'redis-store', '~> 1.1.0'
|
4
|
-
gem 'activesupport', '~> 3'
|
5
|
-
|
6
|
-
group :development do
|
7
|
-
gem 'rake', '~> 10'
|
8
|
-
gem 'bundler', '~> 1.3'
|
9
|
-
gem 'mocha', '~> 0.14.0'
|
10
|
-
gem 'minitest', '~> 4.2'
|
11
|
-
gem 'connection_pool', '~> 1.2.0'
|
12
|
-
gem 'redis-store-testing'
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gem 'redis-store', '~> 1.1.0'
|
4
|
-
gem 'activesupport', '~> 4'
|
5
|
-
|
6
|
-
group :development do
|
7
|
-
gem 'rake', '~> 10'
|
8
|
-
gem 'bundler', '~> 1.3'
|
9
|
-
gem 'mocha', '~> 0.14.0'
|
10
|
-
gem 'minitest', '~> 4.2'
|
11
|
-
gem 'connection_pool', '~> 1.2.0'
|
12
|
-
gem 'redis-store-testing'
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gem 'redis-store', '~> 1.1.0'
|
4
|
-
gem 'activesupport', '>= 5.0.0.beta1', '< 5.1'
|
5
|
-
|
6
|
-
group :development do
|
7
|
-
gem 'rake', '~> 10'
|
8
|
-
gem 'bundler', '~> 1.3'
|
9
|
-
gem 'mocha', '~> 0.14.0'
|
10
|
-
gem 'minitest', '~> 5.1'
|
11
|
-
gem 'connection_pool', '~> 1.2.0'
|
12
|
-
gem 'redis-store-testing'
|
13
|
-
end
|