Class: RedisCluster::Client
- Inherits:
-
Object
- Object
- RedisCluster::Client
- Defined in:
- lib/redis_cluster/client.rb
Instance Method Summary collapse
- #execute(method, args) ⇒ Object
-
#initialize(startup_hosts, global_configs = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(startup_hosts, global_configs = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 |
# File 'lib/redis_cluster/client.rb', line 7 def initialize(startup_hosts, global_configs = {}) @startup_hosts = startup_hosts @pool = Pool.new @mutex = Mutex.new reload_pool_nodes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
46 47 48 |
# File 'lib/redis_cluster/client.rb', line 46 def method_missing(method, *args, &block) execute(method, args) end |
Instance Method Details
#execute(method, args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/redis_cluster/client.rb', line 14 def execute(method, args) ttl = Configuration::REQUEST_TTL asking = false try_random_node = false while ttl > 0 ttl -= 1 begin return @pool.execute(method, args, {asking: asking, random_node: try_random_node}) rescue Errno::ECONNREFUSED, Redis::TimeoutError, Redis::CannotConnectError, Errno::EACCES try_random_node = true sleep 0.1 if ttl < Configuration::REQUEST_TTL/2 rescue => e err_code = e.to_s.split.first raise e unless %w(MOVED ASK).include?(err_code) if err_code == "ASK" asking = true else reload_pool_nodes sleep 0.1 if ttl < Configuration::REQUEST_TTL/2 end end end end |