redis/redis-py · error · DataError
Only one of ```maxlen``` or ```minid``` may be specified
Error message
Only one of ```maxlen``` or ```minid``` may be specified
What it means
Raised by xadd() when both maxlen and minid are specified. MAXLEN trims the stream by count and MINID trims by entry ID; these are mutually exclusive trimming strategies for XADD. It is a DataError.
Solutions
- Choose one trimming strategy: use maxlen for count-based trimming or minid for ID-based trimming.
- If you need both constraints, trim in a separate call (e.g. client.xtrim with one criterion).
Example fix
# before
client.xadd('mystream', {'f': 'v'}, maxlen=1000, minid='1234-0')
# after
client.xadd('mystream', {'f': 'v'}, minid='1234-0') Defensive patterns
Strategy: validation
Validate before calling
if maxlen is not None and minid is not None:
raise ValueError('Specify only one of maxlen or minid for trimming')
client.xadd(name, fields, maxlen=maxlen, minid=minid) Try / catch
from redis.exceptions import DataError
try:
client.xadd(name, fields, maxlen=maxlen, minid=minid)
except DataError as e:
if 'maxlen' in str(e) and 'minid' in str(e):
minid = None
client.xadd(name, fields, maxlen=maxlen) Prevention
- Decide trimming strategy once per stream (count vs ID) and store only that parameter.
- Do not carry both maxlen and minid through a shared config object.
When it happens
Trigger: Calling client.xadd('mystream', fields, maxlen=1000, minid='1234-0'), or passing both through a config object.
Common situations: Combining count-based and ID-based trimming in one call, or migrating from maxlen to minid and forgetting to remove the old parameter.
Related errors
- Only one of ```idmpauto``` or ```idmp``` may be specified
- XADD maxlen must be non-negative integer
- IDMPAUTO and IDMP can only be used with id='*'
- XADD fields must be a non-empty dict
- XADD idmp must be a tuple of (producer_id, idempotent_id)
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/0555116dea76d609.
Report an issue: GitHub.
Appendix: source
Thrown at redis/commands/core.py:7016
- DELREF: When trimming, removes all references from consumer groups' PEL
- ACKED: When trimming, only removes entries acknowledged by all consumer groups
idmpauto: Producer ID for automatic idempotent ID calculation.
Automatically calculates an idempotent ID based on entry content to prevent
duplicate entries. Can only be used with id='*'. Creates an IDMP map if it
doesn't exist yet. The producer ID must be unique per producer and consistent
across restarts.
idmp: Tuple of (producer_id, idempotent_id) for explicit idempotent ID.
Uses a specific idempotent ID to prevent duplicate entries. Can only be used
with id='*'. The producer ID must be unique per producer and consistent across
restarts. The idempotent ID must be unique per message and per producer.
Shorter idempotent IDs require less memory and allow faster processing.
Creates an IDMP map if it doesn't exist yet.
For more information, see https://redis.io/commands/xadd
"""
pieces: list[EncodableT] = []
if maxlen is not None and minid is not None:
raise DataError("Only one of ```maxlen``` or ```minid``` may be specified")
if idmpauto is not None and idmp is not None:
raise DataError("Only one of ```idmpauto``` or ```idmp``` may be specified")
if (idmpauto is not None or idmp is not None) and id != "*":
raise DataError("IDMPAUTO and IDMP can only be used with id='*'")
if ref_policy is not None and ref_policy not in {"KEEPREF", "DELREF", "ACKED"}:
raise DataError("XADD ref_policy must be one of: KEEPREF, DELREF, ACKED")
if nomkstream:
pieces.append(b"NOMKSTREAM")
if ref_policy is not None:
pieces.append(ref_policy)
if idmpauto is not None:
pieces.extend([b"IDMPAUTO", idmpauto])
if idmp is not None:
if not isinstance(idmp, tuple) or len(idmp) != 2:View on GitHub (pinned to 6a6b581b48)