From 9180e34e4f3ae2e74091c7dbb719bc1abb36c6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A4=91=EA=B7=BC?= Date: Thu, 26 May 2022 19:32:32 +0900 Subject: [PATCH 1/4] set default response_callbacks to redis.asyncio.cluster.ClusterNode --- redis/asyncio/cluster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/asyncio/cluster.py b/redis/asyncio/cluster.py index 10a5675e82..fa918721dc 100644 --- a/redis/asyncio/cluster.py +++ b/redis/asyncio/cluster.py @@ -725,7 +725,7 @@ def __init__( server_type: Optional[str] = None, max_connections: int = 2 ** 31, connection_class: Type[Connection] = Connection, - response_callbacks: Dict = None, + response_callbacks: Dict = RedisCluster.RESPONSE_CALLBACKS, **connection_kwargs, ) -> None: if host == "localhost": From 653c729ce400da642d91fdb869b4f2ef9eb5af0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A4=91=EA=B7=BC?= Date: Fri, 27 May 2022 16:57:54 +0900 Subject: [PATCH 2/4] add test case for ClusterNode class --- tests/test_asyncio/test_cluster.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_asyncio/test_cluster.py b/tests/test_asyncio/test_cluster.py index 6543e2849c..bbe4cee72f 100644 --- a/tests/test_asyncio/test_cluster.py +++ b/tests/test_asyncio/test_cluster.py @@ -2230,3 +2230,20 @@ def cmd_init_mock(self, r): async with RedisCluster(startup_nodes=[node_1, node_2]) as rc: assert rc.get_node(host=default_host, port=7001) is not None assert rc.get_node(host=default_host, port=7002) is not None + + +@pytest.mark.onlycluster +class TestClusterNode: + """ + Tests for the ClusterNode class + """ + + async def test_valid_response_callbacks(self) -> None: + """ + ClusterNode must have valid default response_callbacks. + """ + + startup_nodes = [ClusterNode("127.0.0.1", 16379)] + async with RedisCluster(startup_nodes=startup_nodes) as rc: + assert await rc.set("A", 1) + assert await rc.get("A") == b'1' From a7f97bef14ea39163b381019227a6ff633decc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A4=91=EA=B7=BC?= Date: Fri, 27 May 2022 17:00:08 +0900 Subject: [PATCH 3/4] fix lint error --- tests/test_asyncio/test_cluster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_asyncio/test_cluster.py b/tests/test_asyncio/test_cluster.py index bbe4cee72f..6a67668889 100644 --- a/tests/test_asyncio/test_cluster.py +++ b/tests/test_asyncio/test_cluster.py @@ -2246,4 +2246,4 @@ async def test_valid_response_callbacks(self) -> None: startup_nodes = [ClusterNode("127.0.0.1", 16379)] async with RedisCluster(startup_nodes=startup_nodes) as rc: assert await rc.set("A", 1) - assert await rc.get("A") == b'1' + assert await rc.get("A") == b"1" From 9f03e9598e28989ecd851d81da9aca464f9c620e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A4=91=EA=B7=BC?= Date: Fri, 27 May 2022 17:59:38 +0900 Subject: [PATCH 4/4] merge test case into `test_startup_nodes` --- tests/test_asyncio/test_cluster.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/tests/test_asyncio/test_cluster.py b/tests/test_asyncio/test_cluster.py index 6a67668889..6c28ce35a2 100644 --- a/tests/test_asyncio/test_cluster.py +++ b/tests/test_asyncio/test_cluster.py @@ -244,6 +244,11 @@ async def test_startup_nodes(self) -> None: await cluster.close() + startup_nodes = [ClusterNode("127.0.0.1", 16379)] + async with RedisCluster(startup_nodes=startup_nodes) as rc: + assert await rc.set("A", 1) + assert await rc.get("A") == b"1" + async def test_empty_startup_nodes(self) -> None: """ Test that exception is raised when empty providing empty startup_nodes @@ -2230,20 +2235,3 @@ def cmd_init_mock(self, r): async with RedisCluster(startup_nodes=[node_1, node_2]) as rc: assert rc.get_node(host=default_host, port=7001) is not None assert rc.get_node(host=default_host, port=7002) is not None - - -@pytest.mark.onlycluster -class TestClusterNode: - """ - Tests for the ClusterNode class - """ - - async def test_valid_response_callbacks(self) -> None: - """ - ClusterNode must have valid default response_callbacks. - """ - - startup_nodes = [ClusterNode("127.0.0.1", 16379)] - async with RedisCluster(startup_nodes=startup_nodes) as rc: - assert await rc.set("A", 1) - assert await rc.get("A") == b"1"