{"id":"825521623d1d4b05","repo":"redis/redis-py","slug":"only-one-of-ifeq-ifne-ifdeq-ifdne-may-be-specified","errorCode":null,"errorMessage":"Only one of IFEQ/IFNE/IFDEQ/IFDNE may be specified","messagePattern":"Only one of IFEQ/IFNE/IFDEQ/IFDNE may be specified","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":2932,"sourceCode":"            ifeq match-valu: Optional[Union[bytes, str]] - Delete the key only if its value is equal to match-value\n            ifne match-value: Optional[Union[bytes, str]] - Delete the key only if its value is not equal to match-value\n            ifdeq match-digest: Optional[str] - Delete the key only if the digest of its value is equal to match-digest\n            ifdne match-digest: Optional[str] - Delete the key only if the digest of its value is not equal to match-digest\n\n        Returns:\n            int: 1 if the key was deleted, 0 otherwise.\n        Raises:\n            redis.exceptions.ResponseError: if key exists but is not a string\n                                            and a condition is specified.\n            ValueError: if more than one condition is provided.\n\n\n        Requires Redis 8.4 or greater.\n        For more information, see https://redis.io/commands/delex\n        \"\"\"\n        conds = [x is not None for x in (ifeq, ifne, ifdeq, ifdne)]\n        if sum(conds) > 1:\n            raise ValueError(\"Only one of IFEQ/IFNE/IFDEQ/IFDNE may be specified\")\n\n        pieces = [\"DELEX\", name]\n        if ifeq is not None:\n            pieces += [\"IFEQ\", ifeq]\n        elif ifne is not None:\n            pieces += [\"IFNE\", ifne]\n        elif ifdeq is not None:\n            pieces += [\"IFDEQ\", ifdeq]\n        elif ifdne is not None:\n            pieces += [\"IFDNE\", ifdne]\n\n        return self.execute_command(*pieces)\n\n    @overload\n    def dump(self: SyncClientProtocol, name: KeyT) -> bytes | None: ...\n\n    @overload\n    def dump(self: AsyncClientProtocol, name: KeyT) -> Awaitable[bytes | None]: ...","sourceCodeStart":2914,"sourceCodeEnd":2950,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L2914-L2950","documentation":"delex() (experimental, Redis 8.4+) accepts at most one conditional modifier among IFEQ, IFNE, IFDEQ, IFDNE. Passing two or more is contradictory (you cannot require both equal-and-not-equal) and is rejected at core.py:2931 with ValueError. Note this raises ValueError, not DataError.","triggerScenarios":"r.delex('key', ifeq='a', ifne='b'), or r.delex('key', ifdeq=digest, ifdne=other). Any pair of the four condition kwargs triggers sum(conds) > 1.","commonSituations":"Building a generic conditional-delete helper that forwards multiple optional filters; misunderstanding the semantics and assuming conditions are AND-combined.","solutions":["Pass exactly one condition keyword, e.g. r.delex('key', ifeq='expected').","If you need multi-condition logic, issue separate delex calls or implement client-side comparison after a GET.","Catch ValueError specifically (not DataError) when wrapping delex in error handling."],"exampleFix":"# before\nr.delex('key', ifeq='a', ifne='b')\n\n# after\nr.delex('key', ifeq='a')  # pick the single condition you actually need","handlingStrategy":"validation","validationCode":"conds = [ifeq, ifne, ifdeq, ifdne]\nif sum(c is not None for c in conds) > 1:\n    raise ValueError('delex: pass at most one of ifeq/ifne/ifdeq/ifdne')\nr.delex('key', ifeq=ifeq, ifne=ifne, ifdeq=ifdeq, ifdne=ifdne)","typeGuard":"def valid_delex_conditions(ifeq, ifne, ifdeq, ifdne) -> bool:\n    return sum(x is not None for x in (ifeq, ifne, ifdeq, ifdne)) <= 1","tryCatchPattern":"try:\n    r.delex('key', ifeq=ifeq, ifne=ifne, ifdeq=ifdeq, ifdne=ifdne)\nexcept ValueError as e:\n    if 'Only one of IFEQ' in str(e):\n        # pick the highest-priority condition and retry\n        r.delex('key', ifeq=ifeq)\n    else:\n        raise","preventionTips":["Remember delex raises ValueError, not DataError, so catch the right type.","Model the condition as a single (op, value) pair in your API rather than four kwargs."],"tags":["redis","delex","validation","parameter-conflict","experimental"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}