{"id":"6ab27e155a2a4ab3","repo":"redis/redis-py","slug":"async-redis-client-does-not-support-class-inclusio","errorCode":null,"errorMessage":"Async Redis client does not support class inclusion","messagePattern":"Async Redis client does not support class inclusion","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":4812,"sourceCode":"        \"\"\"\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):\n    \"\"\"\n    Redis commands for List data type.\n    see: https://redis.io/topics/data-types#lists","sourceCodeStart":4794,"sourceCodeEnd":4830,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L4794-L4830","documentation":"Raised by AsyncBasicKeyCommands.__contains__ when you write key in async_client. The sync client maps this to EXISTS, but membership testing in the async client requires an awaited call, which the synchronous in operator cannot perform, so it is blocked.","triggerScenarios":"Writing `if 'mykey' in async_client:` against an instance of redis.asyncio.Redis.","commonSituations":"Porting sync code that used `if key in r:` to async; using dict-style containment checks in async code.","solutions":["Replace 'key in async_client' with `(await async_client.exists(key)) > 0`.","Use await async_client.exists(key) directly for the boolean check."],"exampleFix":"# before\nif 'mykey' in r:\n    ...\n# after\nif await r.exists('mykey'):\n    ...","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 'key in r' with (await r.exists(key)) > 0 in async code.","Grep for 'in r' / 'in client' patterns when porting to async.","Use the explicit exists() command for membership checks."],"tags":["async","exists","typeerror","dunder"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}