redis/redis-py · error · TypeError
Async Redis client does not support class retrieval
Error message
Async Redis client does not support class retrieval
What it means
Raised by AsyncBasicKeyCommands.__getitem__ (a TypeError) when you use 'async_client[key]' to read a value. The sync client maps client[key] to GET (raising KeyError on missing), but the async dunder cannot be awaited, so it is disabled to prevent receiving a coroutine instead of the value.
Solutions
- Replace "client[key]" with "await client.get(key)".
- If you relied on KeyError for missing keys, check for None or use a helper that raises KeyError when get returns None.
Example fix
# before
value = client['mykey']
# after
value = await client.get('mykey') Defensive patterns
Strategy: validation
Validate before calling
# Never use client[key] on an async client; call get explicitly. value = await client.get(key) # instead of client[key]
Type guard
import redis
def is_async_client(c) -> bool:
return isinstance(c, (redis.asyncio.Redis, redis.asyncio.RedisCluster)) Try / catch
try:
value = client[key]
except TypeError as e:
if 'class retrieval' in str(e):
value = await client.get(key)
else:
raise Prevention
- Replace client[key] with await client.get(key) in all async code paths.
- If you relied on KeyError for missing keys, check value is None and raise KeyError yourself.
When it happens
Trigger: Writing "value = client['mykey']" where client is a redis.asyncio.Redis instance.
Common situations: Direct port of sync code that used dict-style key access. Generic code that treats the client as a mapping.
Related errors
- Async Redis client does not support class assignment
- Async Redis client does not support class deletion
- Async Redis client does not support class inclusion
- 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/57e42b9255047bc2.
Report an issue: GitHub.
Appendix: source
Thrown at redis/commands/core.py:4815
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):
"""
Redis commands for List data type.
see: https://redis.io/topics/data-types#lists
"""
@overloadView on GitHub (pinned to 6a6b581b48)