Skip to content

Commit

Permalink
Allow the "auto_close_connection_pool" argument to Redis.from_url
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Jul 20, 2023
1 parent 8fd3537 commit a80c64c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion redis/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
20 changes: 20 additions & 0 deletions tests/test_asyncio/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a80c64c

Please sign in to comment.