valkey-py icon indicating copy to clipboard operation
valkey-py copied to clipboard

Only instantiate async single connection client lock when needed

Open robert-schmidtke opened this issue 8 months ago • 1 comments

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

robert-schmidtke avatar Mar 20 '25 12:03 robert-schmidtke