Skip to content

Commit 15e4169

Browse files
committed
Replace ensure_future with create_task
1 parent f9f9d06 commit 15e4169

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

redis/asyncio/cluster.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ async def execute_command(self, *args: EncodableT, **kwargs: Any) -> Any:
642642
keys = [node.name for node in target_nodes]
643643
values = await asyncio.gather(
644644
*(
645-
asyncio.ensure_future(
645+
asyncio.create_task(
646646
self._execute_command(node, *args, **kwargs)
647647
)
648648
for node in target_nodes
@@ -841,7 +841,7 @@ def __del__(self) -> None:
841841
async def disconnect(self) -> None:
842842
ret = await asyncio.gather(
843843
*(
844-
asyncio.ensure_future(connection.disconnect())
844+
asyncio.create_task(connection.disconnect())
845845
for connection in self._connections
846846
),
847847
return_exceptions=True,
@@ -979,13 +979,13 @@ def set_nodes(
979979
if remove_old:
980980
for name in list(old.keys()):
981981
if name not in new:
982-
asyncio.ensure_future(old.pop(name).disconnect())
982+
asyncio.create_task(old.pop(name).disconnect())
983983

984984
for name, node in new.items():
985985
if name in old:
986986
if old[name] is node:
987987
continue
988-
asyncio.ensure_future(old[name].disconnect())
988+
asyncio.create_task(old[name].disconnect())
989989
old[name] = node
990990

991991
def _update_moved_slots(self) -> None:
@@ -1202,7 +1202,7 @@ async def close(self, attr: str = "nodes_cache") -> None:
12021202
self.default_node = None
12031203
await asyncio.gather(
12041204
*(
1205-
asyncio.ensure_future(node.disconnect())
1205+
asyncio.create_task(node.disconnect())
12061206
for node in getattr(self, attr).values()
12071207
)
12081208
)
@@ -1381,7 +1381,7 @@ async def _execute(
13811381

13821382
errors = await asyncio.gather(
13831383
*(
1384-
asyncio.ensure_future(node[0].execute_pipeline(node[1]))
1384+
asyncio.create_task(node[0].execute_pipeline(node[1]))
13851385
for node in nodes.values()
13861386
)
13871387
)

redis/commands/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ async def cluster_delslots(self, *slots: EncodableT) -> List[bool]:
673673
"""
674674
return await asyncio.gather(
675675
*(
676-
asyncio.ensure_future(self.execute_command("CLUSTER DELSLOTS", slot))
676+
asyncio.create_task(self.execute_command("CLUSTER DELSLOTS", slot))
677677
for slot in slots
678678
)
679679
)

tests/test_asyncio/compat.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,4 @@
99

1010

1111
def create_task(coroutine):
12-
if sys.version_info[:2] >= (3, 7):
13-
return asyncio.create_task(coroutine)
14-
else:
15-
return asyncio.ensure_future(coroutine)
12+
return asyncio.create_task(coroutine)

0 commit comments

Comments
 (0)