redis/redis-py · error · DataError

The supported algorithms are: {supported_algos_str}

Error message

The supported algorithms are: {supported_algos_str}

What it means

Raised by stralgo() when the algo argument is not one of the supported values. Currently the only supported algorithm is 'LCS' (longest common substring). The check guards against typos or unsupported algorithm names before the command is sent to Redis.

Source

Thrown at redis/commands/core.py:4620

        ``algo`` Right now must be LCS
        ``value1`` and ``value2`` Can be two strings or two keys
        ``specific_argument`` Specifying if the arguments to the algorithm
        will be keys or strings. strings is the default.
        ``len`` Returns just the len of the match.
        ``idx`` Returns the match positions in each string.
        ``minmatchlen`` Restrict the list of matches to the ones of a given
        minimal length. Can be provided only when ``idx`` set to True.
        ``withmatchlen`` Returns the matches with the len of the match.
        Can be provided only when ``idx`` set to True.

        For more information, see https://redis.io/commands/stralgo
        """
        # check validity
        supported_algo = ["LCS"]
        if algo not in supported_algo:
            supported_algos_str = ", ".join(supported_algo)
            raise DataError(f"The supported algorithms are: {supported_algos_str}")
        if specific_argument not in ["keys", "strings"]:
            raise DataError("specific_argument can be only keys or strings")
        if len and idx:
            raise DataError("len and idx cannot be provided together.")

        pieces: list[EncodableT] = [algo, specific_argument.upper(), value1, value2]
        if len:
            pieces.append(b"LEN")
        if idx:
            pieces.append(b"IDX")
        try:
            int(minmatchlen)
            pieces.extend([b"MINMATCHLEN", minmatchlen])
        except TypeError:
            pass
        if withmatchlen:
            pieces.append(b"WITHMATCHLEN")

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Pass algo='LCS' (uppercase, exact match).
  2. Prefer the dedicated lcs() method which does not require the algo argument.
  3. Validate user-supplied algorithm strings against {'LCS'} before calling stralgo().

Example fix

# before
await r.stralgo('lcs', 'ohmytext', 'mynewtext', specific_argument='strings')
# after
await r.stralgo('LCS', 'ohmytext', 'mynewtext', specific_argument='strings')
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED_ALGOS = {'LCS'}
def validate_stralgo_algo(algo: str) -> str:
    if algo not in SUPPORTED_ALGOS:
        raise ValueError(f'algo must be one of {SUPPORTED_ALGOS}, got {algo!r}')
    return algo

Type guard

def is_supported_algo(algo: str) -> bool:
    return algo in {'LCS'}

Prevention

When it happens

Trigger: Calling client.stralgo('lcs', ...) with wrong casing, or client.stralgo('EDIT', ...) / any string other than exactly 'LCS'.

Common situations: Case mismatch ('lcs' vs 'LCS'); copy-paste from docs referencing a future algorithm name; dynamic algo selection from user input without validation.

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/ff77e39cbfb18a19.json. Report an issue: GitHub.