redis-sentinel 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20c20d9586d8c9751e1ec9e9dff72133a6c07854
4
- data.tar.gz: 9d5e482d914cc224b46061a846468c285368b85a
3
+ metadata.gz: a79a501844ac25c4bdde61c4801a75e65d22bd0d
4
+ data.tar.gz: f40c099446f5b31cc8558aaacb06f8e325381d5f
5
5
  SHA512:
6
- metadata.gz: e0f05568866ee3a20d2ed22784fd93488e7ad00a9f41064973eee7e561a98463cc5f802466bb1f2e568a7caf9b22556c0a2ecbb34c29ecda406a59c8e4354eb0
7
- data.tar.gz: 0a0e3dd641a640f9819f1aa84ca63a45e6c9aca77e874c21abc6f0a1cc182456bd5c4ad504561306d31f8ad1797e73ab0fded4445356d61347ae7e8b46006805
6
+ metadata.gz: 83f3892eacb138abf90d169bb452dc59ff46d91cc25f2581c1278cbf48e026ccc16006db28d92b7041d8c8ce2d2331876619567e1287e713eb3910c27ec70596
7
+ data.tar.gz: 90c948ebe4d6bfa1a8a105d79d6e9569cd88cc63988f02c961c11a03f2c3450b63a02de33f6d38bfc1fef71e3b38ce14860f9219dc041bc6424a9a93d316d77e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.4.2
4
+
5
+ * Fix sentinel reconnection broken
6
+
3
7
  ## 1.4.1
4
8
 
5
9
  * Fix only one sentinel client reconnect issue
@@ -36,7 +36,7 @@ class Redis::Client
36
36
  alias connect connect_with_sentinel
37
37
 
38
38
  def sentinel?
39
- @master_name && @sentinels_options
39
+ !!(@master_name && @sentinels_options)
40
40
  end
41
41
 
42
42
  def auto_retry_with_timeout(&block)
@@ -59,10 +59,10 @@ class Redis::Client
59
59
  end
60
60
 
61
61
  def refresh_sentinels_list
62
- responses = current_sentinel.sentinel("sentinels", @master_name)
63
- @sentinels_options = responses.map do |response|
64
- {:host => response[3], :port => response[5]}
65
- end.unshift(:host => current_sentinel.host, :port => current_sentinel.port)
62
+ current_sentinel.sentinel("sentinels", @master_name).each do |response|
63
+ @sentinels_options << {:host => response[3], :port => response[5]}
64
+ end
65
+ @sentinels_options.uniq! {|h| h.values_at(:host, :port) }
66
66
  end
67
67
 
68
68
  def discover_master
@@ -79,8 +79,8 @@ class Redis::Client
79
79
  else
80
80
  # A null reply
81
81
  end
82
- rescue Redis::CommandError
83
- # An -IDONTKNOWN reply
82
+ rescue Redis::CommandError => e
83
+ raise unless e.message.include?("IDONTKNOW")
84
84
  rescue Redis::CannotConnectError
85
85
  # faile to connect to current sentinel server
86
86
  end
@@ -120,14 +120,16 @@ class Redis::Client
120
120
  return if options.nil?
121
121
 
122
122
  sentinel_options = []
123
- options.each do |sentinel_option|
124
- if sentinel_option.is_a?(Hash)
125
- sentinel_options << sentinel_option
123
+ options.each do |opts|
124
+ opts = opts[:url] if opts.is_a?(Hash) && opts.key?(:url)
125
+ case opts
126
+ when Hash
127
+ sentinel_options << opts
126
128
  else
127
- uri = URI.parse(sentinel_option)
129
+ uri = URI.parse(opts)
128
130
  sentinel_options << {
129
- host: uri.host,
130
- port: uri.port
131
+ host: uri.host,
132
+ port: uri.port
131
133
  }
132
134
  end
133
135
  end
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  module Sentinel
3
- VERSION = "1.4.1"
3
+ VERSION = "1.4.2"
4
4
  end
