redis-sentinel 1.4.0 → 1.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0abad2c1cbcc6e342c7f362b9d6c6ad6ebca6a81
4
- data.tar.gz: e300689d63cec3fec3f9d2ace82d61d828baf4b3
3
+ metadata.gz: 20c20d9586d8c9751e1ec9e9dff72133a6c07854
4
+ data.tar.gz: 9d5e482d914cc224b46061a846468c285368b85a
5
5
  SHA512:
6
- metadata.gz: 5472ab6c41d452eb5550ed58698871956a57deb51d354c95e154d768b4390871f3f302170ac03987029ad02a5973a471864e4034d2e0195385b9f4f6839d667f
7
- data.tar.gz: 4c781a86527902cfc4a9fee13b7b0139b39245eadb894f98647e2f3e0a158c5d5128d2218577830b1b1d0d22df963126a7c1f376522952eb1c1501e0f960eb59
6
+ metadata.gz: e0f05568866ee3a20d2ed22784fd93488e7ad00a9f41064973eee7e561a98463cc5f802466bb1f2e568a7caf9b22556c0a2ecbb34c29ecda406a59c8e4354eb0
7
+ data.tar.gz: 0a0e3dd641a640f9819f1aa84ca63a45e6c9aca77e874c21abc6f0a1cc182456bd5c4ad504561306d31f8ad1797e73ab0fded4445356d61347ae7e8b46006805
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.4.1
4
+
5
+ * Fix only one sentinel client reconnect issue
6
+
3
7
  ## 1.4.0
4
8
 
5
9
  * Rewrite sentinel client to follow http://redis.io/topics/sentinel
@@ -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
- if sentinel_options
57
- @logger.debug "Trying next sentinel: #{sentinel_options[:host]}:#{sentinel_options[:port]}" if @logger && @logger.debug?
58
- @current_sentinel_options = sentinel_options
59
- @current_sentinel = Redis.new sentinel_options
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 => current_sentinel_options[:host], :port => current_sentinel_options[:port])
65
+ end.unshift(:host => current_sentinel.host, :port => current_sentinel.port)
70
66
  end
71
67
 
72
68
  def discover_master
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  module Sentinel
3
- VERSION = "1.4.0"
3
+ VERSION = "1.4.1"
4
4
  end
5
5
  end
@@ -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(:redis) { double("Redis", :sentinel => ["remote.server", 8888], :client => client) }
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 do
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(Redis).to receive(:new).with(:host => "localhost", :port => 26379).and_return(redis)
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
- sentinel = double('sentinel')
69
- allow(subject).to receive(:current_sentinel_options).and_return(:host => "localhost", :port => 26379)
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(redis).to receive(:sentinel).with("get-master-addr-by-name", "master").and_return(["master", 8888])
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(subject).to receive(:current_sentinel).and_return(redis)
95
- expect(redis).to receive(:sentinel).with("get-master-addr-by-name", "master").and_raise(Redis::CannotConnectError)
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 do
105
+ expect {
118
106
  subject.auto_retry_with_timeout { raise Redis::CannotConnectError }
119
- end.to raise_error(Redis::CannotConnectError)
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
- sentinel = double('sentinel')
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.0
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-08 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis