Skip to content

Commit 984b733

Browse files
authored
fix create single_connection_client from url (#2752)
1 parent 8c06d67 commit 984b733

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

redis/asyncio/client.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ class initializer. In the case of conflicting arguments, querystring
139139
arguments always win.
140140
141141
"""
142+
single_connection_client = kwargs.pop("single_connection_client", False)
142143
connection_pool = ConnectionPool.from_url(url, **kwargs)
143-
return cls(connection_pool=connection_pool)
144+
return cls(
145+
connection_pool=connection_pool,
146+
single_connection_client=single_connection_client,
147+
)
144148

145149
def __init__(
146150
self,

redis/client.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,12 @@ class initializer. In the case of conflicting arguments, querystring
906906
arguments always win.
907907
908908
"""
909+
single_connection_client = kwargs.pop("single_connection_client", False)
909910
connection_pool = ConnectionPool.from_url(url, **kwargs)
910-
return cls(connection_pool=connection_pool)
911+
return cls(
912+
connection_pool=connection_pool,
913+
single_connection_client=single_connection_client,
914+
)
911915

912916
def __init__(
913917
self,

tests/test_asyncio/test_connection.py

+6
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,9 @@ async def open_connection(*args, **kwargs):
271271

272272
vals = await asyncio.gather(do_read(), do_close())
273273
assert vals == [b"Hello, World!", None]
274+
275+
276+
@pytest.mark.onlynoncluster
277+
def test_create_single_connection_client_from_url():
278+
client = Redis.from_url("redis://localhost:6379/0?", single_connection_client=True)
279+
assert client.single_connection_client is True

tests/test_connection.py

+8
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,11 @@ def test_pack_command(Class):
205205

206206
actual = Class().pack_command(*cmd)[0]
207207
assert actual == expected, f"actual = {actual}, expected = {expected}"
208+
209+
210+
@pytest.mark.onlynoncluster
211+
def test_create_single_connection_client_from_url():
212+
client = redis.Redis.from_url(
213+
"redis://localhost:6379/0?", single_connection_client=True
214+
)
215+
assert client.connection is not None

0 commit comments

Comments
 (0)