redis/redis-py · error · DataError
No key specified
Error message
No key specified
What it means
Raised by JSON.DEBUG (redis/commands/json/commands.py:830) as a DataError when subcommand is 'MEMORY' but no key argument is supplied. The MEMORY subcommand requires a key (and optional path) to measure, so the library rejects the call before sending JSON.DEBUG MEMORY with no target.
Solutions
- Pass a non-None key: client.json().debug('MEMORY', 'mykey').
- Optionally also pass a path: client.json().debug('MEMORY', 'mykey', '$.field').
- For HELP no key is needed.
Example fix
# before
client.json().debug('MEMORY')
# after
client.json().debug('MEMORY', 'mykey') Defensive patterns
Strategy: validation
Validate before calling
def safe_json_debug_memory(key):
if not key:
raise ValueError('JSON.DEBUG MEMORY requires a key')
return key Type guard
def has_debug_key(key) -> bool:
return isinstance(key, str) and bool(key) Try / catch
from redis.exceptions import DataError
try:
client.json().debug('MEMORY', key)
except DataError as e:
if 'No key' in str(e):
raise # caller must supply a key
raise Prevention
- Always pass a non-empty key with the MEMORY subcommand.
- Do not reuse the debug('HELP') call signature for MEMORY.
- Validate keys at the boundary before reaching the client.
When it happens
Trigger: Calling client.json().debug('MEMORY') or client.json().debug('MEMORY', None). The key parameter defaults to None and is only checked when subcommand == 'MEMORY'.
Common situations: Forgetting the key, reusing a debug('HELP') call signature for MEMORY, or a variable that resolved to None.
Related errors
- The only valid subcommands are
- Invalid FPHA type: . Must be one of
- nx and xx are mutually exclusive: use one, the other or…
- XRANGE count must be a positive integer
- XREAD block must be a non-negative integer
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/16e1800381cebfe2.
Report an issue: GitHub.
Appendix: 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 6a6b581b48)