{"id":"0555116dea76d609","repo":"redis/redis-py","slug":"only-one-of-maxlen-or-minid-may-be-spe","errorCode":null,"errorMessage":"Only one of ```maxlen``` or ```minid``` may be specified","messagePattern":"Only one of ```maxlen``` or ```minid``` may be specified","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":7016,"sourceCode":"            - DELREF: When trimming, removes all references from consumer groups' PEL\n            - ACKED: When trimming, only removes entries acknowledged by all consumer groups\n        idmpauto: Producer ID for automatic idempotent ID calculation.\n            Automatically calculates an idempotent ID based on entry content to prevent\n            duplicate entries. Can only be used with id='*'. Creates an IDMP map if it\n            doesn't exist yet. The producer ID must be unique per producer and consistent\n            across restarts.\n        idmp: Tuple of (producer_id, idempotent_id) for explicit idempotent ID.\n            Uses a specific idempotent ID to prevent duplicate entries. Can only be used\n            with id='*'. The producer ID must be unique per producer and consistent across\n            restarts. The idempotent ID must be unique per message and per producer.\n            Shorter idempotent IDs require less memory and allow faster processing.\n            Creates an IDMP map if it doesn't exist yet.\n\n        For more information, see https://redis.io/commands/xadd\n        \"\"\"\n        pieces: list[EncodableT] = []\n        if maxlen is not None and minid is not None:\n            raise DataError(\"Only one of ```maxlen``` or ```minid``` may be specified\")\n\n        if idmpauto is not None and idmp is not None:\n            raise DataError(\"Only one of ```idmpauto``` or ```idmp``` may be specified\")\n\n        if (idmpauto is not None or idmp is not None) and id != \"*\":\n            raise DataError(\"IDMPAUTO and IDMP can only be used with id='*'\")\n\n        if ref_policy is not None and ref_policy not in {\"KEEPREF\", \"DELREF\", \"ACKED\"}:\n            raise DataError(\"XADD ref_policy must be one of: KEEPREF, DELREF, ACKED\")\n\n        if nomkstream:\n            pieces.append(b\"NOMKSTREAM\")\n        if ref_policy is not None:\n            pieces.append(ref_policy)\n        if idmpauto is not None:\n            pieces.extend([b\"IDMPAUTO\", idmpauto])\n        if idmp is not None:\n            if not isinstance(idmp, tuple) or len(idmp) != 2:","sourceCodeStart":6998,"sourceCodeEnd":7034,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L6998-L7034","documentation":"Raised by xadd() when both maxlen and minid are provided. MAXLEN trims the stream by length while MINID trims by ID; Redis only allows one trimming strategy per XADD, so the client rejects specifying both.","triggerScenarios":"Calling client.xadd(name, fields, maxlen=1000, minid='1234-0').","commonSituations":"Layering two trimming strategies; merging config that sets maxlen with code that sets minid; misunderstanding that they are alternative trim modes.","solutions":["Use maxlen for length-based trimming, or minid for ID-based trimming, but not both.","Decide on a single retention strategy per stream and pass only that argument.","If you need both behaviors, choose the stricter single strategy that satisfies your retention requirement."],"exampleFix":"# before\nawait r.xadd('s', {'f': 'v'}, maxlen=1000, minid='1234-0')\n# after\nawait r.xadd('s', {'f': 'v'}, maxlen=1000)","handlingStrategy":"validation","validationCode":"def validate_xadd_trim(maxlen, minid):\n    if maxlen is not None and minid is not None:\n        raise ValueError('Specify maxlen OR minid, not both')\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose one trimming strategy per stream: length (maxlen) or ID (minid).","Centralize retention config so both cannot be set together.","Remember approximate trimming (~) applies to whichever strategy you pick."],"tags":["stream","xadd","trim","validation","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}