nogara-redis_failover 1.0.5 → 1.0.6
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 +9 -9
- data/README.md +1 -0
- data/lib/redis_failover/client.rb +10 -3
- data/lib/redis_failover/version.rb +1 -1
- data/spec/client_spec.rb +6 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmQ1OWI4NmYzNzE5MWMxNjdjY2ZlMmYyZjU3ZWI2NzU4ZDI1OGVhNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
OTIwZTRmYWExNmUwMDY3MDMxYjgxMDNiYzc2NmU1ZWE0ZjkwMjdjYg==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWMxMzNjNTAwMzVkYjNhZjExZDRiZWZjZGE3MTBhZTk0M2YyMDZjN2Y3ZjVk
|
10
|
+
YjI0NjU0ZGMyNTczMWMzOGIyZTlhN2RjMmZhNjA3NWVjNjA4NTQwOTE2MTg2
|
11
|
+
ZWYyNmYxYmRiMWQ3MWUxZWJiZmI2YWE4NDFlOTBhY2NlNjljM2Y=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2Q5NzQ0OGFiODVhM2FkYWFhZDdkZGY4ZjNhODkxZGNkMzQzMDljNmUzNWVm
|
14
|
+
ZmE3NGQyYTAxNzY4NWYxMGUzYmYwODY1N2ZjNDFiZjk3NjlhMzk2NDNlNmFl
|
15
|
+
YTBjMDg0MDQyNmJjMWUwODc1NzBkNTkwNDExMjQ4ZmY0ZWY1N2U=
|
data/README.md
CHANGED
@@ -151,6 +151,7 @@ The full set of options that can be passed to RedisFailover::Client are:
|
|
151
151
|
:max_retries - max retries for a failure (default 3)
|
152
152
|
:safe_mode - indicates if safe mode is used or not (default true)
|
153
153
|
:master_only - indicates if only redis master is used (default false)
|
154
|
+
:verify_role - verify the actual role of a redis node before every command (default true)
|
154
155
|
|
155
156
|
The RedisFailover::Client also supports a custom callback that will be invoked whenever the list of redis clients changes. Example usage:
|
156
157
|
|
@@ -56,6 +56,7 @@ module RedisFailover
|
|
56
56
|
# @option options [Integer] :max_retries max retries for a failure
|
57
57
|
# @option options [Boolean] :safe_mode indicates if safe mode is used or not
|
58
58
|
# @option options [Boolean] :master_only indicates if only redis master is used
|
59
|
+
# @option options [Boolean] :verify_role verify the actual role of a redis node before every command
|
59
60
|
# @note Use either :zkservers or :zk
|
60
61
|
# @return [RedisFailover::Client]
|
61
62
|
def initialize(options = {})
|
@@ -241,6 +242,7 @@ module RedisFailover
|
|
241
242
|
|
242
243
|
if tries < @max_retries
|
243
244
|
tries += 1
|
245
|
+
free_client
|
244
246
|
build_clients
|
245
247
|
sleep(RETRY_WAIT_TIME)
|
246
248
|
retry
|
@@ -257,7 +259,7 @@ module RedisFailover
|
|
257
259
|
# @raise [NoMasterError] if no master is available
|
258
260
|
def master
|
259
261
|
if master = @lock.synchronize { @master }
|
260
|
-
verify_role!(master, :master)
|
262
|
+
verify_role!(master, :master) if @verify_role
|
261
263
|
return master
|
262
264
|
end
|
263
265
|
raise NoMasterError
|
@@ -271,7 +273,7 @@ module RedisFailover
|
|
271
273
|
def slave
|
272
274
|
# pick a slave, if none available fallback to master
|
273
275
|
if slave = @lock.synchronize { @slaves.shuffle.first }
|
274
|
-
verify_role!(slave, :slave)
|
276
|
+
verify_role!(slave, :slave) if @verify_role
|
275
277
|
return slave
|
276
278
|
end
|
277
279
|
master
|
@@ -343,7 +345,7 @@ module RedisFailover
|
|
343
345
|
opts = {:host => host, :port => port}
|
344
346
|
opts.update(:db => @db) if @db
|
345
347
|
opts.update(:password => @password) if @password
|
346
|
-
client = Redis.new(opts)
|
348
|
+
client = Redis.new(@redis_client_options.merge(opts))
|
347
349
|
if @namespace
|
348
350
|
client = Redis::Namespace.new(@namespace, :redis => client)
|
349
351
|
end
|
@@ -500,6 +502,11 @@ module RedisFailover
|
|
500
502
|
@max_retries = @retry ? options.fetch(:max_retries, 3) : 0
|
501
503
|
@safe_mode = options.fetch(:safe_mode, true)
|
502
504
|
@master_only = options.fetch(:master_only, false)
|
505
|
+
@verify_role = options.fetch(:verify_role, true)
|
506
|
+
|
507
|
+
@redis_client_options = Redis::Client::DEFAULTS.keys.each_with_object({}) do |key, hash|
|
508
|
+
hash[key] = options[key]
|
509
|
+
end
|
503
510
|
end
|
504
511
|
|
505
512
|
# @return [String] the znode path for the master redis nodes config
|
data/spec/client_spec.rb
CHANGED
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module RedisFailover
|
4
4
|
Client::Redis = RedisStub
|
5
|
+
Client::Redis::Client = Redis::Client
|
5
6
|
class ClientStub < Client
|
6
7
|
def current_master
|
7
8
|
@master
|
@@ -120,9 +121,11 @@ module RedisFailover
|
|
120
121
|
client.reconnected.should be_true
|
121
122
|
end
|
122
123
|
|
123
|
-
|
124
|
-
|
125
|
-
|
124
|
+
context 'with :verify_role true' do
|
125
|
+
it 'properly detects when a node has changed roles' do
|
126
|
+
client.current_master.change_role_to('slave')
|
127
|
+
expect { client.send(:master) }.to raise_error(InvalidNodeRoleError)
|
128
|
+
end
|
126
129
|
end
|
127
130
|
|
128
131
|
it 'raises error for unsupported operations' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nogara-redis_failover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan LeCompte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
201
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.
|
202
|
+
rubygems_version: 2.1.11
|
203
203
|
signing_key:
|
204
204
|
specification_version: 4
|
205
205
|
summary: redis_failover is a ZooKeeper-based automatic master/slave failover solution
|