{"id":"a41bfede1e4e4ae7","repo":"redis/redis-py","slug":"async-redis-client-does-not-support-class-assignme","errorCode":null,"errorMessage":"Async Redis client does not support class assignment","messagePattern":"Async Redis client does not support class assignment","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":4818,"sourceCode":"        if minmatchlen is not None and minmatchlen != 0:\n            pieces.extend([\"MINMATCHLEN\", minmatchlen])\n        if withmatchlen:\n            pieces.append(\"WITHMATCHLEN\")\n        return self.execute_command(\"LCS\", *pieces, keys=[key1, key2])\n\n\nclass AsyncBasicKeyCommands(BasicKeyCommands):\n    def __delitem__(self, name: KeyT):\n        raise TypeError(\"Async Redis client does not support class deletion\")\n\n    def __contains__(self, name: KeyT):\n        raise TypeError(\"Async Redis client does not support class inclusion\")\n\n    def __getitem__(self, name: KeyT):\n        raise TypeError(\"Async Redis client does not support class retrieval\")\n\n    def __setitem__(self, name: KeyT, value: EncodableT):\n        raise TypeError(\"Async Redis client does not support class assignment\")\n\n    async def watch(self, *names: KeyT) -> None:\n        return super().watch(*names)\n\n    async def unwatch(self) -> None:\n        return super().unwatch()\n\n\nclass ListCommands(CommandsProtocol):\n    \"\"\"\n    Redis commands for List data type.\n    see: https://redis.io/topics/data-types#lists\n    \"\"\"\n\n    @overload\n    def blpop(\n        self: SyncClientProtocol, keys: KeysT, timeout: Number | None = 0\n    ) -> BlockingListPopResponse: ...","sourceCodeStart":4800,"sourceCodeEnd":4836,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L4800-L4836","documentation":"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.","triggerScenarios":"Writing `async_client['mykey'] = 'v'` against an instance of redis.asyncio.Redis.","commonSituations":"Porting sync dict-style writes to async; copy-pasting sync examples that use r[key] = value.","solutions":["Replace async_client[key] = value with await async_client.set(key, value).","Use the explicit set command for all async writes."],"exampleFix":"# before\nr['mykey'] = 'v'\n# after\nawait r.set('mykey', 'v')","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"import redis.asyncio as aioredis\ndef is_async_client(client) -> bool:\n    return isinstance(client, aioredis.Redis)","tryCatchPattern":null,"preventionTips":["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."],"tags":["async","set","typeerror","dunder"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}