valkey-py
valkey-py copied to clipboard
Only instantiate async single connection client lock when needed
Hi,
we have an admittedly edge-case scenario where we're building the valkey.asyncio.Valkey client from a context without a running event loop (we inject the loop later).
We're not using the single client connection feature.
With the current implementation, the lock is instantiated regardless, rather than only when using the single client connection feature.
https://github.com/valkey-io/valkey-py/blob/95c4b68c93190bdb4c4e64fd38c9980d9dd35e8a/valkey/asyncio/client.py#L359
I'm proposing to change this to something like
self._single_conn_lock = asyncio.Lock() if self.single_connection_client else None