Skip to content

Commit a114f26

Browse files
Async clusters: Support creating locks inside async functions (#2471)
Co-authored-by: Chayim <[email protected]>
1 parent c48dc83 commit a114f26

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

redis/asyncio/cluster.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,13 @@ def __init__(
356356
)
357357

358358
self._initialize = True
359-
self._lock = asyncio.Lock()
359+
self._lock: Optional[asyncio.Lock] = None
360360

361361
async def initialize(self) -> "RedisCluster":
362362
"""Get all nodes from startup nodes & creates connections if not initialized."""
363363
if self._initialize:
364+
if not self._lock:
365+
self._lock = asyncio.Lock()
364366
async with self._lock:
365367
if self._initialize:
366368
try:
@@ -378,6 +380,8 @@ async def initialize(self) -> "RedisCluster":
378380
async def close(self) -> None:
379381
"""Close all connections & client if initialized."""
380382
if not self._initialize:
383+
if not self._lock:
384+
self._lock = asyncio.Lock()
381385
async with self._lock:
382386
if not self._initialize:
383387
self._initialize = True

0 commit comments

Comments
 (0)