Class: MixedGauge::Routing

Inherits:
Object
  • Object
show all
Defined in:
lib/mixed_gauge/routing.rb

Overview

Routing from key to database connection

Instance Method Summary collapse

Constructor Details

#initialize(cluster_config) ⇒ Routing

Returns a new instance of Routing.

Parameters:



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

Parameters:

  • key (String)

Returns:

  • (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)

Parameters:

  • dist_key (String)

Returns:

  • (String)

    connection name



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