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)
| 10 | |
| 11 | |
| 12 | def 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 |
no outgoing calls