From b6e59a54ec63e4ed241f3d850476692c6090c158 Mon Sep 17 00:00:00 2001 From: k1dave6412 Date: Mon, 25 May 2020 16:41:20 +0800 Subject: [PATCH 1/4] feat(redis_backend): add password auth as title, make redis with password work --- broadcaster/_backends/redis.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/broadcaster/_backends/redis.py b/broadcaster/_backends/redis.py index 096a033..0797b9c 100644 --- a/broadcaster/_backends/redis.py +++ b/broadcaster/_backends/redis.py @@ -10,10 +10,11 @@ def __init__(self, url: str): parsed_url = urlparse(url) self._host = parsed_url.hostname or "localhost" self._port = parsed_url.port or 6379 + self._password = parsed_url.password or None async def connect(self) -> None: - self._pub_conn = await asyncio_redis.Connection.create(self._host, self._port) - self._sub_conn = await asyncio_redis.Connection.create(self._host, self._port) + self._pub_conn = await asyncio_redis.Connection.create(self._host, self._port, self._password) + self._sub_conn = await asyncio_redis.Connection.create(self._host, self._port, self._password) self._subscriber = await self._sub_conn.start_subscribe() async def disconnect(self) -> None: From e54b5294857e28916456f91fee513407ac2e9bfa Mon Sep 17 00:00:00 2001 From: k1dave6412 Date: Mon, 25 May 2020 16:48:52 +0800 Subject: [PATCH 2/4] fix(redis_backend): add args name --- broadcaster/_backends/redis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/broadcaster/_backends/redis.py b/broadcaster/_backends/redis.py index 0797b9c..cb91897 100644 --- a/broadcaster/_backends/redis.py +++ b/broadcaster/_backends/redis.py @@ -13,8 +13,8 @@ def __init__(self, url: str): self._password = parsed_url.password or None async def connect(self) -> None: - self._pub_conn = await asyncio_redis.Connection.create(self._host, self._port, self._password) - self._sub_conn = await asyncio_redis.Connection.create(self._host, self._port, self._password) + self._pub_conn = await asyncio_redis.Connection.create(self._host, self._port, password=self._password) + self._sub_conn = await asyncio_redis.Connection.create(self._host, self._port, password=self._password) self._subscriber = await self._sub_conn.start_subscribe() async def disconnect(self) -> None: From 082b4292701b991d5873d349baf5bde75af2002e Mon Sep 17 00:00:00 2001 From: k1dave6412 Date: Tue, 26 May 2020 18:20:46 +0800 Subject: [PATCH 3/4] test(test_broadcast.py): redis with password test --- tests/test_broadcast.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_broadcast.py b/tests/test_broadcast.py index 7e0c8c0..2d797de 100644 --- a/tests/test_broadcast.py +++ b/tests/test_broadcast.py @@ -23,6 +23,16 @@ async def test_redis(): assert event.message == 'hello' +@pytest.mark.asyncio +async def test_redis_with_password(): + async with Broadcast('redis://:password@localhost:6379') as broadcast: + async with broadcast.subscribe('chatroom') as subscriber: + await broadcast.publish('chatroom', 'hello') + event = await subscriber.get() + assert event.channel == 'chatroom' + assert event.message == 'hello' + + @pytest.mark.asyncio async def test_postgres(): async with Broadcast('postgres://postgres:postgres@localhost:5432/broadcaster') as broadcast: From 719625c9fd6d15b0602f4830051ab4769ebd31c8 Mon Sep 17 00:00:00 2001 From: k1dave6412 Date: Tue, 26 May 2020 19:31:54 +0800 Subject: [PATCH 4/4] test(broadcast.py): remove unnecessary test --- tests/test_broadcast.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/test_broadcast.py b/tests/test_broadcast.py index 2d797de..7e0c8c0 100644 --- a/tests/test_broadcast.py +++ b/tests/test_broadcast.py @@ -23,16 +23,6 @@ async def test_redis(): assert event.message == 'hello' -@pytest.mark.asyncio -async def test_redis_with_password(): - async with Broadcast('redis://:password@localhost:6379') as broadcast: - async with broadcast.subscribe('chatroom') as subscriber: - await broadcast.publish('chatroom', 'hello') - event = await subscriber.get() - assert event.channel == 'chatroom' - assert event.message == 'hello' - - @pytest.mark.asyncio async def test_postgres(): async with Broadcast('postgres://postgres:postgres@localhost:5432/broadcaster') as broadcast: