redis-activesupport 5.0.7 → 5.2.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a846eea37c0ff4100e7d31590cf05e621192ae2
4
- data.tar.gz: b02058a9fc69299ec9306796df202d64e1c6f4d7
3
+ metadata.gz: 9e2dae1b761efefc450f3d0058ac0e4079b7e3cc
4
+ data.tar.gz: 066cc4f56fa42e97f9b0d83c04cdc5bb70062dd3
5
5
  SHA512:
6
- metadata.gz: ff311cba47a47387cab50b61b6f62f3f01428828e0c1a446040e752fdebc9e3494317413e52d7058805d162fbeccc5c4c6c7d5b2fbd2d632efaf8720266a72e4
7
- data.tar.gz: 9f6b6d1a4c639ded371d22afeee967896a0917644cf4e42cc321c39e6ac071ffd0b1dc0b958d0a0db6311f81e00818d1fe7e9a1dafbc7bc5f350ed614edd4a4c
6
+ metadata.gz: 94636bbc45b68dfa930864d90d090d9bef4e7bd2bb59e114f5efe06bd3f3f18cfdf474e34fe9e7f4bf9b15ab5b51c42aad4a3ad12b9a374fe6311e0c78c661da
7
+ data.tar.gz: c1ebf00acb907f9d5047d8cab835c0d76e78e91a01355e0fe25f2e754b294d83118398db3c4b690b5c3194b25875182cf1e4b2c2ef5e0c27a5f49744682f6f4e
@@ -14,10 +14,19 @@ matrix:
14
14
  allow_failures:
15
15
  - rvm: jruby-head
16
16
  - rvm: ruby-head
17
+ exclude:
17
18
  - rvm: 2.0
18
- gemfile: gemfiles/Gemfile.activesupport-5.x
19
+ gemfile: gemfiles/activesupport_50.gemfile
19
20
  - rvm: 2.1
20
- gemfile: gemfiles/Gemfile.activesupport-5.x
21
+ gemfile: gemfiles/activesupport_50.gemfile
22
+ - rvm: 2.0
23
+ gemfile: gemfiles/activesupport_51.gemfile
24
+ - rvm: 2.1
25
+ gemfile: gemfiles/activesupport_51.gemfile
26
+ - rvm: 2.0
27
+ gemfile: gemfiles/activesupport_52.gemfile
28
+ - rvm: 2.1
29
+ gemfile: gemfiles/activesupport_52.gemfile
21
30
  notifications:
22
31
  webhooks: https://www.travisbuddy.com/
23
32
  on_success: never
@@ -13,6 +13,12 @@ module ActiveSupport
13
13
  Redis::BaseConnectionError
14
14
  ].freeze
15
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
+
16
22
  attr_reader :data
17
23
 
18
24
  # Instantiate the store.
@@ -65,16 +71,18 @@ module ActiveSupport
65
71
  ::Redis::Store::Factory.create(*addresses, @options)
66
72
  end
67
73
 
74
+ @error_handler = @options[:error_handler] || DEFAULT_ERROR_HANDLER
75
+
68
76
  super(@options)
69
77
  end
70
78
 
71
79
  def write(name, value, options = nil)
72
80
  options = merged_options(options)
73
81
  instrument(:write, name, options) do |payload|
74
- entry = options[:raw].present? ? value : Entry.new(value, options)
75
82
  if options[:expires_in].present? && options[:race_condition_ttl].present? && options[:raw].blank?
76
83
  options[:expires_in] = options[:expires_in].to_f + options[:race_condition_ttl].to_f
77
84
  end
85
+ entry = options[:raw].present? ? value : Entry.new(value, options)
78
86
  write_entry(normalize_key(name, options), entry, options)
79
87
  end
80
88
  end
@@ -91,14 +99,13 @@ module ActiveSupport
91
99
  def delete_matched(matcher, options = nil)
92
100
  options = merged_options(options)
93
101
  instrument(:delete_matched, matcher.inspect) do
94
- matcher = key_matcher(matcher, options)
95
- begin
96
- with do |store|
97
- !(keys = store.keys(matcher)).empty? && store.del(*keys)
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
98
108
  end
99
- rescue *ERRORS_TO_RESCUE
100
- raise if raise_errors?
101
- false
102
109
  end
103
110
  end
104
111
  end
@@ -118,16 +125,15 @@ module ActiveSupport
118
125
  args.flatten!
119
126
 
120
127
  instrument(:read_multi, names) do |payload|
121
- values = with { |c| c.mget(*args) }
122
- values.map! { |v| v.is_a?(ActiveSupport::Cache::Entry) ? v.value : v }
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 }
123
131
 
124
- Hash[names.zip(values)].reject{|k,v| v.nil?}.tap do |result|
125
- payload[:hits] = result.keys if payload
132
+ Hash[names.zip(values)].reject{|k,v| v.nil?}.tap do |result|
133
+ payload[:hits] = result.keys if payload
134
+ end
126
135
  end
127
136
  end
128
- rescue *ERRORS_TO_RESCUE
129
- raise if raise_errors?
130
- {}
131
137
  end
132
138
 
133
139
  def fetch_multi(*names)
@@ -147,7 +153,7 @@ module ActiveSupport
147
153
  memo
148
154
  end
149
155
 
150
- begin
156
+ failsafe(:fetch_multi_write) do
151
157
  with do |c|
152
158
  c.multi do
153
159
  need_writes.each do |name, value|
@@ -155,8 +161,6 @@ module ActiveSupport
155
161
  end
156
162
  end
157
163
  end
158
- rescue *ERRORS_TO_RESCUE
159
- raise if raise_errors?
160
164
  end
161
165
 
162
166
  fetched
