redis/redis-py · error · DataError

specific_argument can be only keys or strings

Error message

specific_argument can be only keys or strings

What it means

Raised by stralgo() when specific_argument is neither 'keys' nor 'strings'. This argument tells Redis whether value1/value2 are key names to look up or literal string values, so only those two spellings are valid.

Source

Thrown at redis/commands/core.py:4622

        ``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")

        return self.execute_command(
            "STRALGO",

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Pass specific_argument='strings' (default) when value1/value2 are literal strings.
  2. Pass specific_argument='keys' when value1/value2 are Redis key names.
  3. Use the lcs() helper which encodes the correct argument automatically.

Example fix

# before
await r.stralgo('LCS', k1, k2, specific_argument='key')
# after
await r.stralgo('LCS', k1, k2, specific_argument='keys')
Defensive patterns

Strategy: validation

Validate before calling

VALID_SPECIFIC = {'keys', 'strings'}
def validate_specific_argument(specific_argument: str) -> str:
    if specific_argument not in VALID_SPECIFIC:
        raise ValueError(f'specific_argument must be one of {VALID_SPECIFIC}')
    return specific_argument

Type guard

def is_valid_specific_argument(s: str) -> bool:
    return s in {'keys', 'strings'}

Prevention

When it happens

Trigger: Calling client.stralgo('LCS', k1, k2, specific_argument='KEY') (wrong case), specific_argument='key' (singular), or any value other than exactly 'keys' or 'strings'.

Common situations: Case mismatch; passing the singular form; passing None or an empty string; deriving the value from unvalidated config input.

Related errors


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