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

Method replace_default_node

redis/cluster.py:613–635  ·  view source on GitHub ↗

Replace the default cluster node. A random cluster node will be chosen if target_node isn't passed, and primaries will be prioritized. The default node will not be changed if there are no other nodes in the cluster. Args: target_node (ClusterNode, optiona

(self, target_node: "ClusterNode" = None)

Source from the content-addressed store, hash-verified

611 )
612
613 def replace_default_node(self, target_node: "ClusterNode" = None) -> None:
614 """Replace the default cluster node.
615 A random cluster node will be chosen if target_node isn't passed, and primaries
616 will be prioritized. The default node will not be changed if there are no other
617 nodes in the cluster.
618
619 Args:
620 target_node (ClusterNode, optional): Target node to replace the default
621 node. Defaults to None.
622 """
623 if target_node:
624 self.nodes_manager.default_node = target_node
625 else:
626 curr_node = self.get_default_node()
627 primaries = [node for node in self.get_primaries() if node != curr_node]
628 if primaries:
629 # Choose a primary if the cluster contains different primaries
630 self.nodes_manager.default_node = random.choice(primaries)
631 else:
632 # Otherwise, choose a primary if the cluster contains different primaries
633 replicas = [node for node in self.get_replicas() if node != curr_node]
634 if replicas:
635 self.nodes_manager.default_node = random.choice(replicas)
636
637
638class RedisCluster(

Calls 3

get_default_nodeMethod · 0.45
get_primariesMethod · 0.45
get_replicasMethod · 0.45