redis/redis-py · error · TypeError
Async Redis client does not support class deletion
Error message
Async Redis client does not support class deletion
What it means
Raised by AsyncBasicKeyCommands.__delitem__ when you attempt del client[key] on an async Redis client. The sync client supports this as sugar for DELETE, but deletion is an async I/O operation in the async client and cannot be performed inside the synchronous __delitem__ dunder, so it is explicitly blocked.
Source
Thrown at redis/commands/core.py:4809
the given ``minmatchlen``.
If ``withmatchlen`` the length of the match also will be returned.
For more information, see https://redis.io/commands/lcs
"""
pieces: list[str | int] = [key1, key2]
if len:
pieces.append("LEN")
if idx:
pieces.append("IDX")
if minmatchlen is not None and minmatchlen != 0:
pieces.extend(["MINMATCHLEN", minmatchlen])
if withmatchlen:
pieces.append("WITHMATCHLEN")
return self.execute_command("LCS", *pieces, keys=[key1, key2])
class AsyncBasicKeyCommands(BasicKeyCommands):
def __delitem__(self, name: KeyT):
raise TypeError("Async Redis client does not support class deletion")
def __contains__(self, name: KeyT):
raise TypeError("Async Redis client does not support class inclusion")
def __getitem__(self, name: KeyT):
raise TypeError("Async Redis client does not support class retrieval")
def __setitem__(self, name: KeyT, value: EncodableT):
raise TypeError("Async Redis client does not support class assignment")
async def watch(self, *names: KeyT) -> None:
return super().watch(*names)
async def unwatch(self) -> None:
return super().unwatch()
class ListCommands(CommandsProtocol):View on GitHub (pinned to da03cdc7e8)
Solutions
- Replace del async_client[key] with await async_client.delete(key).
- Use the explicit command API rather than dunder syntax in async code.
Example fix
# before
del await r['mykey'] # or del r['mykey']
# after
await r.delete('mykey') Defensive patterns
Strategy: type-guard
Type guard
import redis.asyncio as aioredis
def is_async_client(client) -> bool:
return isinstance(client, aioredis.Redis) Prevention
- Never use dict-style del on an async client; always call await client.delete(key).
- When porting sync to async, grep for del r[ / r[ patterns and rewrite them.
- Use the explicit command API consistently in async code.
When it happens
Trigger: Writing `del async_client['mykey']` against an instance of redis.asyncio.Redis.
Common situations: Porting sync code that used the dict-style del syntax to the async client without rewriting the call; copy-pasting sync examples into async code.
Related errors
- Async Redis client does not support class inclusion
- Async Redis client does not support class retrieval
- Async Redis client does not support class assignment
- Connection closed by server.
- Buffer is closed.
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/5b706a8436470f00.json.
Report an issue: GitHub.