Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Conversation

@e-kondr01
Copy link

@e-kondr01 e-kondr01 commented May 5, 2023

Rationale

Broadcaster uses asyncio-redis in its RedisBackend. asyncio-redis is not actively maintained at the moment.

RedisPy (https://github.com/redis/redis-py) is the maintained Redis client for Python, and it has had AsyncIO support for quite some time.

Pull Request Content

This PR provides an updated Redis backend using RedisPy.

Problems faced

RedisPy doesn't allow listening for PubSub messages if the connection is not subscribed to any channels:

https://github.com/redis/redis-py/blob/master/redis/asyncio/client.py#L807

To solve this, the code of the Broadcaster class has been changed to start the listener task only after the first subscription to a channel.

Another solution would be to subscribe to an arbitrary channel in the connect method of Redis backend. I am not sure that I like this workaround.

However, I have not tested that these changes to the Broadcaster class do not break other backends.

@MahmudulHassan5809
Copy link

hello

async def next_published(self) -> Event:
        message = None
        # get_message with timeout=None can return None
        while not message:
            #
            message = await self._sub_conn.get_message(
                timeout=None, ignore_subscribe_messages=True
            )
        return Event(
            channel=message["channel"].decode(),
            message=message["data"].decode(),
        )

here you need to use ignore_subscribe_messages = True

@MichalPham
Copy link

Is this gonna move forward?

@e-kondr01
Copy link
Author

@MichalPham unfortunately I don't have the time right now to contribute to open source. This MR is a demonstration of how I've implemented RedisPy backend to Broadcaster in my work project, so interested people could use it as a reference or a starting point.

@alex-oleshkevich
Copy link
Contributor

@encode/maintainers I fully support transition to redis-py. I will take a look at this PR soon.

@Kludex
Copy link
Contributor

Kludex commented Nov 15, 2023

@encode/maintainers I fully support transition to redis-py. I will take a look at this PR soon.

Whatever you think is fine by me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants