nogara-redis_failover 0.9.7.3 → 0.9.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/Changes.md CHANGED
@@ -1,11 +1,13 @@
1
1
  HEAD
2
2
  -----------
3
- - redis_failover now supports distributed monitoring among the node managers! Previously, the node managers were only used
4
- as a means of redundancy in case a particular node manager crashed. Starting with version 1.0 of redis_failover, the node
5
- managers will all periodically report their health report/snapshots. The primary node manager will utilize a configurable
3
+ - redis_failover now supports distributed monitoring among the Node Managers! Previously, the Node Managers were only used
4
+ as a means of redundancy in case a particular node manager crashed. Starting with version 1.0 of redis_failover, the Node
5
+ Managers will all periodically report their health report/snapshots. The primary Node Manager will utilize a configurable
6
6
  "node strategy" to determine if a particular node is available or unavailable.
7
7
  - redis_failover now supports a configurable "failover strategy" that's consulted when performing a failover. Currently,
8
8
  a single strategy is provided that takes into account the average latency of the last health check to the redis server.
9
+ - Improved handling of underlying ZK client connection in RedisFailover::NodeManager
10
+ - Add support for passing in an existing ZK client instance to RedisFailover::Cient.new
9
11
 
10
12
  0.9.7.2
11
13
  -----------
data/README.md CHANGED
@@ -90,6 +90,9 @@ would look like the following:
90
90
 
91
91
  ---
92
92
  :max_failures: 2
93
+ :node_strategy: majority
94
+ :failover_strategy: latency
95
+ :required_node_managers: 2
93
96
  :nodes:
94
97
  - localhost:6379
95
98
  - localhost:1111
@@ -115,22 +118,30 @@ this Node Manager process dies or becomes partitioned from the network, another
115
118
  will be promoted as the primary manager of redis servers. You can run as many Node Manager
116
119
  processes as you'd like. Every Node Manager periodically records health "snapshots" which the
117
120
  primary/master Node Manager consults when determining if it should officially mark a redis
118
- server as unavailable. By default, a majority strategy is used.
121
+ server as unavailable. By default, a majority strategy is used. Also, when a failover
122
+ happens, the primary Node Manager will consult the node snapshots to determine the best
123
+ node to use as the new master.
119
124
 
120
125
  ## Client Usage
121
126
 
122
127
  The redis failover client must be used in conjunction with a running Node Manager daemon. The
123
128
  client supports various configuration options, however the only mandatory option is the list of
124
- ZooKeeper servers:
129
+ ZooKeeper servers OR an existing ZK client instance:
125
130
 
131
+ # Explicitly specify the ZK servers
126
132
  client = RedisFailover::Client.new(:zkservers => 'localhost:2181,localhost:2182,localhost:2183')
127
133
 
134
+ # Explicitly specify an existing ZK client instance (useful if using a connection pool, etc)
135
+ zk = ZK.new('localhost:2181,localhost:2182,localhost:2183')
136
+ client = RedisFailover::Client.new(:zk => zk)
137
+
128
138
  The client actually employs the common redis and redis-namespace gems underneath, so this should be
129
139
  a drop-in replacement for your existing pure redis client usage.
130
140
 
131
141
  The full set of options that can be passed to RedisFailover::Client are:
132
142
 
133
- :zkservers - comma-separated ZooKeeper host:port pairs (required)
143
+ :zk - an existing ZK client instance
144
+ :zkservers - comma-separated ZooKeeper host:port pairs
134
145
  :znode_path - the Znode path override for redis server list (optional)
135
146
  :password - password for redis nodes (optional)
136
147
  :db - db to use for redis nodes (optional)
@@ -40,6 +40,7 @@ module RedisFailover
40
40
  #
41
41
  # @param [Hash] options the options used to initialize the client instance
42
42
  # @option options [String] :zkservers comma-separated ZooKeeper host:port
43
+ # @option options [String] :zk an existing ZK client connection instance
43
44
  # @option options [String] :znode_path znode path override for redis nodes
44
45
  # @option options [String] :password password for redis nodes
45
46
  # @option options [String] :db database to use for redis nodes
@@ -49,6 +50,7 @@ module RedisFailover
49
50
  # @option options [Integer] :max_retries max retries for a failure
50
51
  # @option options [Boolean] :safe_mode indicates if safe mode is used or not
51
52
  # @option options [Boolean] :master_only indicates if only redis master is used
53
+ # @note Use either :zkservers or :zk
52
54
  # @return [RedisFailover::Client]
53
55
  def initialize(options = {})
54
56
  Util.logger = options[:logger] if options[:logger]
@@ -177,8 +179,8 @@ module RedisFailover
177
179
 
178
180
  # Sets up the underlying ZooKeeper connection.
179
181
  def setup_zk
180
- @zk = ZK.new(@zkservers)
181
- @zk.watcher.register(redis_nodes_path) { |event| handle_zk_event(event) }
182
+ @zk = ZK.new(@zkservers) if @zkservers
183
+ @zk.register(redis_nodes_path) { |event| handle_zk_event(event) }
182
184
  if @safe_mode
183
185
  @zk.on_expired_session { purge_clients }
184
186
  end
@@ -475,7 +477,11 @@ module RedisFailover
475
477
  #
476
478
  # @param [Hash] options the configuration options
477
479
  def parse_options(options)
478
- @zkservers = options.fetch(:zkservers) { raise ArgumentError, ':zkservers required'}
480
+ @zk, @zkservers = options.values_at(:zk, :zkservers)
481
+ if [@zk, @zkservers].all? || [@zk, @zkservers].none?
482
+ raise ArgumentError, 'must specify :zk or :zkservers'
483
+ end
484
+
479
485
  @root_znode = options.fetch(:znode_path, Util::DEFAULT_ROOT_ZNODE_PATH)
480
486
  @namespace = options[:namespace]
481
487
  @password = options[:password]
@@ -1,3 +1,3 @@
1
1
  module RedisFailover
2
- VERSION = '0.9.7.3'
2
+ VERSION = '0.9.7.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nogara-redis_failover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7.3
4
+ version: 0.9.7.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: