nogara-redis_failover 1.0.2 → 1.0.4

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.
data/Changes.md CHANGED
@@ -1,3 +1,8 @@
1
+ 1.0.2
2
+ -----------
3
+ - Reopen client if an ZK::Exceptions::InterruptedSession occurs (#50, mauricio)
4
+ - Insert the "root_znode" path before "master_redis_node_manager_lock" and expose via accessor (#52, jzaleski)
5
+
1
6
  1.0.1
2
7
  -----------
3
8
  - Bumped required dependency on ZK gem. ZK 1.7.4 fixes a critical bug with locking (see https://github.com/slyphon/zk/issues/54)
@@ -36,6 +36,12 @@ module RedisFailover
36
36
  end
37
37
  end
38
38
 
39
+ def call(command, &block)
40
+ method = command[0]
41
+ args = command[1..-1]
42
+ dispatch(method, *args, &block)
43
+ end
44
+
39
45
  # Creates a new failover redis client.
40
46
  #
41
47
  # @param [Hash] options the options used to initialize the client instance
@@ -123,7 +129,7 @@ module RedisFailover
123
129
 
124
130
  # @return [String] a string representation of the client
125
131
  def inspect
126
- "#<RedisFailover::Client (master: #{master_name}, slaves: #{slave_names})>"
132
+ "#<RedisFailover::Client (db: #{@db.to_i}, master: #{master_name}, slaves: #{slave_names})>"
127
133
  end
128
134
  alias_method :to_s, :inspect
129
135
 
@@ -317,7 +323,7 @@ module RedisFailover
317
323
  logger.debug("Fetched nodes: #{nodes.inspect}")
318
324
 
319
325
  nodes
320
- rescue Zookeeper::Exceptions::InheritedConnectionError => ex
326
+ rescue Zookeeper::Exceptions::InheritedConnectionError, ZK::Exceptions::InterruptedSession => ex
321
327
  logger.debug { "Caught #{ex.class} '#{ex.message}' - reopening ZK client" }
322
328
  @zk.reopen
323
329
  retry
@@ -459,6 +459,11 @@ module RedisFailover
459
459
  "#{@root_znode}/nodes"
460
460
  end
461
461
 
462
+ # @return [String] root path for current node manager lock
463
+ def current_lock_path
464
+ "#{@root_znode}/master_redis_node_manager_lock"
465
+ end
466
+
462
467
  # @return [String] the znode path used for performing manual failovers
463
468
  def manual_failover_path
464
469
  ManualFailover.path(@root_znode)
@@ -631,7 +636,7 @@ module RedisFailover
631
636
 
632
637
  # Executes a block wrapped in a ZK exclusive lock.
633
638
  def with_lock
634
- @zk_lock ||= @zk.locker('master_redis_node_manager_lock')
639
+ @zk_lock ||= @zk.locker(current_lock_path)
635
640
 
636
641
  begin
637
642
  @zk_lock.lock!(true)
@@ -1,3 +1,3 @@
1
1
  module RedisFailover
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency('redis', ['>= 2.2', '< 4'])
19
19
  gem.add_dependency('redis-namespace')
20
20
  gem.add_dependency('multi_json', '~> 1')
21
- gem.add_dependency('zk', ['>= 1.7.4', '< 1.8'])
21
+ gem.add_dependency('zk', ['>= 1.7.4', '< 1.9'])
22
22
 
23
23
  gem.add_development_dependency('rake')
24
24
  gem.add_development_dependency('rspec')
data/spec/client_spec.rb CHANGED
@@ -54,6 +54,25 @@ module RedisFailover
54
54
  called.should be_true
55
55
  end
56
56
 
57
+ describe '#inspect' do
58
+ it 'should always include db' do
59
+ opts = {:zkservers => 'localhost:1234'}
60
+ client = ClientStub.new(opts)
61
+ client.inspect.should match('<RedisFailover::Client \(db: 0,')
62
+ db = '5'
63
+ opts.merge!(:db => db)
64
+ client = ClientStub.new(opts)
65
+ client.inspect.should match("<RedisFailover::Client \\(db: #{db},")
66
+ end
67
+ end
68
+
69
+ describe '#call' do
70
+ it 'should dispatch :call messages to correct method' do
71
+ client.should_receive(:dispatch).with(:foo, *['key'])
72
+ client.call([:foo, 'key'])
73
+ end
74
+ end
75
+
57
76
  context 'with :master_only false' do
58
77
  it 'routes read operations to a slave' do
59
78
  called = false
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: 1.0.2
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-26 00:00:00.000000000 Z
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: 1.7.4
76
76
  - - <
77
77
  - !ruby/object:Gem::Version
78
- version: '1.8'
78
+ version: '1.9'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -86,7 +86,7 @@ dependencies:
86
86
  version: 1.7.4
87
87
  - - <
88
88
  - !ruby/object:Gem::Version
89
- version: '1.8'
89
+ version: '1.9'
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: rake
92
92
  requirement: !ruby/object:Gem::Requirement
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  requirements: []
217
217
  rubyforge_project:
218
- rubygems_version: 1.8.24
218
+ rubygems_version: 1.8.25
219
219
  signing_key:
220
220
  specification_version: 3
221
221
  summary: redis_failover is a ZooKeeper-based automatic master/slave failover solution