Add redis backed with RedisPy
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.
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
Is this gonna move forward?
@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.
@encode/maintainers I fully support transition to redis-py. I will take a look at this PR soon.
@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.