Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async clusters: Support creating locks inside async functions #2471

Merged
merged 2 commits into from Dec 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion redis/asyncio/cluster.py
Expand Up @@ -356,11 +356,13 @@ def __init__(
)

self._initialize = True
self._lock = asyncio.Lock()
self._lock: Optional[asyncio.Lock] = None

async def initialize(self) -> "RedisCluster":
"""Get all nodes from startup nodes & creates connections if not initialized."""
if self._initialize:
if not self._lock:
self._lock = asyncio.Lock()
async with self._lock:
if self._initialize:
try:
Expand All @@ -378,6 +380,8 @@ async def initialize(self) -> "RedisCluster":
async def close(self) -> None:
"""Close all connections & client if initialized."""
if not self._initialize:
if not self._lock:
self._lock = asyncio.Lock()
async with self._lock:
if not self._initialize:
self._initialize = True
Expand Down