Skip to content

Commit 77a1282

Browse files
committed
Fixes according to comments
1 parent 2adb2d7 commit 77a1282

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

redis/asyncio/cluster.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ class ClusterPipeline(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterComm
15551555
| Existing :class:`~.RedisCluster` client
15561556
"""
15571557

1558-
__slots__ = ("cluster_client",)
1558+
__slots__ = ("cluster_client", "_transaction", "_execution_strategy")
15591559

15601560
def __init__(
15611561
self, client: RedisCluster, transaction: Optional[bool] = None
@@ -1570,15 +1570,15 @@ def __init__(
15701570

15711571
async def initialize(self) -> "ClusterPipeline":
15721572
if self.cluster_client._initialize:
1573-
await self.cluster_client.initialize()
1573+
await self._execution_strategy.initialize()
15741574
self._execution_strategy._command_queue = []
15751575
return self
15761576

15771577
async def __aenter__(self) -> "ClusterPipeline":
15781578
return await self.initialize()
15791579

15801580
async def __aexit__(self, exc_type: None, exc_value: None, traceback: None) -> None:
1581-
self._execution_strategy._command_queue = []
1581+
await self.reset()
15821582

15831583
def __await__(self) -> Generator[Any, None, "ClusterPipeline"]:
15841584
return self.initialize().__await__()
@@ -1595,7 +1595,7 @@ def __bool__(self) -> bool:
15951595
return True
15961596

15971597
def __len__(self) -> int:
1598-
return len(self._execution_strategy._command_queue)
1598+
return len(self._execution_strategy)
15991599

16001600
def execute_command(
16011601
self, *args: Union[KeyT, EncodableT], **kwargs: Any
@@ -1794,32 +1794,16 @@ async def unlink(self, *names):
17941794
"""
17951795
pass
17961796

1797+
@abstractmethod
1798+
def __len__(self) -> int:
1799+
pass
1800+
17971801

17981802
class AbstractStrategy(ExecutionStrategy):
17991803
def __init__(self, pipe: ClusterPipeline) -> None:
18001804
self._pipe: ClusterPipeline = pipe
18011805
self._command_queue: List["PipelineCommand"] = []
18021806

1803-
async def __aenter__(self) -> "ClusterPipeline":
1804-
return await self._pipe.initialize()
1805-
1806-
async def __aexit__(self, exc_type: None, exc_value: None, traceback: None) -> None:
1807-
self._command_queue = []
1808-
1809-
def __await__(self) -> Generator[Any, None, "ClusterPipeline"]:
1810-
return self._pipe.initialize().__await__()
1811-
1812-
def __enter__(self) -> "ClusterPipeline":
1813-
self._command_queue = []
1814-
return self._pipe
1815-
1816-
def __exit__(self, exc_type: None, exc_value: None, traceback: None) -> None:
1817-
self._command_queue = []
1818-
1819-
def __bool__(self) -> bool:
1820-
"Pipeline instances should always evaluate to True on Python 3+"
1821-
return True
1822-
18231807
async def initialize(self) -> "ClusterPipeline":
18241808
if self._pipe.cluster_client._initialize:
18251809
await self._pipe.cluster_client.initialize()
@@ -1881,6 +1865,9 @@ async def discard(self):
18811865
async def unlink(self, *names):
18821866
pass
18831867

1868+
def __len__(self) -> int:
1869+
return len(self._command_queue)
1870+
18841871

18851872
class PipelineStrategy(AbstractStrategy):
18861873
def __init__(self, pipe: ClusterPipeline) -> None:
@@ -1931,7 +1918,7 @@ async def execute(
19311918
# All other errors should be raised.
19321919
raise e
19331920
finally:
1934-
self._command_queue = []
1921+
await self.reset()
19351922

19361923
async def _execute(
19371924
self,

0 commit comments

Comments
 (0)