Class: RedisCluster::Slot

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_cluster/slot.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.slot_by(key) ⇒ Object

key “xxxooo” will calculate “xxx” for slot if key is “{}dddd”, calculate “{}dddd” for slot



8
9
10
11
12
13
# 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