redis/redis-py · error · RedisClusterException

deleting multiple keys is not implemented in pipeline comman

Error message

deleting multiple keys is not implemented in pipeline command

What it means

PipelineStrategy.delete() (redis/cluster.py:4544) raises RedisClusterException when len(names) != 1. In a cluster pipeline, DEL is constrained to a single key per call because multi-key DEL would require all keys to share a hash slot and the pipeline does not group them. Call delete() once per key instead.

Source

Thrown at redis/cluster.py:4546

    def discard(self):
        raise RedisClusterException(
            "method discard() is not supported outside of transactional context"
        )

    def watch(self, *names):
        raise RedisClusterException(
            "method watch() is not supported outside of transactional context"
        )

    def unwatch(self, *names):
        raise RedisClusterException(
            "method unwatch() is not supported outside of transactional context"
        )

    def delete(self, *names):
        if len(names) != 1:
            raise RedisClusterException(
                "deleting multiple keys is not implemented in pipeline command"
            )

        return self.execute_command("DEL", names[0])

    def unlink(self, *names):
        if len(names) != 1:
            raise RedisClusterException(
                "unlinking multiple keys is not implemented in pipeline command"
            )

        return self.execute_command("UNLINK", names[0])


class TransactionStrategy(AbstractStrategy):
    NO_SLOTS_COMMANDS = {"UNWATCH"}
    IMMEDIATE_EXECUTE_COMMANDS = {"WATCH", "UNWATCH"}
    UNWATCH_COMMANDS = {"DISCARD", "EXEC", "UNWATCH"}

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Delete each key in its own pipeline entry: for k in keys: pipe.delete(k).
  2. If all keys can be hashed to one slot via a hash tag (e.g. {tag}k1, {tag}k2), still delete them one per call through the pipeline.
  3. For bulk deletion without a pipeline, use rc.delete(*keys) only if keys share a slot; otherwise loop.

Example fix

# before
pipe = rc.pipeline()
pipe.delete('k1', 'k2')  # raises: deleting multiple keys
pipe.execute()

# after
pipe = rc.pipeline()
for k in ['k1', 'k2']:
    pipe.delete(k)
pipe.execute()
Defensive patterns

Strategy: validation

Validate before calling

def pipeline_delete(pipe, keys):
    # cluster pipeline requires one delete() per key
    for k in keys:
        pipe.delete(k)
    return pipe

Try / catch

from redis.exceptions import RedisClusterException

try:
    pipe.delete(*keys)
except RedisClusterException as e:
    if 'multiple keys' in str(e):
        for k in keys:
            pipe.delete(k)
    else:
        raise

Prevention

When it happens

Trigger: Calling pipe.delete('k1','k2') (two or more keys, or zero keys) on a cluster pipeline. The length check at redis/cluster.py:4545 fails for any count other than 1.

Common situations: Reusing standalone pipeline code that batches a multi-key DEL. Cleanup routines that delete a list of keys in one call. Migration from non-cluster redis where pipe.delete(*keys) is allowed.

Related errors


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