Skip to content

Commit

Permalink
add aclose() to asyncio.connection.ConnectionPool
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Aug 17, 2023
1 parent 64ce008 commit abfb92e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,10 @@ async def disconnect(self, inuse_connections: bool = True):
if exc:
raise exc

async def aclose(self) -> None:
"""Close the pool, disconnecting all connections"""
await self.disconnect()

def set_retry(self, retry: "Retry") -> None:
for conn in self._available_connections:
conn.retry = retry
Expand Down
12 changes: 11 additions & 1 deletion tests/test_asyncio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from redis.asyncio.connection import Connection, to_bool
from tests.conftest import skip_if_redis_enterprise, skip_if_server_version_lt

from .compat import mock
from .compat import aclosing, mock
from .conftest import asynccontextmanager
from .test_pubsub import wait_for_message

Expand Down Expand Up @@ -134,6 +134,16 @@ async def test_connection_creation(self):
assert isinstance(connection, DummyConnection)
assert connection.kwargs == connection_kwargs

async def test_aclosing(self):
connection_kwargs = {"foo": "bar", "biz": "baz"}
pool = redis.ConnectionPool(
connection_class=DummyConnection,
max_connections=None,
**connection_kwargs,
)
async with aclosing(pool):
pass

async def test_multiple_connections(self, master_host):
connection_kwargs = {"host": master_host[0]}
async with self.get_pool(connection_kwargs=connection_kwargs) as pool:
Expand Down

0 comments on commit abfb92e

Please sign in to comment.