redis-reconnect_with_readonly 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21d616b3294b61179b1704851f3524c4f0bf1be8
4
- data.tar.gz: 7d487051f5cd268ae1a7eb4c4b15245400ed320a
3
+ metadata.gz: 85ea1bdc6974e919bd9c1e8489ab468c94a45177
4
+ data.tar.gz: dae0a9aac547e3b4a167dfc377f9941cb5619309
5
5
  SHA512:
6
- metadata.gz: 6440817029e71d7c7a066f4cdf5a56d9481af40045f064607f04e26a5eea2f8714c91317fbdc10d1ee833acab3304743a65c822f5408013db883780ca5178037
7
- data.tar.gz: f35251da92d88a6695311008ba24e659e378ee0a0d2caa3166e603e5ea1d8c6f7deaecbed8ceacb08ee27513dc4d59f24338a994e6587b0548f034c0c9814c7f
6
+ metadata.gz: 3dda7397c1be54f2d14cc69db36f7161ca6c803f4a9f651491c469d69a3d0e6a31a7dc8ed6517436f7cd58a54568927af482fefe181563216ed964396e98f338
7
+ data.tar.gz: c018f556bb3e88278da33e880cf3565acb2e7004b3118fd5720e65d39434f0be1896d8c158975441bcedc15e629fcf02fa6f2741cda39c064b886259c182ed41
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.9.2 (2016-08-28)
2
+
3
+ Enhancements:
4
+
5
+ * Add logger option
6
+
1
7
  # 0.9.1 (2016-08-26)
2
8
 
3
9
  Fixes:
data/README.md CHANGED
@@ -33,9 +33,10 @@ It will wait `initial_retry_wait * number of retries` seconds on each retry.
33
33
  The waiting interval can be suppressed up to `max_retry_wait` seconds.
34
34
 
35
35
  ```
36
- Redis::ReconnectWithReadonly.reconnect_attempts = 10 # default: 3 (times)
37
- Redis::ReconnectWithReadonly.initial_retry_wait = 1.0 # default: 0.5 (sec)
38
- Redis::ReconnectWithReadonly.max_retry_wait = 5.0 # default: nil which means no max (sec)
36
+ Redis::ReconnectWithReadonly.reconnect_attempts = 10 # default: 3 (times)
37
+ Redis::ReconnectWithReadonly.initial_retry_wait = 1.0 # default: 0.5 (sec)
38
+ Redis::ReconnectWithReadonly.max_retry_wait = 5.0 # default: nil which means no max (sec)
39
+ Redis::ReconnectWithReadonly.logger = Logger.new(STDOUT) # default: nil
39
40
  ```
40
41
 
41
42
  ## Implementation
data/bin/try CHANGED
@@ -7,7 +7,7 @@ require 'logger'
7
7
  Redis::ReconnectWithReadonly.reconnect_attempts = 5
8
8
  Redis::ReconnectWithReadonly.initial_retry_wait = 1
9
9
  Redis::ReconnectWithReadonly.max_retry_wait = 3
10
+ Redis::ReconnectWithReadonly.logger = Logger.new(STDOUT)
10
11
 
11
- logger = Logger.new(STDOUT)
12
- redis = Redis.new(host: 'localhost', port: '6380', logger: logger)
12
+ redis = Redis.new(host: 'localhost', port: '6380')
13
13
  redis.set('key', 'val')
@@ -8,59 +8,60 @@ class Redis
8
8
  @reconnect_attempts = 3
9
9
  @initial_retry_wait = 0.5
10
10
  @max_retry_wait = nil
11
+ @logger = nil
11
12
 
12
13
  class << self
13
- attr_accessor :reconnect_attempts, :initial_retry_wait, :max_retry_wait
14
- end
15
- end
16
- end
14
+ attr_accessor :reconnect_attempts, :initial_retry_wait, :max_retry_wait, :logger
17
15
 
18
- class Redis
19
- class Client
20
- def reconnect_with_readonly(&block)
21
- retries = 0
22
- begin
23
- yield block
24
- rescue CommandError => e
25
- if e.message =~ /READONLY/
26
- if retries < (max_retries = ReconnectWithReadonly.reconnect_attempts)
27
- wait = ReconnectWithReadonly.initial_retry_wait * retries
28
- wait = [wait, ReconnectWithReadonly.max_retry_wait].min if ReconnectWithReadonly.max_retry_wait
29
- logger.info {
30
- "Reconnect with readonly: #{e.message} " \
31
- "(retries: #{retries}/#{max_retries}) (wait: #{wait}sec)"
32
- } if logger
33
- sleep wait
34
- retries += 1
35
- disconnect
36
- logger.debug { "Reconnect with readonly: disconnected and retry" } if logger
37
- retry
16
+ def reconnect_with_readonly(redis, &block)
17
+ retries = 0
18
+ begin
19
+ yield block
20
+ rescue CommandError => e
21
+ if e.message =~ /READONLY/
22
+ if retries < reconnect_attempts
23
+ wait = initial_retry_wait * retries
24
+ wait = [wait, max_retry_wait].min if max_retry_wait
25
+ logger.info {
26
+ "Reconnect with readonly: #{e.message} " \
27
+ "(retries: #{retries}/#{reconnect_attempts}) (wait: #{wait}sec)"
28
+ } if logger
29
+ sleep wait
30
+ retries += 1
31
+ redis.disconnect
32
+ logger.debug { "Reconnect with readonly: disconnected and retry" } if logger
33
+ retry
34
+ else
35
+ logger.info {
36
+ "Reconnect with readonly: Give up " \
37
+ "(retries: #{retries}/#{reconnect_attempts})"
38
+ } if logger
39
+ end
38
40
  else
39
- logger.info {
40
- "Reconnect with readonly: Give up " \
41
- "(retries: #{retries}/#{max_retries})"
42
- } if logger
41
+ raise
43
42
  end
44
- else
45
- raise
46
43
  end
47
44
  end
48
45
  end
46
+ end
47
+ end
49
48
 
49
+ class Redis
50
+ class Client
50
51
  def call_with_reconnect_with_readonly(command, &block)
51
- reconnect_with_readonly do
52
+ ReconnectWithReadonly.reconnect_with_readonly(self) do
52
53
  call_without_reconnect_with_readonly(command, &block)
53
54
  end
54
55
  end
55
56
 
56
57
  def call_loop_with_reconnect_with_readonly(command, &block)
57
- reconnect_with_readonly do
58
+ ReconnectWithReadonly.reconnect_with_readonly(self) do
58
59
  call_loop_without_reconnect_with_readonly(command, &block)
59
60
  end
60
61
  end
61
62
 
62
63
  def call_pipeline_with_reconnect_with_readonly(command, &block)
63
- reconnect_with_readonly do
64
+ ReconnectWithReadonly.reconnect_with_readonly(self) do
64
65
  call_pipeline_without_reconnect_with_readonly(command, &block)
65
66
  end
66
67
  end
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class ReconnectWithReadonly
3
- VERSION = "0.9.1"
3
+ VERSION = "0.9.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-reconnect_with_readonly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-25 00:00:00.000000000 Z
11
+ date: 2016-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis