Skip to content

redis: "RedisCluster[Any]" has no attribute "zadd"|"zrem"| any other command #9810

@juanamari94

Description

@juanamari94

The latest releases of the async version of RedisCluster for the redis library (i.e: redis.asyncio.cluster) are failing on mypy due to undefined attributes (which do exist in reality):

Steps to reproduce:

  • Install mypy
  • Install types-redis
  • Paste the following code into a file (e.g: main.py):
import asyncio
import string
import random
from redis.asyncio.cluster import RedisCluster


async def future(rc: RedisCluster):
    key = ''.join([random.choice(string.ascii_uppercase) for _ in range(6)])
    field = ''.join([random.choice(string.ascii_uppercase) for _ in range(4)])
    value = random.randint(0, 10)
    await rc.zadd(key, {field: value}, ch=True)
    await rc.zrem(key, field)
    print("Ran for %s -> %s: %s" % (key, field, value))


async def main():
    async with RedisCluster("localhost", 6379) as rc:
        futures = [future(rc) for _ in range(100000)]
        await asyncio.gather(*futures)

asyncio.run(main())
  • Evaluate the code with mypy: mypy main.py
  • Output will be:
$ mypy redis_test.py                                                                                                                                                                                                
redis_test.py:11: error: "RedisCluster[Any]" has no attribute "zadd"  [attr-defined]
redis_test.py:12: error: "RedisCluster[Any]" has no attribute "zrem"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: redisIssues related to the redis third-party stubs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions