Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Redis resolves to non-async function calls. #3386

Open
Krupskis opened this issue Sep 26, 2024 · 1 comment
Open

Async Redis resolves to non-async function calls. #3386

Krupskis opened this issue Sep 26, 2024 · 1 comment

Comments

@Krupskis
Copy link

Krupskis commented Sep 26, 2024

Version: What redis-py and what redis version is the issue happening on? ^5.0.8

Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure) macOS, python 3.12.4

Description: Description of your issue, stack traces from errors and code that reproduces the issue

from redis import asyncio as aioredis
redis_client = aioredis.from_url(redis_server, port=6379, db=0)

async def set_cached_audio(user_id: str, audio: np.array) -> None:
    redis_client = config.redis_client
    await redis_client.set(user_id, audio.tobytes())

The set method seems to resolve to under redis/commands/core.py

    def set(
        self,
        name: KeyT,
        value: EncodableT,
        ex: Union[ExpiryT, None] = None,
        px: Union[ExpiryT, None] = None,
        nx: bool = False,
        xx: bool = False,
        keepttl: bool = False,
        get: bool = False,
        exat: Union[AbsExpiryT, None] = None,
        pxat: Union[AbsExpiryT, None] = None,
    ) -> ResponseT:

Correct me if I am wrong, but this doesn't seem to be an async set function. Is this expected behavior of async redis?

This is my project.toml

redis = {extras = ["hiredis"], version = "^5.0.8"}
@vardanaloyan
Copy link

I guess what you're expecting to see is something like async def set, but this is not how it's implemented.

  1. If you look to the set method implementation (and not only) it returns self.execute_command("SET", *pieces, **options).
  2. Inside redis.asyncio.Redis, you can see that it overrides execute_command method with async one.
  3. So when we do client.set we receive async coroutine and combining with await we execute the coroutine. In the sync Redis when we execute set (client.set) we immediately send the command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants