redis-reconnect_with_readonly 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/redis/reconnect_with_readonly.rb +26 -25
- data/lib/redis/reconnect_with_readonly/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b4061788f20bca31f019b8768df6d3170635c02
|
4
|
+
data.tar.gz: e5f7e654372eb55d40e3f6edc96daafc747ecccd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d570f5e027a44faa2330eb28140e1c6732adccbab836613d7f8a5587c2d685806110d93313ed4b7121ddf02c4b010eadebf154f0ebf0b805328cfcf4280bff5
|
7
|
+
data.tar.gz: fb346107919e998637c6a31bae03ff8ab44b6cad7e5fcf5c9d9355c634a410643a481aee3f9cded50c4ad9e998cae1d9c48894d1d282f33fcafad9e7a4231965
|
data/CHANGELOG.md
CHANGED
@@ -12,34 +12,35 @@ class Redis
|
|
12
12
|
|
13
13
|
class << self
|
14
14
|
attr_accessor :reconnect_attempts, :initial_retry_wait, :max_retry_wait, :logger
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
else
|
35
|
-
logger.info {
|
36
|
-
"Reconnect with readonly: Give up " \
|
37
|
-
"(retries: #{retries}/#{reconnect_attempts})"
|
38
|
-
} if logger
|
39
|
-
end
|
17
|
+
def self.reconnect_with_readonly(redis, &block)
|
18
|
+
retries = 0
|
19
|
+
begin
|
20
|
+
yield block
|
21
|
+
rescue CommandError => e
|
22
|
+
if e.message =~ /READONLY/
|
23
|
+
if retries < reconnect_attempts
|
24
|
+
wait = initial_retry_wait * retries
|
25
|
+
wait = [wait, max_retry_wait].min if max_retry_wait
|
26
|
+
logger.info {
|
27
|
+
"Reconnect with readonly: #{e.message} " \
|
28
|
+
"(retries: #{retries}/#{reconnect_attempts}) (wait: #{wait}sec)"
|
29
|
+
} if logger
|
30
|
+
sleep wait
|
31
|
+
retries += 1
|
32
|
+
redis.disconnect
|
33
|
+
logger.debug { "Reconnect with readonly: disconnected and retry" } if logger
|
34
|
+
retry
|
40
35
|
else
|
41
|
-
|
36
|
+
logger.info {
|
37
|
+
"Reconnect with readonly: Give up " \
|
38
|
+
"(retries: #{retries}/#{reconnect_attempts})"
|
39
|
+
} if logger
|
40
|
+
raise e
|
42
41
|
end
|
42
|
+
else
|
43
|
+
raise e
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|