@@ -186,7 +190,9 @@ module ActiveSupport
186
190
  def increment(key, amount = 1, options = {})
187
191
  options = merged_options(options)
188
192
  instrument(:increment, key, :amount => amount) do
189
- with{|c| c.incrby normalize_key(key, options), amount}
193
+ failsafe(:increment) do
194
+ with{|c| c.incrby normalize_key(key, options), amount}
195
+ end
190
196
  end
191
197
  end
192
198
 
@@ -214,7 +220,9 @@ module ActiveSupport
214
220
  def decrement(key, amount = 1, options = {})
215
221
  options = merged_options(options)
216
222
  instrument(:decrement, key, :amount => amount) do
217
- with{|c| c.decrby normalize_key(key, options), amount}
223
+ failsafe(:decrement) do
224
+ with{|c| c.decrby normalize_key(key, options), amount}
225
+ end
218
226
  end
219
227
  end
220
228
 
@@ -226,7 +234,9 @@ module ActiveSupport
226
234
  # Clear all the data from the store.
227
235
  def clear
228
236
  instrument(:clear, nil, nil) do
229
- with(&:flushdb)
237
+ failsafe(:clear) do
238
+ with(&:flushdb)
239
+ end
230
240
  end
231
241
  end
232
242
 
@@ -255,20 +265,18 @@ module ActiveSupport
255
265
 
256
266
  protected
257
267
  def write_entry(key, entry, options)
258
- method = options && options[:unless_exist] ? :setnx : :set
259
- with { |client| client.send method, key, entry, options }
260
- rescue *ERRORS_TO_RESCUE
261
- raise if raise_errors?
262
- false
268
+ failsafe(:write_entry, returning: false) do
269
+ method = options && options[:unless_exist] ? :setnx : :set
270
+ with { |client| client.send method, key, entry, options }
271
+ end
263
272
  end
264
273
 
265
274
  def read_entry(key, options)
266
- entry = with { |c| c.get key, options }
267
- return unless entry
268
- entry.is_a?(Entry) ? entry : Entry.new(entry)
269
- rescue *ERRORS_TO_RESCUE
270
- raise if raise_errors?
271
- nil
275
+ failsafe(:read_entry) do
276
+ entry = with { |c| c.get key, options }
277
+ return unless entry
278
+ entry.is_a?(Entry) ? entry : Entry.new(entry)
279
+ end
272
280
  end
273
281
 
274
282
  ##
@@ -277,10 +285,9 @@ module ActiveSupport
277
285
  # It's really needed and use
278
286
  #
279
287
  def delete_entry(key, options)
280
- with { |c| c.del key }
281
- rescue *ERRORS_TO_RESCUE
282
- raise if raise_errors?
283
- false
288
+ failsafe(:delete_entry, returning: false) do
289
+ with { |c| c.del key }
290
+ end
284
291
  end
285
292
 
286
293
  def raise_errors?
@@ -305,12 +312,27 @@ module ActiveSupport
305
312
  end
306
313
 
307
314
  private
308
-
309
315
  if ActiveSupport::VERSION::MAJOR < 5
310
316
  def normalize_key(*args)
311
317
  namespaced_key(*args)
312
318
  end
313
319
  end
320
+
321
+ def failsafe(method, returning: nil)
322
+ yield
323
+ rescue ::Redis::BaseConnectionError => e
324
+ raise if raise_errors?
325
+ handle_exception(exception: e, method: method, returning: returning)
326
+ returning
327
+ end
328
+
329
+ def handle_exception(exception: nil, method: nil, returning: nil)
330
+ if @error_handler
331
+ @error_handler.(method: method, exception: exception, returning: returning)
332
+ end
333
+ rescue => failsafe
334
+ warn("RedisStore ignored exception in handle_exception: #{failsafe.class}: #{failsafe.message}\n #{failsafe.backtrace.join("\n ")}")
335
+ end
314
336
  end
315
337
  end
316
338
  end
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  module ActiveSupport
3
- VERSION = '5.0.7'
3
+ VERSION = '5.2.0.pre'
4
4
  end
5
5
  end
@@ -377,7 +377,7 @@ describe ActiveSupport::Cache::RedisStore do
377
377
 
378
378
  describe "race_condition_ttl on fetch" do
379
379
  it "persist entry for longer than given ttl" do
380
- options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds }
380
+ options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds, version: Time.now.to_i }
381
381
  @store.fetch("rabbit", options) { @rabbit }
382
382
  sleep 1.1
383
383
  @store.delete("rabbit").must_equal(1)
@@ -385,12 +385,12 @@ describe ActiveSupport::Cache::RedisStore do
385
385
 
386
386
  it "limits stampede time to read-write duration" do
387
387
  first_rabbit = second_rabbit = nil
388
- options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds }
388
+ options = { force: true, expires_in: 1.second, race_condition_ttl: 2.seconds, version: Time.now.to_i }
389
389
  @store.fetch("rabbit", options) { @rabbit }
390
390
  sleep 1
391
391
 
392
392
  th1 = Thread.new do
393
- first_rabbit = @store.fetch("rabbit", race_condition_ttl: 2) do
393
+ first_rabbit = @store.fetch("rabbit", options) do
394
394
  sleep 1
395
395
  @white_rabbit
396
396
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-activesupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.7
4
+ version: 5.2.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-07-13 00:00:00.000000000 Z
12
+ date: 2018-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis-store
@@ -196,9 +196,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ">="
199
+ - - ">"
200
200
  - !ruby/object:Gem::Version
201
- version: '0'
201
+ version: 1.3.1
202
202
  requirements: []
203
203
  rubyforge_project: redis-activesupport
204
204
  rubygems_version: 2.6.14