redis/redis-py · error · TypeError
Async Redis client does not support class assignment
Error message
Async Redis client does not support class assignment
What it means
Raised by AsyncBasicKeyCommands.__setitem__ when you assign async_client[key] = value. The sync client maps this to SET, but the async SET must be awaited and cannot run inside the synchronous __setitem__ dunder, so assignment via subscript is disabled.
Source
Thrown at redis/commands/core.py:4818
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
"""
@overload
def blpop(
self: SyncClientProtocol, keys: KeysT, timeout: Number | None = 0
) -> BlockingListPopResponse: ...View on GitHub (pinned to da03cdc7e8)
Solutions
- Replace async_client[key] = value with await async_client.set(key, value).
- Use the explicit set command for all async writes.
Example fix
# before
r['mykey'] = 'v'
# after
await r.set('mykey', 'v') Defensive patterns
Strategy: type-guard
Type guard
import redis.asyncio as aioredis
def is_async_client(client) -> bool:
return isinstance(client, aioredis.Redis) Prevention
- Replace r[key] = value with await r.set(key, value) in async code.
- Grep for r[' = assignment patterns when porting to async.
- Use the explicit set() command for writes.
When it happens
Trigger: Writing `async_client['mykey'] = 'v'` against an instance of redis.asyncio.Redis.
Common situations: Porting sync dict-style writes to async; copy-pasting sync examples that use r[key] = value.
Related errors
- Async Redis client does not support class deletion
- Async Redis client does not support class inclusion
- Async Redis client does not support class retrieval
- Connection closed by server.
- Buffer is closed.
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/a41bfede1e4e4ae7.json.
Report an issue: GitHub.