redis/redis-py · error · RedisClusterException

method load_scripts() is not implemented

Error message

method load_scripts() is not implemented

What it means

ClusterPipeline.load_scripts() routes to AbstractStrategy.load_scripts() (redis/cluster.py:4107), a stub that always raises. In standalone redis-py this helper SCRIPT LOADs every script the pipeline will run; in cluster mode scripts must be loaded on every primary (scripts are not propagated like data), so the pipeline-level helper is intentionally unimplemented.

Source

Thrown at redis/cluster.py:4109

    def send_cluster_commands(
        self, stack, raise_on_error=True, allow_redirections=True
    ):
        pass

    @abstractmethod
    def reset(self):
        pass

    def exists(self, *keys):
        return self.execute_command("EXISTS", *keys)

    def eval(self):
        """ """
        raise RedisClusterException("method eval() is not implemented")

    def load_scripts(self):
        """ """
        raise RedisClusterException("method load_scripts() is not implemented")

    def script_load_for_pipeline(self, *args, **kwargs):
        """ """
        raise RedisClusterException(
            "method script_load_for_pipeline() is not implemented"
        )

    def annotate_exception(self, exception, number, command):
        """
        Provides extra context to the exception prior to it being handled
        """
        cmd = " ".join(map(safe_str, command))
        msg = (
            f"Command # {number} ({truncate_text(cmd)}) of pipeline "
            f"caused error: {exception.args[0]}"
        )
        exception.args = (msg,) + exception.args[1:]

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Load the script explicitly on all primaries: rc.script_load(script, target_nodes=RedisCluster.PRIMARIES), then call EVAL by SHA via the cluster client.
  2. Prefer Redis 7 Functions (FUNCTION LOAD) over ad-hoc SCRIPT LOAD when targeting a cluster.
  3. Remove the pipe.load_scripts() call entirely; the cluster client does not require pipeline-level script preloading.

Example fix

# before
pipe = rc.pipeline()
pipe.load_scripts()

# after
sha = rc.script_load(script, target_nodes=RedisCluster.PRIMARIES)
rc.evalsha(sha, numkeys, *keys)
Defensive patterns

Strategy: validation

Validate before calling

from redis.cluster import RedisCluster

def ensure_scripts_loaded(client, script):
    if isinstance(client, RedisCluster):
        # load on every primary; do not use pipeline.load_scripts()
        return client.script_load(script, target_nodes=RedisCluster.PRIMARIES)
    pipe = client.pipeline()
    pipe.load_scripts()
    pipe.execute()
    return None

Type guard

from redis.cluster import RedisCluster

def is_cluster_client(client) -> bool:
    return isinstance(client, RedisCluster)

Try / catch

from redis.exceptions import RedisClusterException

try:
    pipe.load_scripts()
except RedisClusterException:
    rc.script_load(script, target_nodes=RedisCluster.PRIMARIES)

Prevention

When it happens

Trigger: Calling pipe.load_scripts() on a RedisCluster pipeline. Path: ClusterPipeline.load_scripts (redis/cluster.py:3726) -> self._execution_strategy.load_scripts() -> raises at redis/cluster.py:4109.

Common situations: Standalone pipeline code that pre-loads scripts before EVAL is reused verbatim against a RedisCluster client. Migration from non-cluster to cluster topology without auditing pipeline helper usage.

Related errors


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