redis/redis-py · error · ResponseError
Wrong number of response items from pipeline execution
Error message
Wrong number of response items from pipeline execution
What it means
Raised by Pipeline._execute_transaction (redis/asyncio/client.py:2082) when the number of items in the EXEC response does not equal the number of queued commands. This indicates a protocol desync — the client and server disagree about how many replies are on the wire. The library disconnects the connection (to reset protocol state) and raises ResponseError.
Source
Thrown at redis/asyncio/client.py:2082
except ExecAbortError as err:
if errors:
raise errors[0][1] from err
raise
# EXEC clears any watched keys
self.watching = False
if response is None:
raise WatchError("Watched variable changed.") from None
# put any parse errors into the response
for i, e in errors:
response.insert(i, e)
if len(response) != len(commands):
if self.connection:
await self.connection.disconnect()
raise ResponseError(
"Wrong number of response items from pipeline execution"
) from None
# find any errors in the response and raise if necessary
if raise_on_error:
self.raise_first_error(commands, response)
# We have to run response callbacks manually
data = []
for r, cmd in zip(response, commands):
if not isinstance(r, Exception):
args, options = cmd
command_name = args[0]
# Remove keys entry, it needs only for cache.
options.pop("keys", None)
if command_name in self.response_callbacks:View on GitHub (pinned to da03cdc7e8)
Solutions
- Report it as a bug: capture redis-py version, server version, and the exact command stack.
- Ensure no custom response_callback consumes/returns multiple frames for a single command.
- Disconnect and rebuild the client (the library already disconnects the offending connection).
- Test against a direct Redis node rather than a proxy/gateway to isolate the cause.
Defensive patterns
Strategy: try-catch
Try / catch
from redis.exceptions import ResponseError
try:
await pipe.execute()
except ResponseError as e:
if 'Wrong number of response items' in str(e):
log.exception('pipeline protocol desync; reconnecting')
await r.connection_pool.disconnect()
raise Prevention
- Keep response_callbacks minimal and single-frame per command.
- Report occurrences with redis-py and server versions — this signals a real bug.
- Avoid proxies that rewrite transaction replies.
When it happens
Trigger: A corrupted or out-of-sync connection where EXEC returns the wrong arity: typically a library/server bug, a partial command drop, or commands that the server rejected in a way that changed reply count. This is a defensive check, not normal control flow.
Common situations: Extremely rare in normal use; seen with intermediary proxies that mis-shape transaction replies, custom response callbacks that consume extra frames, or version skew between client and server on a command's reply shape.
Related errors
- Cannot issue nested calls to MULTI
- Commands without an initial WATCH have already been issued
- A {type(error).__name__} occurred while watching one or more
- Watched variable changed.
- Cannot issue a WATCH after a MULTI
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/13ac6c5b43fd0daf.json.
Report an issue: GitHub.