redis/redis-py · error · TypeError

Async Redis client does not support class retrieval

Error message

Async Redis client does not support class retrieval

What it means

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.

Source

Thrown at redis/commands/core.py:4815

            pieces.append("LEN")
        if idx:
            pieces.append("IDX")
        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

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Replace async_client[key] with await async_client.get(key).
  2. Use the explicit get command for all async reads.

Example fix

# before
val = r['mykey']
# after
val = await r.get('mykey')
Defensive patterns

Strategy: type-guard

Type guard

import redis.asyncio as aioredis
def is_async_client(client) -> bool:
    return isinstance(client, aioredis.Redis)

Prevention

When it happens

Trigger: Writing `val = async_client['mykey']` against an instance of redis.asyncio.Redis.

Common situations: Porting sync dict-style reads to async; copy-pasting sync examples that use r[key].

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/57e42b9255047bc2.json. Report an issue: GitHub.