redis-reconnect_with_readonly 0.1.1 → 0.9.0
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 +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +9 -5
- data/bin/try +2 -1
- data/lib/redis/reconnect_with_readonly.rb +8 -8
- 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: cbdb865f95527d8a9e8ab4fc749d30f7b9cf6947
|
4
|
+
data.tar.gz: b6a976fc9d8e32d30bf1c146b28d407564850659
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9cb7e568d9578ea7ac101957433cd70b433f8d2779516790f7a7749e00133e752623d11fb6b6250636024181f5e9337d7b554b12f4108172f3e0d1f56d91f3d
|
7
|
+
data.tar.gz: 0c221329b3f884417b1e8b5123024bf374832947aba838120885898038bf713cb7877efbfb788647a1eea23fe4deb0b9825f1739b6f4e720e7daf8a81a1d04ad
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# 0.9.0 (2016-08-25)
|
2
|
+
|
3
|
+
Enhancements:
|
4
|
+
|
5
|
+
* Add `initial_retry_wait`
|
6
|
+
|
7
|
+
Changes:
|
8
|
+
|
9
|
+
* Rename `max_retry_interval` to `max_retry_wait`
|
10
|
+
* Change wait formula from `initial_retry_wait ^ number of retries` to `initial_retry_wait * number of retries`
|
11
|
+
|
1
12
|
# 0.1.1 (2016-08-24)
|
2
13
|
|
3
14
|
* Make configurable `reconnect_attempts` and `max_retry_interval`
|
@@ -5,4 +16,3 @@
|
|
5
16
|
# 0.1.0 (2016-08-24)
|
6
17
|
|
7
18
|
First version
|
8
|
-
|
data/README.md
CHANGED
@@ -29,12 +29,13 @@ require 'redis/reconnect_with_readonly'
|
|
29
29
|
## Configuration
|
30
30
|
|
31
31
|
This gem tries reconnection `reconnect_attempts` times.
|
32
|
-
It will wait `
|
33
|
-
The waiting
|
32
|
+
It will wait `initial_retry_wait * number of retries` second wait on each retry.
|
33
|
+
The waiting wait can be suppressed up to `max_retry_wait`.
|
34
34
|
|
35
35
|
```
|
36
|
-
Redis::ReconnectWithReadonly.reconnect_attempts =
|
37
|
-
Redis::ReconnectWithReadonly.
|
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)
|
38
39
|
```
|
39
40
|
|
40
41
|
## Implementation
|
@@ -61,9 +62,12 @@ $ bin/console
|
|
61
62
|
|
62
63
|
## Contributing
|
63
64
|
|
64
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sonots/redis-reconnect_with_readonly. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
65
66
|
|
66
67
|
## License
|
67
68
|
|
68
69
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
69
70
|
|
71
|
+
## ChangeLog
|
72
|
+
|
73
|
+
[CHANGELOG.md](./CHANGELOG.md)
|
data/bin/try
CHANGED
@@ -5,7 +5,8 @@ require "redis/reconnect_with_readonly"
|
|
5
5
|
require 'logger'
|
6
6
|
|
7
7
|
Redis::ReconnectWithReadonly.reconnect_attempts = 5
|
8
|
-
Redis::ReconnectWithReadonly.
|
8
|
+
Redis::ReconnectWithReadonly.initial_retry_wait = 1
|
9
|
+
Redis::ReconnectWithReadonly.max_retry_wait = 3
|
9
10
|
|
10
11
|
logger = Logger.new(STDOUT)
|
11
12
|
redis = Redis.new(host: 'localhost', port: '6380', logger: logger)
|
@@ -5,18 +5,17 @@ require 'redis/errors'
|
|
5
5
|
|
6
6
|
class Redis
|
7
7
|
class ReconnectWithReadonly
|
8
|
-
@reconnect_attempts
|
9
|
-
@
|
8
|
+
@reconnect_attempts = 3
|
9
|
+
@initial_retry_wait = 0.5
|
10
|
+
@max_retry_wait = nil
|
10
11
|
|
11
12
|
class << self
|
12
|
-
attr_accessor :reconnect_attempts, :
|
13
|
+
attr_accessor :reconnect_attempts, :initial_retry_wait, :max_retry_wait
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
class Redis
|
18
|
-
class ReadonlyConnectionError < ConnectionError; end
|
19
|
-
|
20
19
|
class Client
|
21
20
|
def reconnect_with_readonly(&block)
|
22
21
|
retries = 0
|
@@ -25,12 +24,13 @@ class Redis
|
|
25
24
|
rescue CommandError => e
|
26
25
|
if e.message =~ /READONLY/
|
27
26
|
if retries < (max_retries = ReconnectWithReadonly.reconnect_attempts)
|
28
|
-
|
27
|
+
wait = ReconnectWithReadonly.initial_retry_wait * retries
|
28
|
+
wait = [wait, ReconnectWithReadonly.max_retry_wait].min if ReconnectWithReadonly.max_retry_wait
|
29
29
|
logger.info {
|
30
30
|
"Reconnect with readonly: #{e.message} " \
|
31
|
-
"(retries: #{retries}/#{max_retries}) (wait: #{
|
31
|
+
"(retries: #{retries}/#{max_retries}) (wait: #{wait}sec)"
|
32
32
|
} if logger
|
33
|
-
sleep
|
33
|
+
sleep wait
|
34
34
|
retries += 1
|
35
35
|
retry
|
36
36
|
else
|
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.
|
4
|
+
version: 0.9.0
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|