Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create single connection client from url #2752

Merged
merged 1 commit into from May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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,
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