Permalink
Browse files

Merge pull request #58 from fanhattan/verify_role-optional

Make node role verification optional via :verify_role option.
  • Loading branch information...
2 parents 15778c7 + 565f598 commit 6d9754d09618e44c6ddab42c2871816d401b2111 @ryanlecompte committed Oct 15, 2013
Showing with 10 additions and 5 deletions.
  1. +1 −0 README.md
  2. +4 −2 lib/redis_failover/client.rb
  3. +5 −3 spec/client_spec.rb
View
@@ -151,6 +151,7 @@ The full set of options that can be passed to RedisFailover::Client are:
:max_retries - max retries for a failure (default 3)
:safe_mode - indicates if safe mode is used or not (default true)
:master_only - indicates if only redis master is used (default false)
+ :verify_role - verify the actual role of a redis node before every command (default true)
The RedisFailover::Client also supports a custom callback that will be invoked whenever the list of redis clients changes. Example usage:
@@ -56,6 +56,7 @@ def call(command, &block)
# @option options [Integer] :max_retries max retries for a failure
# @option options [Boolean] :safe_mode indicates if safe mode is used or not
# @option options [Boolean] :master_only indicates if only redis master is used
+ # @option options [Boolean] :verify_role verify the actual role of a redis node before every command
# @note Use either :zkservers or :zk
# @return [RedisFailover::Client]
def initialize(options = {})
@@ -258,7 +259,7 @@ def dispatch(method, *args, &block)
# @raise [NoMasterError] if no master is available
def master
if master = @lock.synchronize { @master }
- verify_role!(master, :master)
+ verify_role!(master, :master) if @verify_role
return master
end
raise NoMasterError
@@ -272,7 +273,7 @@ def master
def slave
# pick a slave, if none available fallback to master
if slave = @lock.synchronize { @slaves.shuffle.first }
- verify_role!(slave, :slave)
+ verify_role!(slave, :slave) if @verify_role
return slave
end
master
@@ -501,6 +502,7 @@ def parse_options(options)
@max_retries = @retry ? options.fetch(:max_retries, 3) : 0
@safe_mode = options.fetch(:safe_mode, true)
@master_only = options.fetch(:master_only, false)
+ @verify_role = options.fetch(:verify_role, true)
end
# @return [String] the znode path for the master redis nodes config
View
@@ -120,9 +120,11 @@ def fetch_nodes
client.reconnected.should be_true
end
- it 'properly detects when a node has changed roles' do
- client.current_master.change_role_to('slave')
- expect { client.send(:master) }.to raise_error(InvalidNodeRoleError)
+ context 'with :verify_role true' do
+ it 'properly detects when a node has changed roles' do
+ client.current_master.change_role_to('slave')
+ expect { client.send(:master) }.to raise_error(InvalidNodeRoleError)
+ end
end
it 'raises error for unsupported operations' do

0 comments on commit 6d9754d

Please sign in to comment.