Sha256: b9e15711dc2f9bb000481cc07ce17875af3236b5db6a69648d18ff274c316be1

Contents?: true

Size: 298 Bytes

Versions: 12

Compression:

Stored size: 298 Bytes

Contents

require 'zlib'

module ActiveRecord
  module ShardFor
    class HashModuloRouter < ConnectionRouter
      # @param [String] key sharding key
      def route(key)
        hash(key) % connection_count
      end

      private

      def hash(v)
        Zlib.crc32(v.to_s)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
activerecord-shard_for-0.7.0 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.6.1 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.6.0 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.5.0 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.4.1 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.4.0 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.3.0 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.2.1 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.2.0 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.1.2 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.1.1 lib/activerecord/shard_for/hash_modulo_router.rb
activerecord-shard_for-0.1.0 lib/activerecord/shard_for/hash_modulo_router.rb