MCPcopy
hub / github.com/redis/redis-py / key_slot

Function key_slot

redis/crc.py:12–23  ·  view source on GitHub ↗

Calculate key slot for a given key. See Keys distribution model in https://redis.io/topics/cluster-spec :param key - bytes :param bucket - int

(key: EncodedT, bucket: int = REDIS_CLUSTER_HASH_SLOTS)

Source from the content-addressed store, hash-verified

10
11
12def key_slot(key: EncodedT, bucket: int = REDIS_CLUSTER_HASH_SLOTS) -> int:
13 """Calculate key slot for a given key.
14 See Keys distribution model in https://redis.io/topics/cluster-spec
15 :param key - bytes
16 :param bucket - int
17 """
18 start = key.find(b"{")
19 if start > -1:
20 end = key.find(b"}", start + 1)
21 if end > -1 and end != start + 1:
22 key = key[start + 1 : end]
23 return crc_hqx(key, 0) % bucket

Calls

no outgoing calls