diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 3e6626aedf..1ab8b51bd4 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 1a9b96b83d..36592b361f 100755 --- a/redis/client.py +++ b/redis/client.py @@ -899,8 +899,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 e2d77fc1c3..ae479787bc 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 25b4118b2c..f05175dcda 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