Skip to content

Commit a80c64c

Browse files
committed
Allow the "auto_close_connection_pool" argument to Redis.from_url
1 parent 8fd3537 commit a80c64c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

redis/asyncio/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ class initializer. In the case of conflicting arguments, querystring
145145
146146
"""
147147
single_connection_client = kwargs.pop("single_connection_client", False)
148+
auto_close_connection_pool = kwargs.pop("auto_close_connection_pool", True)
148149
connection_pool = ConnectionPool.from_url(url, **kwargs)
149150
redis = cls(
150151
connection_pool=connection_pool,
151152
single_connection_client=single_connection_client,
152153
)
153-
redis.auto_close_connection_pool = True
154+
redis.auto_close_connection_pool = auto_close_connection_pool
154155
return redis
155156

156157
def __init__(

tests/test_asyncio/test_connection.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,26 @@ async def get_redis_connection():
300300

301301
r1 = await get_redis_connection()
302302
assert r1.auto_close_connection_pool is True
303+
await r1.close()
304+
305+
306+
@pytest.mark.parametrize("from_url", (True, False))
307+
async def test_pool_auto_close_disable(request, from_url):
308+
"""Verify that auto_close_connection_pool can be disabled"""
309+
310+
url: str = request.config.getoption("--redis-url")
311+
url_args = parse_url(url)
312+
313+
async def get_redis_connection():
314+
if from_url:
315+
return Redis.from_url(url, auto_close_connection_pool=False)
316+
url_args["auto_close_connection_pool"] = False
317+
return Redis(**url_args)
318+
319+
r1 = await get_redis_connection()
320+
assert r1.auto_close_connection_pool is False
321+
await r1.connection_pool.disconnect()
322+
await r1.close()
303323

304324

305325
@pytest.mark.onlynoncluster

0 commit comments

Comments
 (0)