Sha256: 6f879b4adfeb7f610087832d39f12bea69825ee2d24367bd46a2958beaf6ebef

Contents?: true

Size: 544 Bytes

Versions: 4

Compression:

Stored size: 544 Bytes

Contents

require 'digest/md5'

module MixedGauge
  class Routing
    # @param [ClusterConfig] cluster_config
    def initialize(cluster_config)
      @cluster_config = cluster_config
    end

    # slot can be one of (0..slot_size - 1)
    # @param [String] dist_key
    # @return [String] connection name
    def route(key)
      slot = hash_f(key) % @cluster_config.slot_size
      @cluster_config.fetch(slot)
    end

    # @param [String] key
    # @return [Integer]
    def hash_f(key)
      MixedGauge.config.hash_proc.call(key)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mixed_gauge-1.2.0.beta2 lib/mixed_gauge/routing.rb
mixed_gauge-1.2.0.beta1 lib/mixed_gauge/routing.rb
mixed_gauge-1.1.0 lib/mixed_gauge/routing.rb
mixed_gauge-1.0.0 lib/mixed_gauge/routing.rb