Skip to content

Commit

Permalink
fix create single_connection_client from url (#2752)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvora-h committed May 8, 2023
1 parent 8c06d67 commit 984b733
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion redis/asyncio/client.py
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion redis/client.py
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_asyncio/test_connection.py
Expand Up @@ -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
8 changes: 8 additions & 0 deletions tests/test_connection.py
Expand Up @@ -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

0 comments on commit 984b733

Please sign in to comment.