Sha256: cead79093f330699960fcd340452f67602618a35567c0bb8f0445c0c72d79d36

Contents?: true

Size: 362 Bytes

Versions: 7

Compression:

Stored size: 362 Bytes

Contents

module RedisCluster

  class Slot
    KEY_PATTERN = /\{([^\}]*)\}/

    # key "{xxx}ooo" will calculate "xxx" for slot
    # if key is "{}dddd", calculate "{}dddd" for slot
    def self.slot_by(key)
      key = key.to_s
      KEY_PATTERN =~ key
      key = $1 if $1 && !$1.empty?
      CRC16.crc16(key) % Configuration::HASH_SLOTS
    end

  end # end Slot

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
redis_cluster-0.2.6 lib/redis_cluster/slot.rb
redis_cluster-0.2.5 lib/redis_cluster/slot.rb
redis_cluster-0.2.4 lib/redis_cluster/slot.rb
redis_cluster-0.2.3 lib/redis_cluster/slot.rb
redis_cluster-0.2.1 lib/redis_cluster/slot.rb
redis_cluster-0.2.0 lib/redis_cluster/slot.rb
redis_cluster-0.1.9 lib/redis_cluster/slot.rb