redis/redis-py · error · DataError
No key specified
Error message
No key specified
What it means
Raised by JSON.debug() when subcommand is 'MEMORY' but no key argument was supplied. The MEMORY subcommand reports bytes used by a value at a specific key, so the key is mandatory; HELP is the only subcommand that works without one.
Source
Thrown at redis/commands/json/commands.py:830
def debug(
self,
subcommand: str,
key: str | None = None,
path: str | None = Path.root_path(),
) -> (int | list[str]) | Awaitable[int | list[str]]:
"""Return the memory usage in bytes of a value under ``path`` from
key ``name``.
For more information see `JSON.DEBUG <https://redis.io/commands/json.debug>`_.
""" # noqa
valid_subcommands = ["MEMORY", "HELP"]
if subcommand not in valid_subcommands:
raise DataError("The only valid subcommands are ", str(valid_subcommands))
pieces = [subcommand]
if subcommand == "MEMORY":
if key is None:
raise DataError("No key specified")
pieces.append(key)
pieces.append(str(path))
return self.execute_command("JSON.DEBUG", *pieces)
@overload
def jsonget(self: SyncClientProtocol, *args, **kwargs) -> JsonType | None: ...
@overload
def jsonget(
self: AsyncClientProtocol, *args, **kwargs
) -> Awaitable[JsonType | None]: ...
@deprecated_function(
version="4.0.0", reason="redisjson-py supported this, call get directly."
)
def jsonget(self, *args, **kwargs) -> (JsonType | None) | Awaitable[
JsonType | None
]:View on GitHub (pinned to da03cdc7e8)
Solutions
- Always pass a key with the MEMORY subcommand: debug('MEMORY', 'mykey').
- Guard before calling: if key is None: skip or raise your own error.
- Use debug('HELP') if you only want usage text.
Example fix
// before
client.json().debug('MEMORY')
// after
client.json().debug('MEMORY', 'mykey') Defensive patterns
Strategy: validation
Validate before calling
def json_debug_memory(client, key, path="$"):
if key is None:
raise ValueError("MEMORY subcommand requires a key")
return client.json().debug("MEMORY", key, path) Type guard
def has_key(v) -> bool:
return v is not None and (not isinstance(v, str) or v != "") Try / catch
from redis.exceptions import DataError
try:
client.json().debug("MEMORY", key)
except DataError as e:
if "No key specified" in str(e):
raise ValueError("caller must supply a non-None key") from e
raise Prevention
- Require key positionally in your wrapper so it can't be silently None.
- Distinguish 'HELP' (no key) from 'MEMORY' (key required) at the API boundary.
- Validate request payloads that drive JSON.DEBUG before invoking the client.
When it happens
Trigger: Call client.json().debug('MEMORY') with key left as the default None, or client.json().debug('MEMORY', None).
Common situations: Forgetting the positional key; passing key from a variable that is None on missing input; refactoring that drops the key argument.
Related errors
- The only valid subcommands are
- Invalid FPHA type: {value}. Must be one of {', '.join(t.valu
- CLIENT KILL type must be one of {client_types!r}
- CLIENT KILL skipme must be a bool
- CLIENT KILL <filter> <value> ... ... <filter> <value> must s
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/16e1800381cebfe2.json.
Report an issue: GitHub.