Permalink
Browse files

Add support for passing in an existing ZK client instance to RedisFai…

…lover::Cient.new
  • Loading branch information...
1 parent b303ebf commit 5d475dd6ce6ad34abf272ff642058833ae660f70 @ryanlecompte committed Oct 8, 2012
Showing with 9 additions and 2 deletions.
  1. +1 −0 Changes.md
  2. +8 −2 lib/redis_failover/client.rb
View
@@ -7,6 +7,7 @@ Managers will all periodically report their health report/snapshots. The primary
- redis_failover now supports a configurable "failover strategy" that's consulted when performing a failover. Currently,
a single strategy is provided that takes into account the average latency of the last health check to the redis server.
- Improved handling of underlying ZK client connection in RedisFailover::NodeManager
+- Add support for passing in an existing ZK client instance to RedisFailover::Cient.new
0.9.7.2
-----------
@@ -40,6 +40,7 @@ class Client
#
# @param [Hash] options the options used to initialize the client instance
# @option options [String] :zkservers comma-separated ZooKeeper host:port
+ # @option options [String] :zk an existing ZK client connection instance
# @option options [String] :znode_path znode path override for redis nodes
# @option options [String] :password password for redis nodes
# @option options [String] :db database to use for redis nodes
@@ -49,6 +50,7 @@ class Client
# @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
+ # @note Use either :zkservers or :zk
# @return [RedisFailover::Client]
def initialize(options = {})
Util.logger = options[:logger] if options[:logger]
@@ -177,7 +179,7 @@ def current_slaves
# Sets up the underlying ZooKeeper connection.
def setup_zk
- @zk = ZK.new(@zkservers)
+ @zk = ZK.new(@zkservers) if @zkservers
@zk.watcher.register(redis_nodes_path) { |event| handle_zk_event(event) }
if @safe_mode
@zk.on_expired_session { purge_clients }
@@ -475,7 +477,11 @@ def free_client
#
# @param [Hash] options the configuration options
def parse_options(options)
- @zkservers = options.fetch(:zkservers) { raise ArgumentError, ':zkservers required'}
+ @zk, @zkservers = options.values_at(:zk, :zkservers)
+ if [@zk, @zkservers].all? || [@zk, @zkservers].none?
+ raise ArgumentError, 'must specify :zk or :zkservers'
+ end
+
@root_znode = options.fetch(:znode_path, Util::DEFAULT_ROOT_ZNODE_PATH)
@namespace = options[:namespace]
@password = options[:password]

0 comments on commit 5d475dd

Please sign in to comment.