Exemple #1
0
    def swapdb(self, *args, **kwargs) -> NoReturn:
        """
        Swaps two Redis databases.

        For more information see https://redis.io/commands/swapdb
        """
        raise RedisClusterException("SWAPDB is not supported in cluster mode")
Exemple #2
0
def wait_for_cluster_creation(redis_url, cluster_nodes, timeout=60):
    """
    Waits for the cluster creation to complete.
    As soon as all :cluster_nodes: nodes become available, the cluster will be
    considered ready.
    :param redis_url: the cluster's url, e.g. redis://localhost:16379/0
    :param cluster_nodes: The number of nodes in the cluster
    :param timeout: the amount of time to wait (in seconds)
    """
    now = time.time()
    end_time = now + timeout
    client = None
    print(f"Waiting for {cluster_nodes} cluster nodes to become available")
    while now < end_time:
        try:
            client = redis.RedisCluster.from_url(redis_url)
            if len(client.get_nodes()) == int(cluster_nodes):
                print("All nodes are available!")
                break
        except RedisClusterException:
            pass
        time.sleep(1)
        now = time.time()
    if now >= end_time:
        available_nodes = 0 if client is None else len(client.get_nodes())
        raise RedisClusterException(
            f"The cluster did not become available after {timeout} seconds. "
            f"Only {available_nodes} nodes out of {cluster_nodes} are available"
        )
Exemple #3
0
    def replicaof(self, *args, **kwargs) -> NoReturn:
        """
        Make the server a replica of another instance, or promote it as master.

        For more information see https://redis.io/commands/replicaof
        """
        raise RedisClusterException("REPLICAOF is not supported in cluster mode")
Exemple #4
0
 def my_bad_function() -> int:
     nonlocal fails_left
     fails_left -= 1
     if fails_left > 0:
         raise RedisClusterException(
             "All slots are not covered after query all startup_nodes.")
     return 1
Exemple #5
0
 def swapdb(self, *args, **kwargs):
     raise RedisClusterException("SWAPDB is not supported in cluster" " mode")
Exemple #6
0
 def replicaof(self, *args, **kwargs):
     raise RedisClusterException("REPLICAOF is not supported in cluster" " mode")
Exemple #7
0
 def slaveof(self, *args, **kwargs):
     raise RedisClusterException("SLAVEOF is not supported in cluster mode")