redis-sentinel 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/example/test.rb +5 -1
- data/lib/redis-sentinel/client.rb +3 -3
- data/lib/redis-sentinel/version.rb +1 -1
- data/spec/redis-sentinel/client_spec.rb +6 -6
- metadata +2 -2
data/example/test.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'redis'
|
2
2
|
require 'redis-sentinel'
|
3
3
|
|
4
|
-
redis = Redis.new(master_name
|
4
|
+
redis = Redis.new(:master_name => "example-test",
|
5
|
+
:sentinels => [
|
6
|
+
{:host => "localhost", :port => 26379},
|
7
|
+
{:host => "localhost", :port => 26380}
|
8
|
+
])
|
5
9
|
redis.set "foo", "bar"
|
6
10
|
|
7
11
|
while true
|
@@ -2,14 +2,14 @@ require "redis"
|
|
2
2
|
|
3
3
|
class Redis::Client
|
4
4
|
class_eval do
|
5
|
-
def
|
5
|
+
def initialize_with_sentinel(options={})
|
6
6
|
@master_name = options.delete(:master_name) || options.delete("master_name")
|
7
7
|
@sentinels = options.delete(:sentinels) || options.delete("sentinels")
|
8
8
|
initialize_without_sentinel(options)
|
9
9
|
end
|
10
10
|
|
11
11
|
alias initialize_without_sentinel initialize
|
12
|
-
alias initialize
|
12
|
+
alias initialize initialize_with_sentinel
|
13
13
|
|
14
14
|
def connect_with_sentinel
|
15
15
|
discover_master if sentinel?
|
@@ -42,7 +42,7 @@ class Redis::Client
|
|
42
42
|
if !host && !port
|
43
43
|
raise Redis::ConnectionError.new("No master named: #{@master_name}")
|
44
44
|
end
|
45
|
-
@options.merge!(host
|
45
|
+
@options.merge!(:host => host, :port => port.to_i)
|
46
46
|
|
47
47
|
break
|
48
48
|
rescue Redis::CannotConnectError
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Redis::Client do
|
4
4
|
context "#sentinel?" do
|
5
5
|
it "should be true if passing sentiels and master_name options" do
|
6
|
-
expect(Redis::Client.new(master_name
|
6
|
+
expect(Redis::Client.new(:master_name => "master", :sentinels => [{:host => "localhost", :port => 26379}, {:host => "localhost", :port => 26380}])).to be_sentinel
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should not be true if not passing sentinels and maser_name options" do
|
@@ -11,24 +11,24 @@ describe Redis::Client do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should not be true if passing sentinels option but not master_name option" do
|
14
|
-
expect(Redis::Client.new(sentinels
|
14
|
+
expect(Redis::Client.new(:sentinels => [{:host => "localhost", :port => 26379}, {:host => "localhost", :port => 26380}])).not_to be_sentinel
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should not be true if passing master_name option but not sentinels option" do
|
18
|
-
expect(Redis::Client.new(master_name
|
18
|
+
expect(Redis::Client.new(:master_name => "master")).not_to be_sentinel
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context "#try_next_sentinel" do
|
23
|
-
let(:client) { Redis::Client.new(master_name
|
23
|
+
let(:client) { Redis::Client.new(:master_name => "master", :sentinels => [{:host => "localhost", :port => 26379}, {:host => "localhost", :port => 26380}]) }
|
24
24
|
|
25
25
|
it "should return next sentinel server" do
|
26
|
-
expect(client.try_next_sentinel).to eq({host
|
26
|
+
expect(client.try_next_sentinel).to eq({:host => "localhost", :port => 26380})
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context "#discover_master" do
|
31
|
-
let(:client) { Redis::Client.new(master_name
|
31
|
+
let(:client) { Redis::Client.new(:master_name => "master", :sentinels => [{:host => "localhost", :port => 26379}, {:host => "localhost", :port => 26380}]) }
|
32
32
|
before { Redis.any_instance.should_receive(:sentinel).with("get-master-addr-by-name", "master").and_return(["remote.server", 8888]) }
|
33
33
|
|
34
34
|
it "should update options" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-sentinel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|