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 parameter tells Redis whether value1/value2 should be treated as key names to look up or as literal string values; any other value is meaningless to the command. It is a DataError.
Solutions
- Set specific_argument='strings' to compare literal string values, or specific_argument='keys' to compare values stored at those keys.
- Double-check spelling: it must be exactly 'keys' or 'strings' (plural).
Example fix
# before
client.stralgo('LCS', 'k1', 'k2', specific_argument='key')
# after
client.stralgo('LCS', 'k1', 'k2', specific_argument='keys') Defensive patterns
Strategy: validation
Validate before calling
if specific_argument not in ('keys', 'strings'):
raise ValueError("specific_argument must be 'keys' or 'strings'")
client.stralgo('LCS', v1, v2, specific_argument=specific_argument) Type guard
from typing import Literal
def is_valid_specific_arg(s: str) -> bool:
return s in ('keys', 'strings')
# usage
specific_argument: Literal['keys', 'strings'] = 'strings' Try / catch
from redis.exceptions import DataError
try:
client.stralgo('LCS', v1, v2, specific_argument=specific_argument)
except DataError as e:
if 'specific_argument' in str(e):
specific_argument = 'strings'
client.stralgo('LCS', v1, v2, specific_argument=specific_argument) Prevention
- Use a Literal['keys','strings'] type annotation on the variable holding specific_argument.
- Validate user/config input against the two allowed values before forwarding.
When it happens
Trigger: Calling client.stralgo('LCS', v1, v2, specific_argument='values'), specific_argument='key', or omitting the default and passing an arbitrary string.
Common situations: Typing 'value' instead of 'strings', or 'key' instead of 'keys'. Confusing whether to pass key names or raw strings.
Related errors
- The supported algorithms are
- len and idx cannot be provided together.
- ACL LOG count must be an integer
- bit must be 0 or 1
- Both start and end must be specified
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/c174994ed53db774.
Report an issue: GitHub.
Appendix: 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 6a6b581b48)