Class: LoadBalancer::Randomized
- Defined in:
- lib/multi_dbs_load_balancer/load_balancer/randomized.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 |
# File 'lib/multi_dbs_load_balancer/load_balancer/randomized.rb', line 5 def next_db(**) r = random_index return @database_configs[r], r if db_available?(r) next_dbs = (r+1...r+@database_configs.size).map { |i| i % @database_configs.size } fail_over(next_dbs) end |