redis/redis-py · error · NotImplementedError

CLUSTER FLUSHSLOTS is intentionally not implemented in the c

Error message

CLUSTER FLUSHSLOTS is intentionally not implemented in the client.

What it means

cluster_flushslots() unconditionally raises NotImplementedError. The client intentionally does not expose CLUSTER FLUSHSLOTS because flushing slots on a cluster node is a destructive cluster-administration operation that the maintainers chose not to wire up. There is no input that avoids it — calling the method is itself the error.

Source

Thrown at redis/commands/cluster.py:1021

        self: AsyncClientProtocol, target_node: "TargetNodesT"
    ) -> Awaitable[ClusterLinksResponse]: ...

    def cluster_links(
        self, target_node: "TargetNodesT"
    ) -> ClusterLinksResponse | Awaitable[ClusterLinksResponse]:
        """
        Each node in a Redis Cluster maintains a pair of long-lived TCP link with each
        peer in the cluster: One for sending outbound messages towards the peer and one
        for receiving inbound messages from the peer.

        This command outputs information of all such peer links as an array.

        For more information see https://redis.io/commands/cluster-links
        """
        return self.execute_command("CLUSTER LINKS", target_nodes=target_node)

    def cluster_flushslots(self, target_nodes: "TargetNodesT" | None = None) -> None:
        raise NotImplementedError(
            "CLUSTER FLUSHSLOTS is intentionally not implemented in the client."
        )

    def cluster_bumpepoch(self, target_nodes: "TargetNodesT" | None = None) -> None:
        raise NotImplementedError(
            "CLUSTER BUMPEPOCH is intentionally not implemented in the client."
        )

    def readonly(self, target_nodes: "TargetNodesT" | None = None) -> ResponseT:
        """
        Enables read queries.
        The command will be sent to the default cluster node if target_nodes is
        not specified.

        For more information see https://redis.io/commands/readonly
        """
        if target_nodes == "replicas" or target_nodes == "all":
            # read_from_replicas will only be enabled if the READONLY command

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Stop calling cluster_flushslots — it is deliberately unsupported and will never execute.
  2. If you truly need the behavior, run the raw command via r.execute_command('CLUSTER', 'FLUSHSLOTS') against a specific node, understanding the cluster-damaging consequences.
  3. For test isolation, flush the node's data with FLUSHALL / FLUSHDB and rebuild the cluster instead of using FLUSHSLOTS.

Example fix

# before
r.cluster_flushslots()
# after (only if you accept the risk, against one node)
r.execute_command('CLUSTER', 'FLUSHSLOTS')
Defensive patterns

Strategy: validation

Validate before calling

# There is no valid call. Guard by feature-checking instead:
if hasattr(client, 'cluster_flushslots') and callable(client.cluster_flushslots):
    # cluster_flushslots always raises NotImplementedError on the cluster client
    raise RuntimeError('cluster_flushslots is intentionally unsupported; use raw execute_command if absolutely necessary')

Type guard

import redis
def supports_cluster_flushslots(client) -> bool:
    # The method exists on the cluster client but always raises.
    return False

Try / catch

try:
    client.cluster_flushslots()
except NotImplementedError:
    # not supported; fall back to raw command only if you accept the risk
    client.execute_command('CLUSTER', 'FLUSHSLOTS')

Prevention

When it happens

Trigger: Calling r.cluster_flushslots() on a RedisCluster client (sync or async). The method body at redis/commands/cluster.py:1020-1023 always raises before doing anything.

Common situations: Discovering the method via IDE autocomplete or dir() and assuming it works; migrating tooling from another client that exposes FLUSHSLOTS; test teardown scripts trying to wipe slot assignments.

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/f6924f074a23de83.json. Report an issue: GitHub.