{"id":"feb1da68ea3962b9","repo":"redis/redis-py","slug":"method-load-scripts-is-not-implemented","errorCode":null,"errorMessage":"method load_scripts() is not implemented","messagePattern":"method load_scripts\\(\\) is not implemented","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":4109,"sourceCode":"    def send_cluster_commands(\n        self, stack, raise_on_error=True, allow_redirections=True\n    ):\n        pass\n\n    @abstractmethod\n    def reset(self):\n        pass\n\n    def exists(self, *keys):\n        return self.execute_command(\"EXISTS\", *keys)\n\n    def eval(self):\n        \"\"\" \"\"\"\n        raise RedisClusterException(\"method eval() is not implemented\")\n\n    def load_scripts(self):\n        \"\"\" \"\"\"\n        raise RedisClusterException(\"method load_scripts() is not implemented\")\n\n    def script_load_for_pipeline(self, *args, **kwargs):\n        \"\"\" \"\"\"\n        raise RedisClusterException(\n            \"method script_load_for_pipeline() is not implemented\"\n        )\n\n    def annotate_exception(self, exception, number, command):\n        \"\"\"\n        Provides extra context to the exception prior to it being handled\n        \"\"\"\n        cmd = \" \".join(map(safe_str, command))\n        msg = (\n            f\"Command # {number} ({truncate_text(cmd)}) of pipeline \"\n            f\"caused error: {exception.args[0]}\"\n        )\n        exception.args = (msg,) + exception.args[1:]\n","sourceCodeStart":4091,"sourceCodeEnd":4127,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/cluster.py#L4091-L4127","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Load the script explicitly on all primaries: rc.script_load(script, target_nodes=RedisCluster.PRIMARIES), then call EVAL by SHA via the cluster client.","Prefer Redis 7 Functions (FUNCTION LOAD) over ad-hoc SCRIPT LOAD when targeting a cluster.","Remove the pipe.load_scripts() call entirely; the cluster client does not require pipeline-level script preloading."],"exampleFix":"# before\npipe = rc.pipeline()\npipe.load_scripts()\n\n# after\nsha = rc.script_load(script, target_nodes=RedisCluster.PRIMARIES)\nrc.evalsha(sha, numkeys, *keys)","handlingStrategy":"validation","validationCode":"from redis.cluster import RedisCluster\n\ndef ensure_scripts_loaded(client, script):\n    if isinstance(client, RedisCluster):\n        # load on every primary; do not use pipeline.load_scripts()\n        return client.script_load(script, target_nodes=RedisCluster.PRIMARIES)\n    pipe = client.pipeline()\n    pipe.load_scripts()\n    pipe.execute()\n    return None","typeGuard":"from redis.cluster import RedisCluster\n\ndef is_cluster_client(client) -> bool:\n    return isinstance(client, RedisCluster)","tryCatchPattern":"from redis.exceptions import RedisClusterException\n\ntry:\n    pipe.load_scripts()\nexcept RedisClusterException:\n    rc.script_load(script, target_nodes=RedisCluster.PRIMARIES)","preventionTips":["Never call load_scripts() on a cluster pipeline; load scripts explicitly on all primaries.","Use Functions instead of SCRIPT LOAD for new cluster work.","Grep the codebase for 'load_scripts' before switching a client from standalone to cluster."],"tags":["cluster","pipeline","scripting","not-implemented"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}