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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +4 -3
- data/bin/try +2 -2
- data/lib/redis/reconnect_with_readonly.rb +34 -33
- data/lib/redis/reconnect_with_readonly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85ea1bdc6974e919bd9c1e8489ab468c94a45177
|
4
|
+
data.tar.gz: dae0a9aac547e3b4a167dfc377f9941cb5619309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dda7397c1be54f2d14cc69db36f7161ca6c803f4a9f651491c469d69a3d0e6a31a7dc8ed6517436f7cd58a54568927af482fefe181563216ed964396e98f338
|
7
|
+
data.tar.gz: c018f556bb3e88278da33e880cf3565acb2e7004b3118fd5720e65d39434f0be1896d8c158975441bcedc15e629fcf02fa6f2741cda39c064b886259c182ed41
|
data/CHANGELOG.md
CHANGED
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
|
37
|
-
Redis::ReconnectWithReadonly.initial_retry_wait = 1.0
|
38
|
-
Redis::ReconnectWithReadonly.max_retry_wait = 5.0
|
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
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2016-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|