{"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/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L4606-L4642","documentation":"Raised by stralgo() when both len=True and idx=True are passed. LEN returns only the numeric length of the longest common substring match, while IDX returns the match positions; the two output modes are incompatible and Redis rejects combining them. The library enforces this client-side.","triggerScenarios":"Calling client.stralgo('LCS', v1, v2, len=True, idx=True).","commonSituations":"Reusing a kwargs dict that toggles both flags; wanting both the length and indices in one call (not supported by the command).","solutions":["Choose either len=True (length only) or idx=True (positions), not both.","If you need both, make two stralgo()/lcs() calls and combine the results client-side."],"exampleFix":"# before\nawait r.stralgo('LCS', v1, v2, len=True, idx=True)\n# after\nawait r.stralgo('LCS', v1, v2, idx=True)","handlingStrategy":"validation","validationCode":"def validate_len_idx(length: bool, idx: bool) -> None:\n    if length and idx:\n        raise ValueError('len and idx cannot both be True for stralgo')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one output mode: len=True for length, idx=True for positions.","If both are needed, issue two calls and merge results.","Avoid reusing a shared kwargs dict that flips both flags."],"tags":["stralgo","lcs","validation","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}