{"id":"5b706a8436470f00","repo":"redis/redis-py","slug":"async-redis-client-does-not-support-class-deletion","errorCode":null,"errorMessage":"Async Redis client does not support class deletion","messagePattern":"Async Redis client does not support class deletion","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":4809,"sourceCode":"        the given ``minmatchlen``.\n        If ``withmatchlen`` the length of the match also will be returned.\n        For more information, see https://redis.io/commands/lcs\n        \"\"\"\n        pieces: list[str | int] = [key1, key2]\n        if len:\n            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):","sourceCodeStart":4791,"sourceCodeEnd":4827,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L4791-L4827","documentation":"Raised by AsyncBasicKeyCommands.__delitem__ when you attempt del client[key] on an async Redis client. The sync client supports this as sugar for DELETE, but deletion is an async I/O operation in the async client and cannot be performed inside the synchronous __delitem__ dunder, so it is explicitly blocked.","triggerScenarios":"Writing `del async_client['mykey']` against an instance of redis.asyncio.Redis.","commonSituations":"Porting sync code that used the dict-style del syntax to the async client without rewriting the call; copy-pasting sync examples into async code.","solutions":["Replace del async_client[key] with await async_client.delete(key).","Use the explicit command API rather than dunder syntax in async code."],"exampleFix":"# before\ndel await r['mykey']  # or del r['mykey']\n# after\nawait r.delete('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":["Never use dict-style del on an async client; always call await client.delete(key).","When porting sync to async, grep for del r[ / r[ patterns and rewrite them.","Use the explicit command API consistently in async code."],"tags":["async","delete","typeerror","dunder"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}