redis-sentinel 1.1.4 → 1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/README.md +3 -1
- data/lib/em-synchrony/redis-sentinel.rb +13 -0
- data/lib/redis-sentinel/client.rb +3 -2
- data/lib/redis-sentinel/version.rb +1 -1
- data/redis-sentinel.gemspec +2 -0
- data/spec/redis-sentinel/client_spec.rb +19 -3
- data/spec/redis-sentinel/em_client_spec.rb +45 -0
- metadata +42 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e8dcd61b9af8824d1cb674236c251562a8c1a7b
|
4
|
+
data.tar.gz: 988dee4fc0381fd9dbf01a7712e5245cff9043d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c75234935cac8fb1076495c432e0066ed865ed46910a66ba6b20fe9a2e3e166b79138f51d8fa96d0c18fe4505c501591a8c8a64294ce8a4f767ea6117cb6689
|
7
|
+
data.tar.gz: ccbdd5ef1b55d557857ee33918ff95e3e756b21264b00320940995c1e8f823f632f8a55db941981b4b031f7dacdd32a2ae9aba781fade7b49c8647d447d3e2cd
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -88,7 +88,9 @@ takes less than 30 seconds.
|
|
88
88
|
* [Donald Plummer](https://github.com/dplummer) - Add wait / timeout for
|
89
89
|
redis connection
|
90
90
|
* [Rafał Michalski](https://github.com/royaltm) - Ensure promoted slave
|
91
|
-
become master
|
91
|
+
become master / Add redis synchrony support
|
92
|
+
* [Zachary Anker](https://github.com/zanker) - Add redis authentication
|
93
|
+
support
|
92
94
|
|
93
95
|
Please fork and contribute, any help in making this project better is appreciated!
|
94
96
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'redis/connection/synchrony' unless defined? Redis::Connection::Synchrony
|
2
|
+
require 'redis-sentinel'
|
3
|
+
|
4
|
+
class Redis::Client
|
5
|
+
class_eval do
|
6
|
+
private
|
7
|
+
def sleep(seconds)
|
8
|
+
f = Fiber.current
|
9
|
+
EM::Timer.new(seconds) { f.resume }
|
10
|
+
Fiber.yield
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -6,6 +6,7 @@ class Redis::Client
|
|
6
6
|
class_eval do
|
7
7
|
def initialize_with_sentinel(options={})
|
8
8
|
@master_name = fetch_option(options, :master_name)
|
9
|
+
@master_password = fetch_option(options, :master_password)
|
9
10
|
@sentinels = fetch_option(options, :sentinels)
|
10
11
|
@failover_reconnect_timeout = fetch_option(options, :failover_reconnect_timeout)
|
11
12
|
@failover_reconnect_wait = fetch_option(options, :failover_reconnect_wait) ||
|
@@ -70,10 +71,10 @@ class Redis::Client
|
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
|
-
if is_down == "1" || runid == '?'
|
74
|
+
if is_down.to_s == "1" || runid == '?'
|
74
75
|
raise Redis::CannotConnectError.new("The master: #{@master_name} is currently not available.")
|
75
76
|
else
|
76
|
-
@options.merge!(:host => host, :port => port.to_i)
|
77
|
+
@options.merge!(:host => host, :port => port.to_i, :password => @master_password)
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
data/redis-sentinel.gemspec
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Redis::Client do
|
4
4
|
let(:redis) { mock("Redis", :sentinel => ["remote.server", 8888])}
|
5
5
|
|
6
|
-
subject { Redis::Client.new(:master_name => "master",
|
6
|
+
subject { Redis::Client.new(:master_name => "master", :master_password => "foobar",
|
7
7
|
:sentinels => [{:host => "localhost", :port => 26379},
|
8
8
|
{:host => "localhost", :port => 26380}]) }
|
9
9
|
|
@@ -45,25 +45,40 @@ describe Redis::Client do
|
|
45
45
|
it "should update options" do
|
46
46
|
redis.should_receive(:sentinel).
|
47
47
|
with("is-master-down-by-addr", "remote.server", 8888).once.
|
48
|
-
and_return([
|
48
|
+
and_return([0, "abc"])
|
49
49
|
subject.discover_master
|
50
50
|
expect(subject.host).to eq "remote.server"
|
51
51
|
expect(subject.port).to eq 8888
|
52
|
+
expect(subject.password).to eq "foobar"
|
52
53
|
end
|
53
54
|
|
54
55
|
it "should not update options" do
|
55
56
|
redis.should_receive(:sentinel).
|
56
57
|
with("is-master-down-by-addr", "remote.server", 8888).twice.
|
57
|
-
and_return([
|
58
|
+
and_return([1, "abc"], [0, "?"])
|
58
59
|
2.times do
|
59
60
|
expect do
|
60
61
|
subject.discover_master
|
61
62
|
end.to raise_error(Redis::CannotConnectError, /currently not available/)
|
62
63
|
expect(subject.host).not_to eq "remote.server"
|
63
64
|
expect(subject.port).not_to eq 8888
|
65
|
+
expect(subject.password).not_to eq "foobar"
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
69
|
+
it "should not use a password" do
|
70
|
+
Redis.should_receive(:new).with({:host => "localhost", :port => 26379})
|
71
|
+
redis.should_receive(:sentinel).with("get-master-addr-by-name", "master")
|
72
|
+
redis.should_receive(:sentinel).with("is-master-down-by-addr", "remote.server", 8888)
|
73
|
+
|
74
|
+
redis = Redis::Client.new(:master_name => "master", :sentinels => [{:host => "localhost", :port => 26379}])
|
75
|
+
redis.discover_master
|
76
|
+
|
77
|
+
expect(redis.host).to eq "remote.server"
|
78
|
+
expect(redis.port).to eq 8888
|
79
|
+
expect(redis.password).to eq nil
|
80
|
+
end
|
81
|
+
|
67
82
|
it "should select next sentinel" do
|
68
83
|
Redis.should_receive(:new).with({:host => "localhost", :port => 26379})
|
69
84
|
redis.should_receive(:sentinel).
|
@@ -77,6 +92,7 @@ describe Redis::Client do
|
|
77
92
|
subject.discover_master
|
78
93
|
expect(subject.host).to eq "remote.server"
|
79
94
|
expect(subject.port).to eq 8888
|
95
|
+
expect(subject.password).to eq "foobar"
|
80
96
|
end
|
81
97
|
|
82
98
|
describe "memoizing sentinel connections" do
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "em-synchrony/redis-sentinel"
|
3
|
+
require "eventmachine"
|
4
|
+
|
5
|
+
describe Redis::Client do
|
6
|
+
context "#auto_retry_with_timeout" do
|
7
|
+
subject { described_class.new(:failover_reconnect_timeout => 3,
|
8
|
+
:failover_reconnect_wait => 0.1) }
|
9
|
+
context "configured wait time" do
|
10
|
+
|
11
|
+
it "uses the wait time and blocks em" do
|
12
|
+
Time.stub(:now).and_return(100, 101, 105)
|
13
|
+
flag = false; EM.next_tick { flag = true }
|
14
|
+
subject.should_receive(:sleep).with(0.1).and_return(0.1)
|
15
|
+
begin
|
16
|
+
subject.auto_retry_with_timeout { raise Redis::CannotConnectError }
|
17
|
+
rescue Redis::CannotConnectError
|
18
|
+
end
|
19
|
+
flag.should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "uses the wait time and doesn't block em" do
|
23
|
+
Time.stub(:now).and_return(100, 101, 105)
|
24
|
+
flag = false; EM.next_tick { flag = true }
|
25
|
+
begin
|
26
|
+
subject.auto_retry_with_timeout { raise Redis::CannotConnectError }
|
27
|
+
rescue Redis::CannotConnectError
|
28
|
+
end
|
29
|
+
flag.should be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
around(:each) do |testcase|
|
35
|
+
EM.run do
|
36
|
+
Fiber.new do
|
37
|
+
begin
|
38
|
+
testcase.call
|
39
|
+
ensure
|
40
|
+
EM.stop
|
41
|
+
end
|
42
|
+
end.resume
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,46 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-sentinel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Richard Huang
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: redis
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: eventmachine
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: em-synchrony
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
44
67
|
- !ruby/object:Gem::Version
|
45
68
|
version: '0'
|
46
69
|
description: another redis automatic master/slave failover solution for ruby by using
|
@@ -65,38 +88,40 @@ files:
|
|
65
88
|
- example/test.rb
|
66
89
|
- example/test_wait_for_failover.rb
|
67
90
|
- example/test_wait_for_failover_write.rb
|
91
|
+
- lib/em-synchrony/redis-sentinel.rb
|
68
92
|
- lib/redis-sentinel.rb
|
69
93
|
- lib/redis-sentinel/client.rb
|
70
94
|
- lib/redis-sentinel/version.rb
|
71
95
|
- redis-sentinel.gemspec
|
72
96
|
- spec/redis-sentinel/client_spec.rb
|
97
|
+
- spec/redis-sentinel/em_client_spec.rb
|
73
98
|
- spec/spec_helper.rb
|
74
99
|
homepage: https://github.com/flyerhzm/redis-sentinel
|
75
100
|
licenses: []
|
101
|
+
metadata: {}
|
76
102
|
post_install_message:
|
77
103
|
rdoc_options: []
|
78
104
|
require_paths:
|
79
105
|
- lib
|
80
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
107
|
requirements:
|
83
|
-
- -
|
108
|
+
- - '>='
|
84
109
|
- !ruby/object:Gem::Version
|
85
110
|
version: '0'
|
86
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
112
|
requirements:
|
89
|
-
- -
|
113
|
+
- - '>='
|
90
114
|
- !ruby/object:Gem::Version
|
91
115
|
version: '0'
|
92
116
|
requirements: []
|
93
117
|
rubyforge_project:
|
94
|
-
rubygems_version:
|
118
|
+
rubygems_version: 2.0.3
|
95
119
|
signing_key:
|
96
|
-
specification_version:
|
120
|
+
specification_version: 4
|
97
121
|
summary: another redis automatic master/slave failover solution for ruby by using
|
98
122
|
built-in redis sentinel
|
99
123
|
test_files:
|
100
124
|
- spec/redis-sentinel/client_spec.rb
|
125
|
+
- spec/redis-sentinel/em_client_spec.rb
|
101
126
|
- spec/spec_helper.rb
|
102
127
|
has_rdoc:
|