redis_failover 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes.md +5 -0
- data/lib/redis_failover/client.rb +21 -26
- data/lib/redis_failover/version.rb +1 -1
- data/spec/node_spec.rb +1 -1
- metadata +8 -2
data/Changes.md
CHANGED
@@ -105,7 +105,9 @@ module RedisFailover
|
|
105
105
|
@max_retries = @retry ? options.fetch(:max_retries, 3) : 0
|
106
106
|
@master = nil
|
107
107
|
@slaves = []
|
108
|
+
@node_addresses = {}
|
108
109
|
@lock = Monitor.new
|
110
|
+
@current_client_key = "current-client-#{self.object_id}"
|
109
111
|
setup_zk
|
110
112
|
build_clients
|
111
113
|
end
|
@@ -228,11 +230,7 @@ module RedisFailover
|
|
228
230
|
end
|
229
231
|
raise
|
230
232
|
ensure
|
231
|
-
|
232
|
-
if info[:method] == method
|
233
|
-
Thread.current[:last_operation_info] = nil
|
234
|
-
end
|
235
|
-
end
|
233
|
+
free_client
|
236
234
|
end
|
237
235
|
end
|
238
236
|
|
@@ -312,6 +310,7 @@ module RedisFailover
|
|
312
310
|
if @namespace
|
313
311
|
client = Redis::Namespace.new(@namespace, :redis => client)
|
314
312
|
end
|
313
|
+
@node_addresses[client] = node
|
315
314
|
client
|
316
315
|
end
|
317
316
|
end
|
@@ -364,7 +363,7 @@ module RedisFailover
|
|
364
363
|
# @return [String] the address for the node
|
365
364
|
def address_for(node)
|
366
365
|
return unless node
|
367
|
-
|
366
|
+
@node_addresses[node]
|
368
367
|
end
|
369
368
|
|
370
369
|
# Determines if the currently known redis servers is different
|
@@ -400,6 +399,7 @@ module RedisFailover
|
|
400
399
|
disconnect(@master, *@slaves)
|
401
400
|
@master = nil
|
402
401
|
@slaves = []
|
402
|
+
@node_addresses = {}
|
403
403
|
end
|
404
404
|
end
|
405
405
|
|
@@ -414,32 +414,27 @@ module RedisFailover
|
|
414
414
|
Time.now - @last_znode_timestamp <= ZNODE_UPDATE_TIMEOUT
|
415
415
|
end
|
416
416
|
|
417
|
-
#
|
417
|
+
# Acquires a client to use for the specified operation.
|
418
418
|
#
|
419
419
|
# @param [Symbol] method the method for which to retrieve a client
|
420
420
|
# @return [Redis] a redis client to use
|
421
421
|
# @note
|
422
|
-
# This method stores
|
423
|
-
# where the same RedisFailover::Client instance is referenced by
|
424
|
-
# block passed to multi.
|
422
|
+
# This method stores a stack of clients used to handle the case
|
423
|
+
# where the same RedisFailover::Client instance is referenced by
|
424
|
+
# nested blocks (e.g., block passed to multi).
|
425
425
|
def client_for(method)
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
:client => slave,
|
432
|
-
:method => method
|
433
|
-
}
|
434
|
-
else
|
435
|
-
# direct everything else to master
|
436
|
-
Thread.current[:last_operation_info] = {
|
437
|
-
:client => master,
|
438
|
-
:method => method
|
439
|
-
}
|
440
|
-
end
|
426
|
+
stack = Thread.current[@current_client_key] ||= []
|
427
|
+
client = stack.last || (REDIS_READ_OPS.include?(method) ? slave : master)
|
428
|
+
stack << client
|
429
|
+
client
|
430
|
+
end
|
441
431
|
|
442
|
-
|
432
|
+
# Pops a client from the thread-local client stack.
|
433
|
+
def free_client
|
434
|
+
if stack = Thread.current[@current_client_key]
|
435
|
+
stack.pop
|
436
|
+
end
|
437
|
+
nil
|
443
438
|
end
|
444
439
|
end
|
445
440
|
end
|
data/spec/node_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_failover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.8
|
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: 2012-07-
|
12
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -181,12 +181,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
181
|
- - ! '>='
|
182
182
|
- !ruby/object:Gem::Version
|
183
183
|
version: '0'
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
hash: 1682617654026329056
|
184
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
188
|
none: false
|
186
189
|
requirements:
|
187
190
|
- - ! '>='
|
188
191
|
- !ruby/object:Gem::Version
|
189
192
|
version: '0'
|
193
|
+
segments:
|
194
|
+
- 0
|
195
|
+
hash: 1682617654026329056
|
190
196
|
requirements: []
|
191
197
|
rubyforge_project:
|
192
198
|
rubygems_version: 1.8.23
|