redic-sentinels 0.1.0 → 0.2.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/README.md +2 -2
- data/lib/redic/sentinels/version.rb +1 -1
- data/lib/redic/sentinels.rb +31 -13
- data/spec/coverage_helper.rb +5 -0
- data/spec/minitest_helper.rb +1 -3
- data/spec/sentinels_spec.rb +13 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00f2c98ea246c4dee97dca3fe3757fec01f0b1e3
|
4
|
+
data.tar.gz: 5c871add547ae0d15a034886e5480f284f000e7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6740acd8892fe316e54a0af8847cb1a110e9e618c461e2c2cd08e68458b06f389e49a2a1cbf24e85146269c50f08d61b922073988e7e74626146534f95fae982
|
7
|
+
data.tar.gz: 06188323e825f5db6efe3aac9d2546d1c20491c89ff6b6cccdd1ae543c21a09312b780d4fe7f52e235a43cf276b4143f68cf1b7f4214c126dd3dbf52aedaf9f6
|
data/README.md
CHANGED
@@ -29,13 +29,13 @@ Or install it yourself as:
|
|
29
29
|
## Usage
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
|
32
|
+
hosts = [
|
33
33
|
'localhost:26379',
|
34
34
|
'localhost:26380',
|
35
35
|
'localhost:26381'
|
36
36
|
]
|
37
37
|
|
38
|
-
redis = Redic::Sentinels.new
|
38
|
+
redis = Redic::Sentinels.new hosts: hosts,
|
39
39
|
master_name: 'mymaster',
|
40
40
|
db: 1, # optional (default: 0)
|
41
41
|
password: 'pass' # optional
|
data/lib/redic/sentinels.rb
CHANGED
@@ -8,10 +8,10 @@ class Redic
|
|
8
8
|
class UnreachableHosts < ArgumentError; end
|
9
9
|
class UnknownMaster < ArgumentError; end
|
10
10
|
|
11
|
-
attr_reader :hosts, :master_name, :password, :db, :timeout
|
11
|
+
attr_reader :hosts, :master_name, :password, :db, :timeout
|
12
12
|
|
13
13
|
def initialize(options)
|
14
|
-
@hosts
|
14
|
+
@hosts = options.fetch(:hosts)
|
15
15
|
@master_name = options.fetch(:master_name)
|
16
16
|
@password = options[:password]
|
17
17
|
@db = options.fetch(:db, 0)
|
@@ -21,32 +21,50 @@ class Redic
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def call(*args)
|
24
|
-
forward {
|
24
|
+
forward { redis.call *args }
|
25
25
|
end
|
26
26
|
|
27
27
|
def call!(*args)
|
28
|
-
forward {
|
28
|
+
forward { redis.call! *args }
|
29
29
|
end
|
30
30
|
|
31
31
|
def queue(*args)
|
32
|
-
forward {
|
33
|
-
end
|
34
|
-
|
35
|
-
def clear
|
36
|
-
forward { client.clear }
|
32
|
+
forward { redis.queue *args }
|
37
33
|
end
|
38
34
|
|
39
35
|
def commit
|
40
|
-
buffer =
|
36
|
+
buffer = redis.buffer
|
41
37
|
|
42
38
|
forward do
|
43
|
-
|
44
|
-
|
39
|
+
redis.buffer.replace(buffer)
|
40
|
+
redis.commit
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
44
|
+
def buffer
|
45
|
+
forward { redis.buffer }
|
46
|
+
end
|
47
|
+
|
48
|
+
def reset
|
49
|
+
forward { redis.reset }
|
50
|
+
end
|
51
|
+
|
52
|
+
def clear
|
53
|
+
forward { redis.clear }
|
54
|
+
end
|
55
|
+
|
56
|
+
def client
|
57
|
+
forward { redis.client }
|
58
|
+
end
|
59
|
+
|
60
|
+
def url
|
61
|
+
forward { redis.url }
|
62
|
+
end
|
63
|
+
|
48
64
|
private
|
49
65
|
|
66
|
+
attr_reader :redis
|
67
|
+
|
50
68
|
def forward
|
51
69
|
yield
|
52
70
|
rescue Errno::ECONNREFUSED
|
@@ -62,7 +80,7 @@ class Redic
|
|
62
80
|
ip, port = sentinel.call 'SENTINEL', 'get-master-addr-by-name', master_name
|
63
81
|
raise UnknownMaster if ip.nil? && port.nil?
|
64
82
|
|
65
|
-
@
|
83
|
+
@redis = Redic.new *["redis://#{password ? ":#{password}@" : ''}#{ip}:#{port}/#{db}", timeout].compact
|
66
84
|
return
|
67
85
|
|
68
86
|
rescue Errno::ECONNREFUSED
|
data/spec/minitest_helper.rb
CHANGED
data/spec/sentinels_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe Redic::Sentinels do
|
|
18
18
|
MASTER_NAME = 'mymaster'
|
19
19
|
|
20
20
|
def disconnect(redis)
|
21
|
-
redis.client.configure "redis://#{INVALID_HOSTS.sample}"
|
21
|
+
redis.client.configure "redis://#{INVALID_HOSTS.sample}", 10_000_000
|
22
22
|
end
|
23
23
|
|
24
24
|
after do
|
@@ -46,12 +46,18 @@ describe Redic::Sentinels do
|
|
46
46
|
redis.commit.must_equal ['PONG', 'PONG']
|
47
47
|
end
|
48
48
|
|
49
|
-
it 'clear' do
|
49
|
+
it 'clear/reset' do
|
50
50
|
redis.queue 'PING'
|
51
|
-
redis.
|
51
|
+
redis.buffer.must_equal [['PING']]
|
52
52
|
|
53
53
|
redis.clear
|
54
|
-
redis.
|
54
|
+
redis.buffer.must_be_empty
|
55
|
+
|
56
|
+
redis.queue 'PING'
|
57
|
+
redis.buffer.must_equal [['PING']]
|
58
|
+
|
59
|
+
redis.reset
|
60
|
+
redis.buffer.must_be_empty
|
55
61
|
end
|
56
62
|
|
57
63
|
it 'get/set' do
|
@@ -75,17 +81,17 @@ describe Redic::Sentinels do
|
|
75
81
|
end
|
76
82
|
|
77
83
|
it 'Default DB' do
|
78
|
-
redis.
|
84
|
+
redis.url.must_equal 'redis://127.0.0.1:16379/0'
|
79
85
|
end
|
80
86
|
|
81
87
|
it 'Custom DB' do
|
82
88
|
redis = Redic::Sentinels.new hosts: HOSTS, master_name: MASTER_NAME, db: 7
|
83
|
-
redis.
|
89
|
+
redis.url.must_equal 'redis://127.0.0.1:16379/7'
|
84
90
|
end
|
85
91
|
|
86
92
|
it 'Auth' do
|
87
93
|
redis = Redic::Sentinels.new hosts: HOSTS, master_name: MASTER_NAME, password: 'pass'
|
88
|
-
redis.
|
94
|
+
redis.url.must_equal 'redis://:pass@127.0.0.1:16379/0'
|
89
95
|
end
|
90
96
|
|
91
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redic-sentinels
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redic
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- lib/redic/sentinels.rb
|
163
163
|
- lib/redic/sentinels/version.rb
|
164
164
|
- redic-sentinels.gemspec
|
165
|
+
- spec/coverage_helper.rb
|
165
166
|
- spec/minitest_helper.rb
|
166
167
|
- spec/sentinels_spec.rb
|
167
168
|
homepage: https://github.com/gabynaiman/redic-sentinels
|
@@ -190,5 +191,6 @@ specification_version: 4
|
|
190
191
|
summary: Redic::Sentinels is a wrapper for the Redis client that fetches configuration
|
191
192
|
details from sentinels
|
192
193
|
test_files:
|
194
|
+
- spec/coverage_helper.rb
|
193
195
|
- spec/minitest_helper.rb
|
194
196
|
- spec/sentinels_spec.rb
|