@@ -340,12 +340,13 @@ def __init__(
340340 ]:
341341 raise RedisError ("Client caching is only supported with RESP version 3" )
342342
343- self ._connection_lock = threading .Lock ()
343+ self .single_connection_lock = threading .Lock ()
344344 self .connection = None
345- if single_connection_client :
345+ self ._single_connection_client = single_connection_client
346+ if self ._single_connection_client :
346347 self .connection = self .connection_pool .get_connection ("_" )
347348 event_dispatcher .dispatch (
348- AfterSingleConnectionInstantiationEvent (self .connection , ClientType .SYNC , self ._connection_lock )
349+ AfterSingleConnectionInstantiationEvent (self .connection , ClientType .SYNC , self .single_connection_lock )
349350 )
350351
351352 self .response_callbacks = CaseInsensitiveDict (_RedisCallbacks )
@@ -582,6 +583,9 @@ def _execute_command(self, *args, **options):
582583 pool = self .connection_pool
583584 command_name = args [0 ]
584585 conn = self .connection or pool .get_connection (command_name , ** options )
586+
587+ if self ._single_connection_client :
588+ self .single_connection_lock .acquire ()
585589 try :
586590 return conn .retry .call_with_retry (
587591 lambda : self ._send_command_parse_response (
@@ -590,6 +594,8 @@ def _execute_command(self, *args, **options):
590594 lambda error : self ._disconnect_raise (conn , error ),
591595 )
592596 finally :
597+ if self ._single_connection_client :
598+ self .single_connection_lock .release ()
593599 if not self .connection :
594600 pool .release (conn )
595601
0 commit comments