Sha256: 703840cef198d0ab35763c864f630d6043724db4c7d775dd9f5c4157b9b92610

Contents?: true

Size: 472 Bytes

Versions: 7

Compression:

Stored size: 472 Bytes

Contents

module RedisRing
  module Client

    class Sharder

      attr_reader :metadata

      def initialize(metadata)
        @metadata = metadata
      end

      def shard_for_key(key)
        crc = Zlib.crc32(hashable_part(key.to_s))
        return crc % metadata.ring_size
      end

      private

      def hashable_part(key)
        if key =~ /{([^}]*)}$/
          return Regexp.last_match(1)
        else
          return key
        end
      end

    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
redis_ring_client-0.1.2 lib/redis_ring/client/sharder.rb
redis_ring_client-0.1.1 lib/redis_ring/client/sharder.rb
redis_ring_client-0.1.0 lib/redis_ring/client/sharder.rb
redis_ring_client-0.0.4 lib/redis_ring/client/sharder.rb
redis_ring_client-0.0.3 lib/redis_ring/client/sharder.rb
redis_ring_client-0.0.2 lib/redis_ring/client/sharder.rb
redis_ring_client-0.0.1 lib/redis_ring/client/sharder.rb