redis-sentinel 1.2.0 → 1.3.0

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: 7e8dcd61b9af8824d1cb674236c251562a8c1a7b
4
- data.tar.gz: 988dee4fc0381fd9dbf01a7712e5245cff9043d0
3
+ metadata.gz: 13e25cdba4cbb9a679bc1510df3733769f269084
4
+ data.tar.gz: d73c7b49c1056871ec68faa8eb49d6cc6c201eb4
5
5
  SHA512:
6
- metadata.gz: 0c75234935cac8fb1076495c432e0066ed865ed46910a66ba6b20fe9a2e3e166b79138f51d8fa96d0c18fe4505c501591a8c8a64294ce8a4f767ea6117cb6689
7
- data.tar.gz: ccbdd5ef1b55d557857ee33918ff95e3e756b21264b00320940995c1e8f823f632f8a55db941981b4b031f7dacdd32a2ae9aba781fade7b49c8647d447d3e2cd
6
+ metadata.gz: 733ae6b08e7176b1ae8009ef6c70a7ec0a02ccfecdae4dc5973912e6fd937a73040e297c4155ff2b9248bcd369b93dedba35b58f87934f8bb34ffa63b2d82cae
7
+ data.tar.gz: afbcb2c666c307aa7851b1db2b01abfbcf8f1dbabd9f7d9a76805297d450ddbb5657a3ca0723537043bd2c05e6ed5f7ca3c7e8d5f5d3091a1ab6915f25a7c80b
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ redis-sentinel
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.0
4
+
5
+ * Add ability to reconnect all redis sentinel clients
6
+ * Avoid the config gets modified
7
+ * Reconnect if redis suddenly becones read-only
8
+
3
9
  ## 1.2.0
4
10
 
5
11
  * Add redis synchrony support
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in redis-sentinel.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -91,6 +91,12 @@ takes less than 30 seconds.
91
91
  become master / Add redis synchrony support
92
92
  * [Zachary Anker](https://github.com/zanker) - Add redis authentication
93
93
  support
94
+ * [Nick Deteffen](https://github.com/nick-desteffen) - Add ability to
95
+ reconnect all redis sentinel clients
96
+ * [Carlos Paramio](https://github.com/carlosparamio) - Avoid the config
97
+ gets modified
98
+ * [Michael Gee](https://github.com/mikegee) - Reconnect if redis suddenly
99
+ becomes read-only.
94
100
 
95
101
  Please fork and contribute, any help in making this project better is appreciated!
96
102
 
data/Rakefile CHANGED
@@ -1 +1,19 @@
1
+ #!/usr/bin/env rake
1
2
  require "bundler/gem_tasks"
3
+
4
+ require "rake"
5
+ require "rdoc/task"
6
+ require "rspec"
7
+ require "rspec/core/rake_task"
8
+
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = "spec/**/*_spec.rb"
12
+ end
13
+
14
+ RSpec::Core::RakeTask.new('spec:progress') do |spec|
15
+ spec.rspec_opts = %w(--format progress)
16
+ spec.pattern = "spec/**/*_spec.rb"
17
+ end
18
+
19
+ task :default => :spec
@@ -5,6 +5,7 @@ class Redis::Client
5
5
 
6
6
  class_eval do
7
7
  def initialize_with_sentinel(options={})
8
+ options = options.dup # Don't touch my options
8
9
  @master_name = fetch_option(options, :master_name)
9
10
  @master_password = fetch_option(options, :master_password)
10
11
  @sentinels = fetch_option(options, :sentinels)
@@ -78,6 +79,31 @@ class Redis::Client
78
79
  end
79
80
  end
80
81
 
82
+ def reconnect_with_sentinels
83
+ redis_sentinels.each do |config, sentinel|
84
+ sentinel.client.reconnect
85
+ end
86
+ reconnect_without_sentinels
87
+ end
88
+
89
+ alias reconnect_without_sentinels reconnect
90
+ alias reconnect reconnect_with_sentinels
91
+
92
+ def call_with_readonly_protection(*args, &block)
93
+ tries = 0
94
+ call_without_readonly_protection(*args, &block)
95
+ rescue Redis::CommandError => e
96
+ if e.message == "READONLY You can't write against a read only slave."
97
+ reconnect
98
+ retry if (tries += 1) < 4
99
+ else
100
+ raise
101
+ end
102
+ end
103
+
104
+ alias call_without_readonly_protection call
105
+ alias call call_with_readonly_protection
106
+
81
107
  private
82
108
 
83
109
  def fetch_option(options, key)
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  module Sentinel
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -18,7 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency "redis"
21
+ gem.add_development_dependency "rake"
21
22
  gem.add_development_dependency "rspec"
22
23
  gem.add_development_dependency "eventmachine"
23
24
  gem.add_development_dependency "em-synchrony"
25
+ gem.add_development_dependency "hiredis"
24
26
  end
@@ -1,7 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Redis::Client do
4
- let(:redis) { mock("Redis", :sentinel => ["remote.server", 8888])}
4
+ let(:client) { double("Client", :reconnect => true) }
5
+ let(:redis) { double("Redis", :sentinel => ["remote.server", 8888], :client => client) }
5
6
 
6
7
  subject { Redis::Client.new(:master_name => "master", :master_password => "foobar",
7
8
  :sentinels => [{:host => "localhost", :port => 26379},
@@ -170,4 +171,17 @@ describe Redis::Client do
170
171
  end
171
172
  end
172
173
  end
174
+
175
+ context "#reconnect" do
176
+ it "calls reconnect on each sentinel client" do
177
+ subject.stub(:connect)
178
+ subject.discover_master
179
+ subject.send(:redis_sentinels).each do |config, sentinel|
180
+ sentinel.client.should_receive(:reconnect)
181
+ end
182
+
183
+ subject.reconnect
184
+ end
185
+ end
186
+
173
187
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "rspec"
2
2
 
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
3
6
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
7
  require "redis"
5
8
  require "redis-sentinel"
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.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-10 00:00:00.000000000 Z
11
+ date: 2013-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - '>='
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hiredis
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: another redis automatic master/slave failover solution for ruby by using
70
98
  built-in redis sentinel
71
99
  email:
@@ -75,6 +103,8 @@ extensions: []
75
103
  extra_rdoc_files: []
76
104
  files:
77
105
  - .gitignore
106
+ - .ruby-gemset
107
+ - .ruby-version
78
108
  - CHANGELOG.md
79
109
  - CONTRIBUTING.md
80
110
  - Gemfile
@@ -115,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
145
  version: '0'
116
146
  requirements: []
117
147
  rubyforge_project:
118
- rubygems_version: 2.0.3
148
+ rubygems_version: 2.0.6
119
149
  signing_key:
120
150
  specification_version: 4
121
151
  summary: another redis automatic master/slave failover solution for ruby by using
@@ -124,4 +154,3 @@ test_files:
124
154
  - spec/redis-sentinel/client_spec.rb
125
155
  - spec/redis-sentinel/em_client_spec.rb
126
156
  - spec/spec_helper.rb
127
- has_rdoc: