Skip to content

Commit fd08589

Browse files
committed
Add aclose() to asyncio.client.Pipeline
1 parent 7119770 commit fd08589

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

redis/asyncio/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,10 @@ async def reset(self):
12011201
await self.connection_pool.release(self.connection)
12021202
self.connection = None
12031203

1204+
async def aclose(self) -> None:
1205+
"""Alias for reset(), a standard method name for cleanup"""
1206+
await self.reset()
1207+
12041208
def multi(self):
12051209
"""
12061210
Start a transactional block of the pipeline after WATCH commands

tests/test_asyncio/test_pipeline.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import redis
33
from tests.conftest import skip_if_server_version_lt
44

5+
from .compat import aclosing, mock
56
from .conftest import wait_for_command
67

78

@@ -286,6 +287,24 @@ async def test_watch_reset_unwatch(self, r):
286287
assert unwatch_command is not None
287288
assert unwatch_command["command"] == "UNWATCH"
288289

290+
@pytest.mark.onlynoncluster
291+
async def test_aclose_is_reset(self, r):
292+
async with r.pipeline() as pipe:
293+
called = 0
294+
295+
async def mock_reset():
296+
nonlocal called
297+
called += 1
298+
299+
with mock.patch.object(pipe, "reset", mock_reset):
300+
await pipe.aclose()
301+
assert called == 1
302+
303+
@pytest.mark.onlynoncluster
304+
async def test_aclosing(self, r):
305+
async with aclosing(r.pipeline()):
306+
pass
307+
289308
@pytest.mark.onlynoncluster
290309
async def test_transaction_callable(self, r):
291310
await r.set("a", 1)

0 commit comments

Comments
 (0)