Class: Redis::Retry
- Inherits:
-
Object
- Object
- Redis::Retry
- Defined in:
- lib/redis/retry.rb
Instance Attribute Summary collapse
-
#tries ⇒ Object
The number of times a command will be retried if a connection cannot be made to Redis.
-
#wait ⇒ Object
The number of seconds to wait before retrying a command.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Retry
constructor
A new instance of Retry.
- #method_missing(command, *args, &block) ⇒ Object
-
#type(key) ⇒ Object
Ruby defines a now deprecated type method so we need to override it here since it will never hit method_missing.
Constructor Details
#initialize(options = {}) ⇒ Retry
Returns a new instance of Retry.
12 13 14 15 16 |
# File 'lib/redis/retry.rb', line 12 def initialize( = {}) @tries = [:tries] || 3 @wait = [:wait] || 2 @redis = [:redis] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(command, *args, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/redis/retry.rb', line 24 def method_missing(command, *args, &block) try = 1 while try <= @tries begin # Dispatch the command to Redis return @redis.send(command, *args, &block) rescue Errno::ECONNREFUSED try += 1 sleep @wait end end # Ran out of retries raise Errno::ECONNREFUSED end |
Instance Attribute Details
#tries ⇒ Object
The number of times a command will be retried if a connection cannot be made to Redis. If zero, retry forever.
7 8 9 |
# File 'lib/redis/retry.rb', line 7 def tries @tries end |
#wait ⇒ Object
The number of seconds to wait before retrying a command.
10 11 12 |
# File 'lib/redis/retry.rb', line 10 def wait @wait end |
Instance Method Details
#type(key) ⇒ Object
Ruby defines a now deprecated type method so we need to override it here since it will never hit method_missing.
20 21 22 |
# File 'lib/redis/retry.rb', line 20 def type(key) method_missing(:type, key) end |