class RedisCluster::Slot

Constants

KEY_PATTERN

Public Class Methods

at_one?(keys) click to toggle source

check if keys at same slot

# File lib/redis_cluster/slot.rb, line 16
def self.at_one?(keys)
  keys.map { |k| slot_by(k) }.uniq.size == 1
end
slot_by(key) click to toggle source

hash tag key “{xxx}ooo” will calculate “xxx” for slot if key is “{}dddd”, calculate “{}dddd” for slot

# File lib/redis_cluster/slot.rb, line 8
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