5
5
  end
@@ -2,12 +2,13 @@ require "spec_helper"
2
2
 
3
3
  describe Redis::Client do
4
4
  let(:client) { double("Client", :reconnect => true) }
5
- let(:current_sentinel) { double("Redis", :client => client, :host => "localhost", :port => 26379) }
5
+ let(:current_sentinel) { double("Redis", :client => client) }
6
6
 
7
7
  let(:sentinels) do
8
8
  [
9
9
  { :host => "localhost", :port => 26379 },
10
- 'sentinel://localhost:26380'
10
+ 'sentinel://localhost:26380',
11
+ { :url => 'sentinel://localhost:26381' },
11
12
  ]
12
13
  end
13
14
 
@@ -16,6 +17,16 @@ describe Redis::Client do
16
17
 
17
18
  before { allow(Redis).to receive(:new).and_return(current_sentinel) }
18
19
 
20
+ context "new instances" do
21
+ it "should parse sentinel options" do
22
+ expect(subject.instance_variable_get(:@sentinels_options)).to eq [
23
+ {:host=>"localhost", :port=>26379},
24
+ {:host=>"localhost", :port=>26380},
25
+ {:host=>"localhost", :port=>26381}
26
+ ]
27
+ end
28
+ end
29
+
19
30
  context "#sentinel?" do
20
31
  it "should be true if passing sentiels and master_name options" do
21
32
  expect(subject).to be_sentinel
@@ -57,13 +68,15 @@ describe Redis::Client do
57
68
  allow(subject).to receive(:current_sentinel).and_return(current_sentinel)
58
69
  expect(current_sentinel).to receive(:sentinel).with("sentinels", "master").and_return([
59
70
  ["name", "localhost:26381", "ip", "localhost", "port", 26380],
60
- ["name", "localhost:26381", "ip", "localhost", "port", 26381]
71
+ ["name", "localhost:26381", "ip", "localhost", "port", 26381],
72
+ ["name", "localhost:26381", "ip", "localhost", "port", 26382],
61
73
  ])
62
74
  subject.refresh_sentinels_list
63
75
  expect(subject.instance_variable_get(:@sentinels_options)).to eq [
64
76
  {:host => "localhost", :port => 26379},
65
77
  {:host => "localhost", :port => 26380},
66
- {:host => "localhost", :port => 26381}
78
+ {:host => "localhost", :port => 26381},
79
+ {:host => "localhost", :port => 26382},
67
80
  ]
68
81
  end
69
82
  end
@@ -90,6 +103,19 @@ describe Redis::Client do
90
103
  expect(subject.port).to eq 8888
91
104
  end
92
105
 
106
+ it "selects next sentinel if sentinel doesn't know" do
107
+ expect(current_sentinel).to receive(:sentinel).with("get-master-addr-by-name", "master").and_raise(Redis::CommandError.new("IDONTKNOW: No idea"))
108
+ expect(current_sentinel).to receive(:sentinel).with("get-master-addr-by-name", "master").and_return(["master", 8888])
109
+ subject.discover_master
110
+ expect(subject.host).to eq "master"
111
+ expect(subject.port).to eq 8888
112
+ end
113
+
114
+ it "raises error if try_next_sentinel raises error" do
115
+ expect(current_sentinel).to receive(:sentinel).with("get-master-addr-by-name", "master").and_raise(Redis::CommandError.new("ERR: No such command"))
116
+ expect { subject.discover_master }.to raise_error(Redis::CommandError)
117
+ end
118
+
93
119
  it "raises error if try_next_sentinel raises error" do
94
120
  expect(subject).to receive(:try_next_sentinel).and_raise(Redis::CannotConnectError)
95
121
  expect { subject.discover_master }.to raise_error(Redis::CannotConnectError)
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.1
4
+ version: 1.4.2
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-13 00:00:00.000000000 Z
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.0.14
149
+ rubygems_version: 2.2.1
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: another redis automatic master/slave failover solution for ruby by using