Skip to content

Commit abfb92e

Browse files
committed
add aclose() to asyncio.connection.ConnectionPool
1 parent 64ce008 commit abfb92e

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
@@ -1187,6 +1187,10 @@ async def disconnect(self, inuse_connections: bool = True):
11871187
if exc:
11881188
raise exc
11891189

1190+
async def aclose(self) -> None:
1191+
"""Close the pool, disconnecting all connections"""
1192+
await self.disconnect()
1193+
11901194
def set_retry(self, retry: "Retry") -> None:
11911195
for conn in self._available_connections:
11921196
conn.retry = retry

tests/test_asyncio/test_connection_pool.py

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

11-
from .compat import mock
11+
from .compat import aclosing, mock
1212
from .conftest import asynccontextmanager
1313
from .test_pubsub import wait_for_message
1414

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

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

0 commit comments

Comments
 (0)