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__ (a TypeError) when you use 'del async_client[key]' on an async Redis client. The sync client maps del client[key] to DELETE, but the async client cannot because Python dunder methods cannot be async (awaitable), so the override raises immediately to prevent silent misuse.
Solutions
- Replace 'del client[key]' with 'await client.delete(key)'.
- If deleting multiple keys, use 'await client.delete(*keys)'.
Example fix
# before
del client['mykey']
# after
await client.delete('mykey') Defensive patterns
Strategy: validation
Validate before calling
# Never use del on an async client; call delete explicitly. await client.delete(key) # instead of del client[key]
Type guard
import redis
def is_async_client(c) -> bool:
return isinstance(c, (redis.asyncio.Redis, redis.asyncio.RedisCluster))
# usage: if is_async_client(client): await client.delete(key) else: del client[key] Try / catch
try:
del client[key]
except TypeError as e:
if 'class deletion' in str(e):
await client.delete(key)
else:
raise Prevention
- When migrating to redis.asyncio, grep for 'del client[' and replace with await client.delete().
- Treat the async client as await-only; never use dict/item protocol on it.
- Run a quick grep for dunder usage (__delitem__/__setitem__/__getitem__/__contains__) on async clients.
When it happens
Trigger: Writing 'del redis_async[key]' or 'del redis_async['mykey']' where redis_async is a redis.asyncio.Redis instance. Code ported verbatim from the sync client that used item deletion.
Common situations: Migrating from redis.Redis to redis.asyncio.Redis and leaving dict-style deletion syntax in place. Code that generically calls __delitem__ on any mapping-like object.
Related errors
- Async Redis client does not support class assignment
- Async Redis client does not support class inclusion
- Async Redis client does not support class retrieval
- Bad response from PING health check
- Buffer is closed.
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/5b706a8436470f00.
Report an issue: GitHub.
Appendix: 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 6a6b581b48)