From 984b733d52b44ec75e2c9ff53689a7b6fa86d719 Mon Sep 17 00:00:00 2001 From: dvora-h <67596500+dvora-h@users.noreply.github.com> Date: Mon, 8 May 2023 14:15:39 +0300 Subject: [PATCH] fix create single_connection_client from url (#2752) --- redis/asyncio/client.py | 6 +++++- redis/client.py | 6 +++++- tests/test_asyncio/test_connection.py | 6 ++++++ tests/test_connection.py | 8 ++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index a7b888eee4..7479b742b6 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -139,8 +139,12 @@ class initializer. In the case of conflicting arguments, querystring arguments always win. """ + single_connection_client = kwargs.pop("single_connection_client", False) connection_pool = ConnectionPool.from_url(url, **kwargs) - return cls(connection_pool=connection_pool) + return cls( + connection_pool=connection_pool, + single_connection_client=single_connection_client, + ) def __init__( self, diff --git a/redis/client.py b/redis/client.py index 65d0cec9a9..9fd5b7ca9e 100755 --- a/redis/client.py +++ b/redis/client.py @@ -906,8 +906,12 @@ class initializer. In the case of conflicting arguments, querystring arguments always win. """ + single_connection_client = kwargs.pop("single_connection_client", False) connection_pool = ConnectionPool.from_url(url, **kwargs) - return cls(connection_pool=connection_pool) + return cls( + connection_pool=connection_pool, + single_connection_client=single_connection_client, + ) def __init__( self, diff --git a/tests/test_asyncio/test_connection.py b/tests/test_asyncio/test_connection.py index e49dd42204..158b8545e2 100644 --- a/tests/test_asyncio/test_connection.py +++ b/tests/test_asyncio/test_connection.py @@ -271,3 +271,9 @@ async def open_connection(*args, **kwargs): vals = await asyncio.gather(do_read(), do_close()) assert vals == [b"Hello, World!", None] + + +@pytest.mark.onlynoncluster +def test_create_single_connection_client_from_url(): + client = Redis.from_url("redis://localhost:6379/0?", single_connection_client=True) + assert client.single_connection_client is True diff --git a/tests/test_connection.py b/tests/test_connection.py index 75ba738047..31268a9e8b 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -205,3 +205,11 @@ def test_pack_command(Class): actual = Class().pack_command(*cmd)[0] assert actual == expected, f"actual = {actual}, expected = {expected}" + + +@pytest.mark.onlynoncluster +def test_create_single_connection_client_from_url(): + client = redis.Redis.from_url( + "redis://localhost:6379/0?", single_connection_client=True + ) + assert client.connection is not None