{"id":"57e42b9255047bc2","repo":"redis/redis-py","slug":"async-redis-client-does-not-support-class-retrieva","errorCode":null,"errorMessage":"Async Redis client does not support class retrieval","messagePattern":"Async Redis client does not support class retrieval","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":4815,"sourceCode":"            pieces.append(\"LEN\")\n        if idx:\n            pieces.append(\"IDX\")\n        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","sourceCodeStart":4797,"sourceCodeEnd":4833,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L4797-L4833","documentation":"Raised by AsyncBasicKeyCommands.__getitem__ when you index an async client like async_client[key]. The sync client maps this to GET, but the async GET must be awaited and cannot run inside the synchronous __getitem__ dunder, so retrieval via subscript is disabled.","triggerScenarios":"Writing `val = async_client['mykey']` against an instance of redis.asyncio.Redis.","commonSituations":"Porting sync dict-style reads to async; copy-pasting sync examples that use r[key].","solutions":["Replace async_client[key] with await async_client.get(key).","Use the explicit get command for all async reads."],"exampleFix":"# before\nval = r['mykey']\n# after\nval = await r.get('mykey')","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] reads with await r.get(key) in async code.","Grep for r[' patterns when porting to async.","Use the explicit get() command for reads."],"tags":["async","get","typeerror","dunder"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}