redis-sentinel 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/redis-sentinel/client.rb +5 -9
- data/lib/redis-sentinel/version.rb +1 -1
- data/spec/redis-sentinel/client_spec.rb +17 -32
- 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: 20c20d9586d8c9751e1ec9e9dff72133a6c07854
|
4
|
+
data.tar.gz: 9d5e482d914cc224b46061a846468c285368b85a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0f05568866ee3a20d2ed22784fd93488e7ad00a9f41064973eee7e561a98463cc5f802466bb1f2e568a7caf9b22556c0a2ecbb34c29ecda406a59c8e4354eb0
|
7
|
+
data.tar.gz: 0a0e3dd641a640f9819f1aa84ca63a45e6c9aca77e874c21abc6f0a1cc182456bd5c4ad504561306d31f8ad1797e73ab0fded4445356d61347ae7e8b46006805
|
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,6 @@ class Redis::Client
|
|
5
5
|
|
6
6
|
class_eval do
|
7
7
|
attr_reader :current_sentinel
|
8
|
-
attr_reader :current_sentinel_options
|
9
8
|
|
10
9
|
def initialize_with_sentinel(options={})
|
11
10
|
options = options.dup # Don't touch my options
|
@@ -53,20 +52,17 @@ class Redis::Client
|
|
53
52
|
|
54
53
|
def try_next_sentinel
|
55
54
|
sentinel_options = @sentinels_options.shift
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
else
|
61
|
-
raise Redis::CannotConnectError
|
62
|
-
end
|
55
|
+
@sentinels_options.push sentinel_options
|
56
|
+
|
57
|
+
@logger.debug "Trying next sentinel: #{sentinel_options[:host]}:#{sentinel_options[:port]}" if @logger && @logger.debug?
|
58
|
+
@current_sentinel = Redis.new sentinel_options
|
63
59
|
end
|
64
60
|
|
65
61
|
def refresh_sentinels_list
|
66
62
|
responses = current_sentinel.sentinel("sentinels", @master_name)
|
67
63
|
@sentinels_options = responses.map do |response|
|
68
64
|
{:host => response[3], :port => response[5]}
|
69
|
-
end.unshift(:host =>
|
65
|
+
end.unshift(:host => current_sentinel.host, :port => current_sentinel.port)
|
70
66
|
end
|
71
67
|
|
72
68
|
def discover_master
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Redis::Client do
|
4
4
|
let(:client) { double("Client", :reconnect => true) }
|
5
|
-
let(:
|
5
|
+
let(:current_sentinel) { double("Redis", :client => client, :host => "localhost", :port => 26379) }
|
6
6
|
|
7
7
|
let(:sentinels) do
|
8
8
|
[
|
@@ -14,9 +14,7 @@ describe Redis::Client do
|
|
14
14
|
subject { Redis::Client.new(:master_name => "master", :master_password => "foobar",
|
15
15
|
:sentinels => sentinels) }
|
16
16
|
|
17
|
-
before
|
18
|
-
allow(Redis).to receive(:new).and_return(redis)
|
19
|
-
end
|
17
|
+
before { allow(Redis).to receive(:new).and_return(current_sentinel) }
|
20
18
|
|
21
19
|
context "#sentinel?" do
|
22
20
|
it "should be true if passing sentiels and master_name options" do
|
@@ -50,25 +48,14 @@ describe Redis::Client do
|
|
50
48
|
|
51
49
|
context "#try_next_sentinel" do
|
52
50
|
it "returns next sentinel server" do
|
53
|
-
expect(
|
54
|
-
subject.try_next_sentinel
|
55
|
-
end
|
56
|
-
|
57
|
-
it "raises an error if no available sentinel server" do
|
58
|
-
client = Redis::Client.new(
|
59
|
-
:master_name => "master",
|
60
|
-
:sentinels => []
|
61
|
-
)
|
62
|
-
expect { client.try_next_sentinel }.to raise_error(Redis::CannotConnectError)
|
51
|
+
expect(subject.try_next_sentinel).to eq current_sentinel
|
63
52
|
end
|
64
53
|
end
|
65
54
|
|
66
55
|
context "#refresh_sentinels_list" do
|
67
56
|
it "gets all sentinels list" do
|
68
|
-
|
69
|
-
|
70
|
-
expect(subject).to receive(:current_sentinel).and_return(sentinel)
|
71
|
-
expect(sentinel).to receive(:sentinel).with("sentinels", "master").and_return([
|
57
|
+
allow(subject).to receive(:current_sentinel).and_return(current_sentinel)
|
58
|
+
expect(current_sentinel).to receive(:sentinel).with("sentinels", "master").and_return([
|
72
59
|
["name", "localhost:26381", "ip", "localhost", "port", 26380],
|
73
60
|
["name", "localhost:26381", "ip", "localhost", "port", 26381]
|
74
61
|
])
|
@@ -82,21 +69,22 @@ describe Redis::Client do
|
|
82
69
|
end
|
83
70
|
|
84
71
|
context "#discover_master" do
|
72
|
+
before do
|
73
|
+
allow(subject).to receive(:try_next_sentinel)
|
74
|
+
allow(subject).to receive(:refresh_sentinels_list)
|
75
|
+
allow(subject).to receive(:current_sentinel).and_return(current_sentinel)
|
76
|
+
end
|
77
|
+
|
85
78
|
it "updates master config options" do
|
86
|
-
expect(
|
87
|
-
expect(redis).to receive(:sentinel).with("sentinels", "master").and_return([{:host => "sentinel", :port => 8888}])
|
79
|
+
expect(current_sentinel).to receive(:sentinel).with("get-master-addr-by-name", "master").and_return(["master", 8888])
|
88
80
|
subject.discover_master
|
89
81
|
expect(subject.host).to eq "master"
|
90
82
|
expect(subject.port).to eq 8888
|
91
83
|
end
|
92
84
|
|
93
85
|
it "selects next sentinel if failed to connect to current_sentinel" do
|
94
|
-
expect(
|
95
|
-
expect(
|
96
|
-
sentinel = double('sentinel')
|
97
|
-
expect(subject).to receive(:current_sentinel).and_return(sentinel)
|
98
|
-
expect(sentinel).to receive(:sentinel).with("get-master-addr-by-name", "master").and_return(["master", 8888])
|
99
|
-
allow(subject).to receive(:refresh_sentinels_list)
|
86
|
+
expect(current_sentinel).to receive(:sentinel).with("get-master-addr-by-name", "master").and_raise(Redis::CannotConnectError)
|
87
|
+
expect(current_sentinel).to receive(:sentinel).with("get-master-addr-by-name", "master").and_return(["master", 8888])
|
100
88
|
subject.discover_master
|
101
89
|
expect(subject.host).to eq "master"
|
102
90
|
expect(subject.port).to eq 8888
|
@@ -114,9 +102,9 @@ describe Redis::Client do
|
|
114
102
|
|
115
103
|
it "does not sleep" do
|
116
104
|
expect(subject).not_to receive(:sleep)
|
117
|
-
expect
|
105
|
+
expect {
|
118
106
|
subject.auto_retry_with_timeout { raise Redis::CannotConnectError }
|
119
|
-
|
107
|
+
}.to raise_error(Redis::CannotConnectError)
|
120
108
|
end
|
121
109
|
end
|
122
110
|
|
@@ -176,10 +164,7 @@ describe Redis::Client do
|
|
176
164
|
|
177
165
|
context "#disconnect" do
|
178
166
|
it "calls disconnect on each sentinel client" do
|
179
|
-
|
180
|
-
client = double('client')
|
181
|
-
allow(subject).to receive(:current_sentinel).and_return(sentinel)
|
182
|
-
expect(sentinel).to receive(:client).and_return(client)
|
167
|
+
allow(subject).to receive(:current_sentinel).and_return(current_sentinel)
|
183
168
|
expect(client).to receive(:disconnect)
|
184
169
|
subject.disconnect
|
185
170
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-sentinel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|