Class: LoadBalancer::Hash
- Defined in:
- lib/multi_dbs_load_balancer/load_balancer/hash.rb
Instance Attribute Summary
Attributes inherited from Algo
#database_configs, #key, #redis
Instance Method Summary collapse
Methods inherited from Algo
#after_connected, #after_executed, #connected_to_next_db, #fail_over, #initialize, #warm_up
Methods included from Healthcheck
#db_available?, #mark_db_down, #mark_redis_down, #redis_available?
Methods included from RedisLua
Constructor Details
This class inherits a constructor from LoadBalancer::Algo
Instance Method Details
#next_db(**options) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/multi_dbs_load_balancer/load_balancer/hash.rb', line 5 def next_db(**) db_index = hash_to_index(**) return @database_configs[db_index], db_index if db_available?(db_index) # fail over next_dbs = (db_index+1...db_index+@database_configs.size).map { |i| i % @database_configs.size } fail_over(next_dbs) end |