Server : LiteSpeed System : Linux in-mum-web1112.main-hosting.eu 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64 User : u451330669 ( 451330669) PHP Version : 8.2.27 Disable Function : NONE Directory : /opt/alt/python311/lib/python3.11/site-packages/redis/ |
from binascii import crc_hqx
# Redis Cluster's key space is divided into 16384 slots.
# For more information see: https://github.com/redis/redis/issues/2576
REDIS_CLUSTER_HASH_SLOTS = 16384
__all__ = ["key_slot", "REDIS_CLUSTER_HASH_SLOTS"]
def key_slot(key, bucket=REDIS_CLUSTER_HASH_SLOTS):
"""Calculate key slot for a given key.
See Keys distribution model in https://redis.io/topics/cluster-spec
:param key - bytes
:param bucket - int
"""
start = key.find(b"{")
if start > -1:
end = key.find(b"}", start + 1)
if end > -1 and end != start + 1:
key = key[start + 1 : end]
return crc_hqx(key, 0) % bucket