{"record":{"id":"45784d1172d5ac59","repo":"redis/redis-py","slug":"len-and-idx-cannot-be-provided-together","errorCode":null,"errorMessage":"len and idx cannot be provided together.","messagePattern":"len and idx cannot be provided together\\.","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":4624,"sourceCode":"        will be keys or strings. strings is the default.\n        ``len`` Returns just the len of the match.\n        ``idx`` Returns the match positions in each string.\n        ``minmatchlen`` Restrict the list of matches to the ones of a given\n        minimal length. Can be provided only when ``idx`` set to True.\n        ``withmatchlen`` Returns the matches with the len of the match.\n        Can be provided only when ``idx`` set to True.\n\n        For more information, see https://redis.io/commands/stralgo\n        \"\"\"\n        # check validity\n        supported_algo = [\"LCS\"]\n        if algo not in supported_algo:\n            supported_algos_str = \", \".join(supported_algo)\n            raise DataError(f\"The supported algorithms are: {supported_algos_str}\")\n        if specific_argument not in [\"keys\", \"strings\"]:\n            raise DataError(\"specific_argument can be only keys or strings\")\n        if len and idx:\n            raise DataError(\"len and idx cannot be provided together.\")\n\n        pieces: list[EncodableT] = [algo, specific_argument.upper(), value1, value2]\n        if len:\n            pieces.append(b\"LEN\")\n        if idx:\n            pieces.append(b\"IDX\")\n        try:\n            int(minmatchlen)\n            pieces.extend([b\"MINMATCHLEN\", minmatchlen])\n        except TypeError:\n            pass\n        if withmatchlen:\n            pieces.append(b\"WITHMATCHLEN\")\n\n        return self.execute_command(\n            \"STRALGO\",\n            *pieces,\n            len=len,","sourceCodeStart":4606,"sourceCodeEnd":4642,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/core.py#L4606-L4642","documentation":"Raised by stralgo() when both len and idx are True simultaneously. LEN returns only the length of the match while IDX returns match positions; requesting both in STRALGO is ambiguous/unsupported, so the client rejects it before sending. It is a DataError.","triggerScenarios":"Calling client.stralgo('LCS', v1, v2, len=True, idx=True).","commonSituations":"Wanting both the match length and positions in one call, or copying idx=True from one call and len=True from another into the same invocation.","solutions":["Use idx=True alone; the IDX output already includes match length information when withmatchlen=True is also set.","If you only need the numeric length, use len=True alone."],"exampleFix":"# before\nclient.stralgo('LCS', v1, v2, len=True, idx=True)\n\n# after\nclient.stralgo('LCS', v1, v2, idx=True, withmatchlen=True)","handlingStrategy":"validation","validationCode":"if len and idx:\n    raise ValueError('Use idx=True with withmatchlen=True; do not pass len=True together with idx')\nclient.stralgo('LCS', v1, v2, len=len, idx=idx, withmatchlen=idx)","typeGuard":null,"tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.stralgo('LCS', v1, v2, len=True, idx=True)\nexcept DataError as e:\n    if 'len and idx' in str(e):\n        client.stralgo('LCS', v1, v2, idx=True, withmatchlen=True)","preventionTips":["If you need lengths alongside positions, use idx=True plus withmatchlen=True.","Treat len and idx as mutually exclusive in your own option builder."],"tags":["stralgo","lcs","mutual-exclusivity","validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}