diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 867be53cf2..a380f286c8 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -145,12 +145,13 @@ class initializer. In the case of conflicting arguments, querystring """ single_connection_client = kwargs.pop("single_connection_client", False) + auto_close_connection_pool = kwargs.pop("auto_close_connection_pool", True) connection_pool = ConnectionPool.from_url(url, **kwargs) redis = cls( connection_pool=connection_pool, single_connection_client=single_connection_client, ) - redis.auto_close_connection_pool = True + redis.auto_close_connection_pool = auto_close_connection_pool return redis def __init__( diff --git a/tests/test_asyncio/test_connection.py b/tests/test_asyncio/test_connection.py index 3e641a27d5..c4816a7e53 100644 --- a/tests/test_asyncio/test_connection.py +++ b/tests/test_asyncio/test_connection.py @@ -300,6 +300,26 @@ async def get_redis_connection(): r1 = await get_redis_connection() assert r1.auto_close_connection_pool is True + await r1.close() + + +@pytest.mark.parametrize("from_url", (True, False)) +async def test_pool_auto_close_disable(request, from_url): + """Verify that auto_close_connection_pool can be disabled""" + + url: str = request.config.getoption("--redis-url") + url_args = parse_url(url) + + async def get_redis_connection(): + if from_url: + return Redis.from_url(url, auto_close_connection_pool=False) + url_args["auto_close_connection_pool"] = False + return Redis(**url_args) + + r1 = await get_redis_connection() + assert r1.auto_close_connection_pool is False + await r1.connection_pool.disconnect() + await r1.close() @pytest.mark.onlynoncluster