Skip to content

Commit 80edee7

Browse files
committed
add aclose() to asyncio.connection.ConnectionPool
1 parent c526c85 commit 80edee7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

redis/asyncio/connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,10 @@ async def disconnect(self, inuse_connections: bool = True):
10951095
if exc:
10961096
raise exc
10971097

1098+
async def aclose(self) -> None:
1099+
"""Close the pool, disconnecting all connections"""
1100+
await self.disconnect()
1101+
10981102
def set_retry(self, retry: "Retry") -> None:
10991103
for conn in self._available_connections:
11001104
conn.retry = retry

tests/test_asyncio/test_connection_pool.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from redis.asyncio.connection import Connection, to_bool
88
from tests.conftest import skip_if_redis_enterprise, skip_if_server_version_lt
99

10-
from .compat import mock
10+
from .compat import aclosing, mock
1111
from .conftest import asynccontextmanager
1212
from .test_pubsub import wait_for_message
1313

@@ -135,6 +135,16 @@ async def test_connection_creation(self):
135135
assert isinstance(connection, DummyConnection)
136136
assert connection.kwargs == connection_kwargs
137137

138+
async def test_aclosing(self):
139+
connection_kwargs = {"foo": "bar", "biz": "baz"}
140+
pool = redis.ConnectionPool(
141+
connection_class=DummyConnection,
142+
max_connections=None,
143+
**connection_kwargs,
144+
)
145+
async with aclosing(pool):
146+
pass
147+
138148
async def test_multiple_connections(self, master_host):
139149
connection_kwargs = {"host": master_host[0]}
140150
async with self.get_pool(connection_kwargs=connection_kwargs) as pool:

0 commit comments

Comments
 (0)