Sha256: ad8f6e0088cbd0f33f5639e60f8e5f5c9b3263c75cf7122e99575eb4814433bf

Contents?: true

Size: 489 Bytes

Versions: 4

Compression:

Stored size: 489 Bytes

Contents

module RedisCluster

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

    # hash tag 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

    # check if keys at same slot
    def self.at_one?(keys)
      keys.map { |k| slot_by(k) }.uniq.size == 1
    end

  end # end Slot

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redis_cluster-0.3.2 lib/redis_cluster/slot.rb
redis_cluster-0.3.1 lib/redis_cluster/slot.rb
redis_cluster-0.3.0 lib/redis_cluster/slot.rb
redis_cluster-0.2.9 lib/redis_cluster/slot.rb