Class: MixedGauge::Routing
- Inherits:
-
Object
- Object
- MixedGauge::Routing
- Defined in:
- lib/mixed_gauge/routing.rb
Overview
Routing from key to database connection
Instance Method Summary collapse
- #hash_f(key) ⇒ Integer
-
#initialize(cluster_config) ⇒ Routing
constructor
A new instance of Routing.
-
#route(key) ⇒ String
slot can be one of (0..slot_size - 1).
Constructor Details
#initialize(cluster_config) ⇒ Routing
Returns a new instance of Routing.
7 8 9 |
# File 'lib/mixed_gauge/routing.rb', line 7 def initialize(cluster_config) @cluster_config = cluster_config end |
Instance Method Details
#hash_f(key) ⇒ Integer
21 22 23 |
# File 'lib/mixed_gauge/routing.rb', line 21 def hash_f(key) MixedGauge.config.hash_proc.call(key) end |
#route(key) ⇒ String
slot can be one of (0..slot_size - 1)
14 15 16 17 |
# File 'lib/mixed_gauge/routing.rb', line 14 def route(key) slot = hash_f(key) % @cluster_config.slot_size @cluster_config.fetch(slot) end |