Get the node that holds the key's slot. If replica set to True but the slot doesn't have any replicas, None is returned.
(self, key, replica=False)
| 1041 | return list(self.nodes_manager.nodes_cache.values()) |
| 1042 | |
| 1043 | def get_node_from_key(self, key, replica=False): |
| 1044 | """ |
| 1045 | Get the node that holds the key's slot. |
| 1046 | If replica set to True but the slot doesn't have any replicas, None is |
| 1047 | returned. |
| 1048 | """ |
| 1049 | slot = self.keyslot(key) |
| 1050 | slot_cache = self.nodes_manager.slots_cache.get(slot) |
| 1051 | if slot_cache is None or len(slot_cache) == 0: |
| 1052 | raise SlotNotCoveredError(f'Slot "{slot}" is not covered by the cluster.') |
| 1053 | if replica and len(self.nodes_manager.slots_cache[slot]) < 2: |
| 1054 | return None |
| 1055 | elif replica: |
| 1056 | node_idx = 1 |
| 1057 | else: |
| 1058 | # primary |
| 1059 | node_idx = 0 |
| 1060 | |
| 1061 | return slot_cache[node_idx] |
| 1062 | |
| 1063 | def get_default_node(self): |
| 1064 | """ |