+
     hs  c                   s  a  R3 t\0 t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHtHt ^ RIHt ^ RIHtHtHtHtHtHtHt ^ RIHtHtHt ^ RIHtHtH t H!t!H"t"H#t# ^R	I$H%t%H&t&H't'H(t( ^R
I)H*t* ^RI+H,t,H-t- ^RI.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6 ^RI7H8t8 ^RI9H:t:H;t;H<t<H=t=H>t>H?t?H@t@HAtA ];'       d   ^ RIBtBRtCRtDRtERtF^tG]H! 4       tI] ^ k ];'       d   ]&tJM]'tJ ! R R4      tK ! R R4      tL ! R R4      tM ! R R]M4      tN ! R R]N4      tO ! R R]M4      tP ! R R ]O4      tQ ! R! R"]N4      tRR4tSR# tTR$]UR%]VR&]VR']TR(]TR)]WR*]UR+]UR,]TR-]V/
tXR. tY ! R/ R04      tZ ! R1 R2]Z4      t[R# )5    N)abstractmethod)chain)EmptyFull	LifoQueue)time)AnyCallableDictListOptionalTypeUnion)parse_qsunquoteurlparse)
CacheEntryCacheEntryStatusCacheFactoryCacheFactoryInterfaceCacheInterfaceCacheKey)Encoder_HiredisParser_RESP2Parser_RESP3Parser)	NoBackoff)CredentialProvider"UsernamePasswordCredentialProvider)AuthenticationError$AuthenticationWrongNumberOfArgsErrorChildDeadlockedErrorConnectionError	DataError
RedisErrorResponseErrorTimeoutError)Retry)CRYPTOGRAPHY_AVAILABLEHIREDIS_AVAILABLESSL_AVAILABLEcompare_versionsensure_stringformat_error_messageget_lib_versionstr_if_bytess   *s   $s   
    c                   s2   a  ] tR t^Dt o V 3R lR ltRtV tR# )HiredisRespSerializerc                    < V ^8  d   QhRS[ /# )   args)r
   format__classdict__   "5/usr/lib/python3.14/site-packages/redis/connection.py__annotate__Z"HiredisRespSerializer.__annotate__E   s      $ r/   c                s   . p\        V^ ,          \        4      '       d>   \        V^ ,          P                  4       P	                  4       4      VR,          ,           pM<RV^ ,          9   d/   \        V^ ,          P	                  4       4      VR,          ,           p VP                  \        P                  ! V4      4       V#   \         d4    \        P                  ! 4       w  r4p\        T4      P                  T4      hi ; i2Pack a series of arguments into the Redis protocol:   NNs    )
isinstancestrtupleencodesplitappendhiredispack_command	TypeErrorsysZexc_infor"   Zwith_traceback)selfr3   output_valueZ	tracebacks   &*    r8   packZHiredisRespSerializer.packE   s    d1gs##a)//12T"X=DT!W_a)DH4D	=MM'..t45
 	  	="%,,.AiE"11)<<	=s   %C >C? N)__name__
__module____qualname____firstlineno__rK   __static_attributes____classdictcell__r6      @r8   r0   r0   D   s      r/   r0   c                   s8   a  ] tR t^Vt o V 3R lR ltR tRtV tR# )PythonRespSerializerc                   < V ^8  d   QhRR/# r2   returnNrL   r4   r7   r8   r9   Z!PythonRespSerializer.__annotate__W   s       r/   c                s    Wn         W n        R # N_buffer_cutoffr@   )rG   buffer_cutoffr@      &&&r8   __init__ZPythonRespSerializer.__init__W   s    +r/   c           	     s   . p\        V^ ,          \        4      '       d>   \        V^ ,          P                  4       P	                  4       4      VR,          ,           pM<RV^ ,          9   d/   \        V^ ,          P	                  4       4      VR,          ,           p\
        P                  \        \        \        V4      4      P                  4       \        34      pV P                  p\        V P                  V4       F  p\        V4      p\        V4      V8  g   Wd8  g   \        V\        4      '       dc   \
        P                  V\        \        V4      P                  4       \        34      pVP                  V4       VP                  V4       \        pK  \
        P                  V\        \        V4      P                  4       \        V\        34      pK  	  VP                  V4       V# r:   )r=   r>   r?   r@   rA   	SYM_EMPTYjoinSYM_STARlenSYM_CRLFr[   Zmap
memoryview
SYM_DOLLARrB   )rG   r3   rH   Zbuffr\   ZargZ
arg_lengths   &*     r8   rK   ZPythonRespSerializer.pack[   sd    d1gs##a)//12T"X=DT!W_a)DH4D~~xSY)>)>)@(KL++t{{D)C SJD	M)-c:.. ~~:s:'='='?J d#c" ~~"J..0  	! *4 	dr/   rZ   N)rM   rN   rO   rP   r^   rK   rQ   rR   rS   rT   r8   rU   rU   V   s      + +r/   rU   c                   s>  a  ] tR t^t o ]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       t]R 4       t]RR
 l4       t]R 4       t]RR l4       t]RRR	RR/R ll4       t]R 4       t]R 4       t]]V 3R lR l4       4       tRtV tR# )ConnectionInterfacec                    R # rY   rL   rG      &r8   repr_piecesZConnectionInterface.repr_pieces       r/   c                rg   rY   rL   rG   callback   &&r8   register_connect_callbackZ-ConnectionInterface.register_connect_callback   rk   r/   c                rg   rY   rL   rl   rn   r8   deregister_connect_callbackZ/ConnectionInterface.deregister_connect_callback   rk   r/   c                rg   rY   rL   rG   parser_classrn   r8   
set_parserZConnectionInterface.set_parser   rk   r/   c                rg   rY   rL   rh   ri   r8   connectZConnectionInterface.connect   rk   r/   c                rg   rY   rL   rh   ri   r8   
on_connectZConnectionInterface.on_connect   rk   r/   c                rg   rY   rL   rG   r3      &*r8   
disconnectZConnectionInterface.disconnect   rk   r/   c                rg   rY   rL   rh   ri   r8   check_healthZ ConnectionInterface.check_health   rk   r/   Tc                rg   rY   rL   rG   commandry   r]   r8   send_packed_commandZ'ConnectionInterface.send_packed_command   rk   r/   c                rg   rY   rL   rG   r3   kwargs   &*,r8   send_commandZ ConnectionInterface.send_command   rk   r/   c                rg   rY   rL   rG   timeoutrn   r8   can_readZConnectionInterface.can_read   rk   r/   Fdisconnect_on_errorpush_requestc               rg   rY   rL   )rG   disable_decodingr   r   s   &&$$r8   read_responseZ!ConnectionInterface.read_response   s     	r/   c                rg   rY   rL   rv   rw   r8   rD   Z ConnectionInterface.pack_command   rk   r/   c                rg   rY   rL   rG   commandsrn   r8   pack_commandsZ!ConnectionInterface.pack_commands   rk   r/   c                b   < V ^8  d   QhRS[ S[S[S[3,          S[S[S[3,          3,          /# r2   rX   r   r	   bytesr>   r4   r7   r8   r9   Z ConnectionInterface.__annotate__   s/      E$ue|*<d38n*L$M r/   c                rg   rY   rL   rh   ri   r8   handshake_metadataZ&ConnectionInterface.handshake_metadata   s     	r/   rL   NTr    F)rM   rN   rO   rP   r   rj   ro   rp   rs   rt   ru   rx   ry   r|   r   r   r   rD   r   propertyr   rQ   rR   rS   rT   r8   rf   rf      sK                           !	
         r/   rf   c                   s  a  ] tR t^t o Rt^ RRRR]RRR]R^ RR]! 4       RRRR^R3V 3R lR	 lltR
 t	]
R 4       tR tR tR tR tR tR t]
R 4       t]
R 4       tR tR tR tR tR tR tR*R ltR tR+R ltR,RRRR/R  lltR! tR" tV 3R# lR$ lt ]!V 3R% lR& l4       t"]"PF                  V 3R' lR( l4       t"R)t$V t%R# )-AbstractConnectionz0Manages communication to and from a Redis serverNFutf-8stricti   zredis-pyc          )      st  < V ^8  d   QhRS[ RS[S[,          RS[S[,          RS[S[,          RS[RS[RS[RS[R	S[ R
S[ RS[S[,          RS[S[,          RS[S[,          RS[S[,          RS[S[R3,          RS[S[. R3,          ,          RS[S[,          RS[S[ ,          RS[S[. R3,          ,          /# )r2   dbpasswordsocket_timeoutsocket_connect_timeoutretry_on_timeoutencodingencoding_errorsdecode_responsessocket_read_sizehealth_check_intervalclient_namelib_namelib_versionusernameretryNredis_connect_funccredential_providerprotocolcommand_packer)	intr   r>   floatboolr   r   r   r   r4   r7   r8   r9   AbstractConnection.__annotate__   s>    XN XNXN 3-XN !	XN
 !)XN XN XN XN XN XN  #XN c]XN 3-XN  c]!XN" 3-#XN$ S$Y%XN& %Xb$h%78'XN( &&89)XN* 3-+XN, !"d(!34-XNr/   c                s0   V'       g	   V'       d   Ve   \        R4      h\        P                  ! 4       V n        Wn        Wn        Wn        Wn        VV n        W n	        VV n
        W0n        Vf   TpW@n        WPn        V\        J d   . pV'       d   VP                  \         4       W`n        V'       g	   V'       dV   Vf   \%        \'        4       ^4      V n        M\*        P,                  ! V4      V n        V P(                  P/                  V4       M\%        \'        4       ^ 4      V n        Wn        ^ V n        VV n        \7        WxV	4      V n        RV n        RV n        Wn        V PA                  V
4       . V n!        RV n"         \G        V4      pT^8  g   T^8  d   \O        R4      hTT n(        T PS                  T4      T n*        R#   \H         d
    \J        p LK\L         d    \O        R4      hi ; i  X^8  g   T^8  d   \O        R4      hTT n(        i ; i)a  
Initialize a new Connection.
To specify a retry policy for specific errors, first set
`retry_on_error` to a list of the error/s to retry on, then set
`retry` to a valid `Retry` object.
To retry on TimeoutError, `retry_on_timeout` can also be set to `True`.
Nz'username' and 'password' cannot be passed along with 'credential_provider'. Please provide only one of the following arguments: 
1. 'password' and (optional) 'username'
2. 'credential_provider'ip  zprotocol must be an integerzprotocol must be either 2 or 3)+r"   osgetpidpidr   r   r   r   r   r   r   r   r   r   SENTINELrB   r%   retry_on_errorr&   r   r   copydeepcopyZupdate_supported_errorsr   next_health_checkr   r   encoderr   _sock_socket_read_sizers   _connect_callbacksr[   r   rE   DEFAULT_RESP_VERSION
ValueErrorr!   r   _construct_command_packer_command_packer)rG   r   r   r   r   r   r   r   r   r   rr   r   r   r   r   r   r   r   r   r   r   r   Zps   &&&&&&&&&&&&&&&&&&&&&& r8   r^   ZAbstractConnection.__init__   s   > &9&E+  99;& &#6   ,!)%3"&<# 0X%N!!,/,N}"9;2
 "]]51
JJ..~>y{A.DJ%:"!""4x:JK"&
!1%"$"
	HA 1uA%&FGGDM#==nM  	%$A 	A!"?@@	A 1uA%&FGGDMs*   G G0G3 G0#G00G3 3"Hc           	     s    R P                  V P                  4        UUu. uF  w  rV RV 2NK  	  upp4      pRV P                  P                   RV P                  P                   RV R2# u uppi )Z,Z=<.()>)r`   rj   	__class__rN   rM   )rG   kvZ	repr_argss   &   r8   __repr__ZAbstractConnection.__repr__+  sn    HHT5E5E5GH5GTQ1QCj5GHI	4>>,,-Qt~~/F/F.GqSUVV Is   A-
c                rg   rY   rL   rh   ri   r8   rj   ZAbstractConnection.repr_pieces/  rk   r/   c                sL     V P                  4        R #   \         d     R # i ; irY   )rx   Z	Exceptionrh   ri   r8   __del__ZAbstractConnection.__del__3  s#    	OO 		s    ##c                s    Ve   V# \         '       d   \        4       # \        V P                  V P                  P
                  4      # rY   )r(   r0   rU   r[   r   r@   )rG   Zpackerrn   r8   r   Z,AbstractConnection._construct_command_packer9  s9    M(**'(;(;T\\=P=PQQr/   c                s    \         P                  ! V4      pW P                  9  d   V P                  P                  V4       R# R# )a.  
Register a callback to be called when the connection is established either
initially or reconnected.  This allows listeners to issue commands that
are ephemeral to the connection, for example pub/sub subscription or
key tracking.  The callback must be a _method_ and will be kept as
a weak reference.
N)weakref
WeakMethodr   rB   )rG   rm   Zwm   && r8   ro   Z,AbstractConnection.register_connect_callbackA  s9     ),,,##**2. -r/   c                s     V P                   P                  \        P                  ! V4      4       R#   \         d     R# i ; i)z
De-register a previously registered callback.  It will no-longer receive
notifications on connection events.  Calling this is not required when the
listener goes away, since the callbacks are kept as weak methods.
N)r   remover   r   r   rl   rn   r8   rp   Z.AbstractConnection.deregister_connect_callbackM  s8    	##**7+=+=h+GH 		s   /3 AAc                s6    V! V P                   R7      V n        R# )z
Creates a new instance of parser_class with socket size:
_socket_read_size and assigns it to the parser for the connection
:param parser_class: The required parser class
)r   N)r   _parserrq   rn   r8   rs   ZAbstractConnection.set_parserX  s     $T5K5KLr/   c                s  a  S P                   '       d   R#  S P                  P                  V 3R lV 3R l4      pTS n          S P                  f   S P                  4        MS P                  S 4        S P                   Uu. uF  q3! 4       '       g   K  TNK  	  upS n        S P                   F  pT! 4       pT'       g   K  T! S 4       K  	  R#   \        P                   d    \        R4      h\         d    p\        S P                  T4      4      hRp?ii ; i  \         d    S P                  4        h i ; iu upi )z5Connects to the Redis server if not already connectedNc                  s$   < S P                  4       # rY   )_connectrh   s   r8   <lambda>,AbstractConnection.connect.<locals>.<lambda>f  s    r/   c                 s&   < SP                  V 4      # rY   rx   )errorrG   s   &r8   r   r   f  s    tu7Mr/   zTimeout connecting to server)r   r   call_with_retrysocketr   r%   OSErrorr!   _error_messager   ru   r#   rx   r   )rG   sockeZrefrm   s   f    r8   rt   ZAbstractConnection.connect`  s   :::	:::--')MD 

	&&.! ''- 372I2I"S2I3SU332I"S**CuHx +- ~~ 	?=>> 	:!$"5"5a"899	:  	OO	 #Ts;   $C D "D D=D=(D:D;DDD:c                rg   rY   rL   rh   ri   r8   r   ZAbstractConnection._connect  rk   r/   c                rg   rY   rL   rh   ri   r8   _host_errorZAbstractConnection._host_error  rk   r/   c                s6    \        V P                  4       V4      # rY   )r,   r   )rG   Z	exceptionrn   r8   r   Z!AbstractConnection._error_message  s    #D$4$4$6	BBr/   c                s   V P                   P                  V 4       V P                   pRpV P                  '       g%   V P                  '       g   V P                  '       dE   V P                  ;'       g!    \        V P                  V P                  4      pVP                  4       pV'       d   V P                  R9  d   \        V P                   \        4      '       dL   V P                  \        4       VP                  V P                   n        V P                   P                  V 4       \        V4      ^8X  d   RV^ ,          .pV P                  ! RV P                  R.VO5!   V P                  4       V n        EMXV'       dE   V P                  ! R.VO5RR/   V P                  4       p\%        V4      R8w  d   \'        R	4      hEMV P                  R9  d   \        V P                   \        4      '       dL   V P                  \        4       VP                  V P                   n        V P                   P                  V 4       V P                  RV P                  4       V P                  4       V n        V P                   P)                  R
4      V P                  8w  d6   V P                   P)                  R4      V P                  8w  d   \+        R4      hV P,                  '       dG   V P                  RRV P,                  4       \%        V P                  4       4      R8w  d   \+        R4      h V P.                  '       d/   V P                  RRRV P.                  4       V P                  4         T P2                  '       d/   T P                  RRRT P2                  4       T P                  4        T P4                  '       dH   T P                  RT P4                  4       \%        T P                  4       4      R8w  d   \+        R4      hR# R#   \"         d0    T P                  RTR,          RR7       T P                  4       p ELi ; i  \0         d     Li ; i  \0         d     Li ; i)z=Initialize the connection, authenticate and select a databaseNZdefaultZHELLOZAUTHry   Fry   ZOKzInvalid Username or Passwords   protoprotozInvalid RESP versionCLIENTZSETNAMEzError setting client nameZSETINFOzLIB-NAMEzLIB-VERZSELECTzInvalid Database)r2   Z2i)r   ru   r   r   r   r   Zget_credentialsr   r=   r   rs   r   ZEXCEPTION_CLASSESrb   r   r   r   r   r.   r   getr!   r   r   r$   r   r   )rG   parserZ	auth_argsZcred_providerZauth_response   &    r8   ru   ZAbstractConnection.on_connect  s{   %	###(( T T5dmmT]]S  &557I h6$,,55-171I1I.''-9~"&	!5	gt}}fIyI&*&8&8&:D#
  fEyEuE5 $ 2 2 4 M*d2)*HII 3 ]](*$,,55-171I1I.''-gt}}5&*&8&8&:D#''++H5F++//8DMMI%&<== h	43C3CDD..01T9%&ABB	}}}!!(Iz4==Q""$	!!(Iy$BRBRS""$
 777h0D..01T9%&899 : a 8 5
 !!&)B-e!L $ 2 2 45J  		  		sB   P +Q =.Q ,Q >.Q 6Q QQQQ#"Q#c                sh   V P                   P                  4        V P                  pRV n        Vf   R# \        P                  ! 4       V P
                  8X  d!    VP                  \        P                  4        VP                  4        R#   \        \        3 d     L&i ; i  \         d     R# i ; i)z!Disconnects from the Redis serverN)r   Zon_disconnectr   r   r   r   shutdownr   Z	SHUT_RDWRr   rE   close)rG   r3   Z	conn_socks   &* r8   rx   ZAbstractConnection.disconnect  s    ""$JJ	
99;$(("""6#3#34	OO	 Y' 
  		s$   B 9B" BB"B10B1c                s~    V P                  RRR7       \        V P                  4       4      R8w  d   \        R4      hR# )z Send PING, expect PONG in returnZPINGFr   ZPONGz#Bad response from PING health checkN)r   r.   r   r!   rh   ri   r8   
_send_pingZAbstractConnection._send_ping  s<    &u5**,-7!"GHH 8r/   c                &    V P                  4        R# )z Function to call when PING failsNr   )rG   r   rn   r8   _ping_failedZAbstractConnection._ping_failed      r/   c                s    V P                   '       dN   \        4       V P                  8  d3   V P                  P	                  V P
                  V P                  4       R# R# R# )z3Check the health of the connection with a PING/PONGN)r   r   r   r   r   r   r   rh   ri   r8   ry   ZAbstractConnection.check_health  sD    %%%$&43I3I*IJJ&&t8I8IJ +J%r/   Tc                s   V P                   '       g   V P                  4        V'       d   V P                  4         \        V\        4      '       d   V.pV F  pV P                   P                  V4       K   	  R#   \        P                   d    T P                  4        \        R4      h\         d}   pT P                  4        \        TP                  4      ^8X  d   RTP                  ^ ,          reM&TP                  ^ ,          pTP                  ^,          p\        RT RT R24      hRp?i\         d    T P                  4        h i ; i)z2Send an already packed command to the Redis serverzTimeout writing to socketZUNKNOWNzError z while writing to socket. r   N)r   rt   ry   r=   r>   Zsendallr   r   rx   r%   r   rb   r3   r!   BaseException)rG   r{   ry   Zitemr   ZerrnoZerrmsgs   &&&    r8   r|   Z&AbstractConnection.send_packed_command  s   zzzLLN	'3''")

""4(  ~~ 	<OO:;; 	WOO166{a )166!9vq	!F5'1KF8ST"UVV 	
 OO	s$   =A; ;8E4E5A7D,,E9Ec                s|    V P                  V P                  P                  ! V!  VP                  RR4      R7       R# )z+Pack and send a command to the Redis serverry   Tr   N)r|   r   rK   r   r}   r   r8   r   ZAbstractConnection.send_command*  s7        %%t,ND9 	! 	
r/   c                s   V P                   pV'       g   V P                  4        V P                  4       p V P                  P	                  V4      #   \
         d1   pT P                  4        \        RT RTP                   24      hRp?ii ; i)z8Poll the socket to see if there's data that can be read.Error while reading from z: N)	r   rt   r   r   r   r   rx   r!   r3   )rG   r   r   
host_errorr   s   &&   r8   r   ZAbstractConnection.can_read1  sy    zzLLN%%'
	V<<((11 	VOO!$=j\AFF8"TUU	Vs   A B+BBr   r   c               s   V P                  4       p V P                  R9   d*   \        '       g   V P                  P	                  WR7      pMV P                  P	                  VR7      p V P                  '       d!   \        4       V P                  ,           V n        \!        V\"        4      '       d    VhV#   \
        P                   d(    T'       d   T P                  4        \        RT 24      h\         d9   pT'       d   T P                  4        \        RT RTP                   24      hRp?i\         d    T'       d   T P                  4        h i ; i  ?i ; i)z0Read the response from a previously sent command)r   r   )r   zTimeout reading from r   z : N)3   )r   r   r(   r   r   r   r   rx   r%   r   r!   r3   r   r   r   r   r=   r$   )rG   r   r   r   r   responser   s   &&$$   r8   r   Z AbstractConnection.read_response?  s/    %%'
	}}(1B1B<<55%5 6   <<55GW5X& %%%%)Vd.H.H%HD"h.. 5 ~~ 	E"!!6zlCDD 	"!!+J<3qvvhG   	 #!	 sF   B6 B6 B6 2E 6E&E:E;3D..E;EEEc                6    V P                   P                  ! V!  # )r;   )r   rK   rv   rw   r8   rD   ZAbstractConnection.pack_commandm  s    ##(($//r/   c                s    . p. p^ pV P                   pV F  pV P                  P                  ! V!   F  p\        V4      pWE8  g   W8  g   \	        V\
        4      '       d1   V'       d%   VP                  \        P                  V4      4       ^ p. pW8  g   \	        V\
        4      '       d   VP                  V4       K  VP                  V4       WH,          pK  	  K  	  V'       d%   VP                  \        P                  V4      4       V# )z.Pack multiple commands into the Redis protocol)	r[   r   rK   rb   r=   rd   rB   r_   r`   )	rG   r   rH   piecesZbuffer_lengthr\   ZcmdZchunkZchunklens	   &&       r8   r   Z AbstractConnection.pack_commandsq  s    ++C--22C8u:!1/!%44innV&<=$%MF+z%/L/LMM%(MM%(!-M! 9 & MM)..01r/   c                s6   < V ^8  d   QhRS[ ;'       g    S[/# r   )r   r>   r4   r7   r8   r9   r     s      cjjS r/   c                    V P                   # rY   )r   rh   ri   r8   get_protocolZAbstractConnection.get_protocol  s    }}r/   c                r   r   r   r4   r7   r8   r9   r     s/     ( (E$ue|*<d38n*L$M (r/   c                r   rY   _handshake_metadatarh   ri   r8   r   %AbstractConnection.handshake_metadata  s    '''r/   c                r   )r2   rJ   r   r4   r7   r8   r9   r     s/     ) )d5%<.@$sCx..P(Q )r/   c                s    Wn         R # rY   r   )rG   rJ   rn   r8   r   r     s    #( r/   )r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )&rM   rN   rO   rP   __doc__r   DefaultParserr-   r^   r   r   rj   r   r   ro   rp   rs   rt   r   r   r   ru   rx   r   r   ry   r|   r   r   r   rD   r   r   r   r   ZsetterrQ   rR   rS   rT   r8   r   r      sM    6 "&*.26!&'!&" %%&%)",%4%6"&"&;?<@"#7;-XN XNtW  R
/	M!F    CX:t(IK
>
V, !	,
 ,\0<  ( ( ) )r/   r   c                   L   a a ] tR tRt oRtRV 3R lltR tR tR tRt	Vt
V ;t# )	
Connectioni  z4Manages TCP communication to and from a Redis serverc                s   < Wn         \        V4      V n        W0n        T;'       g    / V n        WPn        \        SV `  ! R/ VB  R # NrL   )hostr   portsocket_keepalivesocket_keepalive_optionssocket_typesuperr^   )rG   r   r   r   r   r   r~   r   s   &&&&&&,r8   r^   ZConnection.__init__  sA     	I	 0(@(F(FB%&"6"r/   c                s    R V P                   3RV P                  3RV P                  3.pV P                  '       d   VP	                  RV P                  34       V# )r   r   r   r   )r   r   r   r   rB   rG   r      & r8   rj   ZConnection.repr_pieces  sP    499%		':T477OLMM=$*:*:;<r/   c                sh   Rp\         P                  ! V P                  V P                  V P                  \         P
                  4       EF  pVw  r4rVpRp \         P                   ! W4V4      pVP                  \         P                  \         P                  ^4       V P                  '       ds   VP                  \         P                  \         P                  ^4       V P                  P                  4        F%  w  rVP                  \         P                  W4       K'  	  VP                  V P                  4       VP!                  V4       VP                  V P"                  4       Vu # 	  Ve   Vh\%        R4      h  \$         d*   pTpTe   TP'                  4         Rp?EK]   Rp?EKd  Rp?ii ; i)zCreate a TCP socket connectionNz)socket.getaddrinfo returned an empty list)r   Zgetaddrinfor   r   r   SOCK_STREAMZ
setsockoptZIPPROTO_TCPZTCP_NODELAYr   Z
SOL_SOCKETZSO_KEEPALIVEr   items
settimeoutr   rt   r   r   r   )rG   ZerrZresZfamilyZsocktyper   Z	canonnameZsocket_addressr   r   r   rI   s   &           r8   r   ZConnection._connect  s[   
 %%IItyy$"2"2F4F4F
C BE>FeD!}}Vu= 2 2F4F4FJ (((OOF$5$5v7J7JAN $ = = C C E(:(:AA !F  ; ;< ^,  3 341
> ?IABB  !#JJLL $!s   DE==F1F,,F1c                s8    V P                    R V P                   2# )Z:)r   r   rh   ri   r8   r   ZConnection._host_error  s    ))Adii[))r/   )r   r   r   r   r   )Z	localhosti  FNr    rM   rN   rO   rP   r   r^   rj   r   r   rQ   rR   __classcell__r   r6      @@r8   r   r     s#     :# 'CR* *r/   r   c                   s   a  ] tR tRt o RtRtRtV 3R lR ltR tR t	R	 t
R
 tR tR tR tR tR$R ltR tR%R ltR&RRRR/R lltR tR t]V 3R lR l4       tR tR tV 3R lR ltR tV 3R  lR! ltR"tV tR## )'CacheProxyConnectioni  s   fooz7.4.0Zredisc                s@   < V ^8  d   QhRS[ RS[RS[P                  /# )r2   conncache	pool_lock)rf   r   	threadingLockr4   r7   r8   r9   !CacheProxyConnection.__annotate__  s2     G G!G G >>	Gr/   c                s   \         P                  ! 4       V n        Wn        V P                  P                  V n        V P                  P
                  V n        V P                  P                  V n        W0n        W n        \        P                  ! 4       V n        R V n        R V n        V P                  V P                  4       R # rY   )r   r   r   _connr   r   r   
_pool_lock_cacher	  r
  _cache_lock_current_command_cache_key_current_optionsro   _enable_tracking_callback)rG   r  r  r  s   &&&&r8   r^   ZCacheProxyConnection.__init__  s     99;
ZZ%%
JJOO	JJOO	#$>>+*.' $&&t'E'EFr/   c                s6    V P                   P                  4       # rY   )r  rj   rh   ri   r8   rj   Z CacheProxyConnection.repr_pieces  s    zz%%''r/   c                <    V P                   P                  V4       R # rY   )r  ro   rl   rn   r8   ro   Z.CacheProxyConnection.register_connect_callback  s    

,,X6r/   c                r  rY   )r  rp   rl   rn   r8   rp   Z0CacheProxyConnection.deregister_connect_callback  s    

..x8r/   c                r  rY   )r  rs   rq   rn   r8   rs   ZCacheProxyConnection.set_parser  s    

l+r/   c                s6   V P                   P                  4        V P                   P                  P                  R R4      pVf'   V P                   P                  P                  RR4      pV P                   P                  P                  RR4      pVf'   V P                   P                  P                  RR4      pVe   Vf   \	        R4      h\        V4      p\        V4      pWP                  8w  g   \        W P                  4      ^8X  d   \	        R4      hR# )s   serverNZservers   versionZversionz0Cannot retrieve information about server versionziTo maximize compatibility with all Redis products, client-side caching is supported by Redis 7.4 or later)	r  rt   r   r   r!   r+   DEFAULT_SERVER_NAMEr*   MIN_ALLOWED_VERSION)rG   Zserver_nameZ
server_vers   &  r8   rt   ZCacheProxyConnection.connect  s    

jj3377	4H**77;;HdKKZZ2266z4H
66::9dKJ!3!"TUU":.
#K0 333
,D,DEJ!{  Kr/   c                :    V P                   P                  4        R # rY   )r  ru   rh   ri   r8   ru   ZCacheProxyConnection.on_connect  s    

r/   c                s    V P                   ;_uu_ 4        V P                  P                  4        R R R 4       V P                  P                  ! V!   R #   + '       g   i     L,; irY   )r  r  flushr  rx   rv   rw   r8   rx   ZCacheProxyConnection.disconnect  s>    KK 

t$ s   AA$	c                r  rY   )r  ry   rh   ri   r8   ry   Z!CacheProxyConnection.check_health#  s    

!r/   Tc                r  rY   )r  r|   rz   r]   r8   r|   Z(CacheProxyConnection.send_packed_command&  s     	

&&w/r/   c                s   V P                  4        V P                  ;_uu_ 4        V P                  P                  \	        V^ ,          RR7      4      '       g/   RV n        V P                  P                  ! V/ VB   RRR4       R#  RRR4       VP                  R4      f   \        R4      h\	        V^ ,          \        VP                  R4      4      R7      V n        V P                  ;_uu_ 4        V P                  P                  V P
                  4      '       d   V P                  P                  V P
                  4      pVP                  V P                  8w  d]   V P                  ;_uu_ 4        VP                  P                  4       '       d   VP                  P                  RR7       K>   RRR4        RRR4       R# V P                  P                  \!        V P
                  V P"                  \$        P&                  V P                  R7      4       RRR4       V P                  P                  ! V/ VB  R#   + '       g   i     EL; i  + '       g   i     L; i  + '       g   i     LU; i)	r    )r{   Z
redis_keysNkeyszCannot create cache key.Tr   )Z	cache_keycache_valuestatusconnection_refrL   )_process_pending_invalidationsr  r  Zis_cachabler   r  r  r   r   r   r?   r  r  r   r   setr   DUMMY_CACHE_VALUEr   IN_PROGRESS)rG   r3   r~   Zentrys   &*, r8   r   Z!CacheProxyConnection.send_command+  s   ++- ;;**8DGPR+STT26/

''88  U  ::f%788 +3Gfjj.@(A+
'  {{t>>??(G(GH''4::5#22;;==!00>>D>Q > )    KKOO"== $ 6 6+77#'::	! 6 	

00W 0 ) s>   AI 3B I'3 I	I	3	I'AI' I	I$I''I7	c                8    V P                   P                  V4      # rY   )r  r   r   rn   r8   r   ZCacheProxyConnection.can_read[  s    zz""7++r/   Fr   r   c               s   V P                   ;_uu_ 4        V P                  e   V P                  P                  V P                  4      e   V P                  P                  V P                  4      P                  \
        P                  8w  dN   \        P                  ! V P                  P                  V P                  4      P                  4      uuR R R 4       # R R R 4       V P                  P                  VVVR7      pV P                   ;_uu_ 4        V P                  f   VuuR R R 4       # Vf3   V P                  P                  V P                  .4       VuuR R R 4       # V P                  P                  V P                  4      pVe7   \
        P                  Vn        WEn	        V P                  P                  V4       R R R 4       V#   + '       g   i     L; i  + '       g   i     T# ; i)N)r   r   r   )r  r  r  r   r  r   r   r   r   r  r  r   Zdelete_by_cache_keysZVALIDr  )rG   r   r   r   r   Zcache_entrys   &&$$  r8   r   Z"CacheProxyConnection.read_response^  sy     //;KKOOD$C$CDPKKOOD$C$CDKK#//0 }}KKOOD$C$CDPP  ::++- 3% , 
 ..6 
 00$2Q2Q1RS  ++//$*I*IJK &%5%;%;"*2',! $ I $ $ s%   B:GG!/+G!%AG!G	!G2	c                r   rY   )r  rD   rv   rw   r8   rD   Z!CacheProxyConnection.pack_command  s    zz&&--r/   c                r!  rY   )r  r   r   rn   r8   r   Z"CacheProxyConnection.pack_commands  s    zz''11r/   c                r   r   r   r4   r7   r8   r9   r    s/     - -E$ue|*<d38n*L$M -r/   c                s.    V P                   P                  # rY   )r  r   rh   ri   r8   r   Z'CacheProxyConnection.handshake_metadata  s    zz,,,r/   c                r  rY   )r  r   rh   ri   r8   r   ZCacheProxyConnection._connect  s    

r/   c                r  rY   )r  r   rh   ri   r8   r   Z CacheProxyConnection._host_error  s    

 r/   c                $   < V ^8  d   QhRS[ RR/# )r2   r  rX   N)rf   r4   r7   r8   r9   r    s      S S.A Sd Sr/   c                s    VP                  R RR4       VP                  4        VP                  P                  V P                  4       R# )r   ZTRACKINGZONN)r   r   r   Zset_invalidation_push_handler_on_invalidation_callback)rG   r  rn   r8   r  Z.CacheProxyConnection._enable_tracking_callback  s8    (J52243Q3QRr/   c                sn    V P                  4       '       d   V P                  P                  R R7       K4  R# )Tr  N)r   r  r   rh   ri   r8   r  Z3CacheProxyConnection._process_pending_invalidations  s'    mmooJJ$$$$7 r/   c                sf   < V ^8  d   QhRS[ S[S[S[S[ S[,          ,          3,          ,          /# )r2   data)r
   r   r>   r   r   r4   r7   r8   r9   r    s,     : :d5htE{>S9S3T.U :r/   c                s    V P                   ;_uu_ 4        V^,          f   V P                  P                  4        M"V P                  P                  V^,          4       RRR4       R#   + '       g   i     R# ; i)r<   N)r  r  r  Zdelete_by_redis_keys)rG   r$  rn   r8   r#  Z.CacheProxyConnection._on_invalidation_callback  sL    Aw!!#00a9 s   A	A((A9	)
r  r  r  r  r  r  r   r   r   r   Nr   r   r   )rM   rN   rO   rP   r  r  r  r^   rj   ro   rp   rs   rt   ru   rx   ry   r|   r   r   r   rD   r   r   r   r   r   r  r  r#  rQ   rR   rS   rT   r8   r  r    s     !!G G$(79,. %
"0
.1`,'=A'PU'R.2 - -!S S
8: :r/   r  c                   sL   a a ] tR tRt oRtRV 3R lltV 3R ltR tRtVt	V ;t
# )SSLConnectioni  zManages SSL connections to and from the Redis server(s).
This class extends the Connection class, adding SSL functionality, and making
use of ssl.SSLContext (https://docs.python.org/3/library/ssl.html#ssl.SSLContext)
c                s  < \         '       g   \        R4      hWn        W n        Vf   \        P
                  pMf\        V\        4      '       dQ   R\        P
                  R\        P                  R\        P                  /pVV9  d   \        RV 24      hVV,          pW0n
        W@n        WPn        Wpn        W`n        Wn        Wn        Wn        Wn        Wn        Wn        Wn        \,        SV `\  ! R/ VB  R# )aq  Constructor

Args:
    ssl_keyfile: Path to an ssl private key. Defaults to None.
    ssl_certfile: Path to an ssl certificate. Defaults to None.
    ssl_cert_reqs: The string value for the SSLContext.verify_mode (none, optional, required). Defaults to "required".
    ssl_ca_certs: The path to a file of concatenated CA certificates in PEM format. Defaults to None.
    ssl_ca_data: Either an ASCII string of one or more PEM-encoded certificates or a bytes-like object of DER-encoded certificates.
    ssl_check_hostname: If set, match the hostname during the SSL handshake. Defaults to False.
    ssl_ca_path: The path to a directory containing several CA certificates in PEM format. Defaults to None.
    ssl_password: Password for unlocking an encrypted private key. Defaults to None.

    ssl_validate_ocsp: If set, perform a full ocsp validation (i.e not a stapled verification)
    ssl_validate_ocsp_stapled: If set, perform a validation on a stapled ocsp response
    ssl_ocsp_context: A fully initialized OpenSSL.SSL.Context object to be used in verifying the ssl_ocsp_expected_cert
    ssl_ocsp_expected_cert: A PEM armoured string containing the expected certificate to be returned from the ocsp verification service.
    ssl_min_version: The lowest supported SSL version. It affects the supported SSL versions of the SSLContext. None leaves the default provided by ssl module.
    ssl_ciphers: A string listing the ciphers that are allowed to be used. Defaults to None, which means that the default ciphers are used. See https://docs.python.org/3/library/ssl.html#ssl.SSLContext.set_ciphers for more information.

Raises:
    RedisError
z$Python wasn't built with SSL supportNZnoneZoptionalrequiredz+Invalid SSL Certificate Requirements Flag: rL   )r)   r#   keyfilecertfilesslZ	CERT_NONEr=   r>   ZCERT_OPTIONALZCERT_REQUIRED	cert_reqsca_certsca_dataca_pathcheck_hostnamecertificate_passwordssl_validate_ocspssl_validate_ocsp_stapledssl_ocsp_contextssl_ocsp_expected_certssl_min_versionssl_ciphersr   r^   )rG   Zssl_keyfileZssl_certfileZssl_cert_reqsZssl_ca_certsZssl_ca_datassl_check_hostnameZssl_ca_pathZssl_passwordr0  r1  r2  r3  r4  r5  r~   Z	CERT_REQSr   s   &&&&&&&&&&&&&&&, r8   r^   ZSSLConnection.__init__  s    P }CDD"$ MMMs++C--C--I
 I- A-Q  &m4M&$""0$0!!2)B& 0&<#.&"6"r/   c                s   < \         SV `  4       p V P                  V4      #   \        \        3 d    TP                  4        h i ; i)z>
Wrap the socket with SSL support, handling potential errors.
)r   r   _wrap_socket_with_sslr   r#   r   )rG   r   r   s   & r8   r   ZSSLConnection._connect  sH     w!	--d33$ 	JJL	s	   " #Ac                s   \         P                  ! 4       pV P                  Vn        V P                  Vn        V P
                  '       g   V P                  '       d3   VP                  V P
                  V P                  V P                  R7       V P                  f   V P                  f   V P                  e3   VP                  V P                  V P                  V P                  R7       V P                  e   V P                  Vn        V P                  '       d   VP!                  V P                  4       V P"                  RJ d   \$        RJ d   \'        R4      hV P(                  '       d   V P"                  '       d   \'        R4      hVP+                  WP,                  R7      pV P(                  '       Ed.   ^ RIp^R	IHp V P4                  fg   VP6                  P9                  VP6                  P:                  4      pVP=                  V P
                  4       VP?                  V P                  4       MV P4                  pVPA                  WPPB                  4       VP6                  PE                  V\F        PF                  ! 4       4      pVPI                  4        VPK                  V P,                  V PL                  34       VPO                  4        VPQ                  4        V# V P"                  RJ d^   \$        '       dR   ^R
IH)p V! W0P,                  V PL                  V P                  4      p	V	PU                  4       '       d   V# \W        R4      hV# )z}
Wraps the socket with SSL support.

Args:
    sock: The plain socket to wrap with SSL.

Returns:
    An SSL wrapped socket.
)r(  r'  r   N)ZcafileZcapathZcadataTFzcryptography is not installed.zKEither an OCSP staple or pure OCSP connection must be validated - not both.)Zserver_hostname)ocsp_staple_verifier)OCSPVerifierzocsp validation error),r)  Zcreate_default_contextr.  r*  Zverify_moder(  r'  Zload_cert_chainr/  r+  r-  r,  Zload_verify_locationsr4  Zminimum_versionr5  Zset_ciphersr0  r'   r#   r1  Zwrap_socketr   OpenSSLZocspr8  r2  ZSSLZContextZSSLv23_METHODZuse_certificate_fileZuse_privatekey_fileZset_ocsp_client_callbackr3  r   r   Zrequest_ocsprt   r   Zdo_handshaker   r9  Zis_validr!   )
rG   r   ZcontextZsslsockr:  r8  Z
staple_ctxZconr9  Zos
   &&        r8   r7  Z#SSLConnection._wrap_socket_with_ssl  s    ,,.!%!4!4"nn===DLLL##22 $  MM%||'||'))}}T\\$,, *  +&*&:&:G# 0 01!!T).D.M=>>)))d.D.D.D 
 %%dII%F )))2 $$,$[[001J1JK
//>..t||<!22
//$&A&A
 ++((V]]_ECKKDII./LLNN !!T).D.D*WiiDMMJAzz||%&=>>r/   )r+  r,  r-  r*  r(  r/  r.  r'  r5  r4  r2  r3  r0  r1  )NNr&  NNFNNFFNNNN)rM   rN   rO   rP   r   r^   r   r7  rQ   rR   r  r  r  r8   r%  r%    s"     
F#P	M Mr/   r%  c                   r   )	UnixDomainSocketConnectioniR  z4Manages UDS communication to and from a Redis serverc                s@   < \         SV `  ! R/ VB  Wn        W n        R # r   )r   r^   pathr   )rG   r<  r   r~   r   s   &&&,r8   r^   Z#UnixDomainSocketConnection.__init__U  s    "6"	,r/   c                s    R V P                   3RV P                  3.pV P                  '       d   VP                  RV P                  34       V# )r<  r   r   )r<  r   r   rB   r   r   r8   rj   Z&UnixDomainSocketConnection.repr_piecesZ  sE    499%dgg7MM=$*:*:;<r/   c                sP   \         P                   ! \         P                  \         P                  4      pVP                  V P                  4        VP                  V P                  4       TP                  T P                  4       T#   \         d    TP                  4        h i ; i)z&Create a Unix domain socket connection)
r   ZAF_UNIXr   r   r   rt   r<  r   r   r   )rG   r   r   r8   r   Z#UnixDomainSocketConnection._connect`  sy    }}V^^V-?-?@334	LL#
 	++,  	JJL	s   B B%c                r   rY   )r<  rh   ri   r8   r   Z&UnixDomainSocketConnection._host_errorm  s    yyr/   )r<  r   ) Nr  r  r  r8   r;  r;  R  s!     :-
 r/   r;  c                 s    V e   V R8X  d   R # \        V \        4      '       d   V P                  4       \        9   d   R# \	        V 4      # )Nr=  F)r=   r>   ZupperFALSE_STRINGSr   )rJ   ri   r8   to_boolr?  t  s7    }%%++-="@;r/   r   r   r   r   r   r   max_connectionsr   r6  r   c                 s   V P                  R 4      '       g:   V P                  R4      '       g#   V P                  R4      '       g   \        R4      h\        V 4      p / p\        V P                  4      P                  4        Fa  w  r#V'       g   K  \        V4      ^ 8  g   K!  \        V^ ,          4      p\        P                  V4      pV'       d    V! V4      W&   K]  W1V&   Kc  	  V P                  '       d   \        V P                  4      VR&   V P                  '       d   \        V P                  4      VR&   V P                  R8X  d6   V P                  '       d   \        V P                  4      VR	&   \        VR
&   V# V P                   '       d   \        V P                   4      VR&   V P"                  '       d   \%        V P"                  4      VR&   V P                  '       d:   RV9  d3    \%        \        V P                  4      P'                  RR4      4      VR&   V P                  R8X  d
   \*        VR
&   V#   \        \        3 d    \        RT R24      hi ; i  \(        \        3 d     LSi ; i)zredis://z	rediss://zunix://zRRedis URL must specify one of the following schemes (redis://, rediss://, unix://)zInvalid value for 'z' in connection URL.r   r   Zunixr<  connection_classr   r   r   Z/r=  Zrediss)Z
startswithr   r   r   Zqueryr   rb   r   URL_QUERY_ARGUMENT_PARSERSr   rE   r   r   Zschemer<  r;  Zhostnamer   r   ZreplaceZAttributeErrorr%  )urlr~   ZnamerJ   r   r   r8   	parse_urlrD    s   z"">>+&&>>)$$5
 	

 3-CF		*0025SZ!^E!H%E/33D9FW#)%=FL  %t 3 |||$S\\2z
|||$S\\2z zzV888$SXX.F6N%?!"& M! <<<$S\\2F6N888 ]F6N 888F*"7388#4#<#<S"#EFt ::!)6F%&MC ":. W$':4&@T%UVVW6 #J/ s   
H;.1I ;!II32I3c                   s   a  ] tR tRt o Rt]R 4       t]RR3V 3R lR lltV 3R lR lt	R	 t
V 3R
 lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRV 3R lR lltV 3R lR ltV 3R lR ltRtV tR# ) ConnectionPooli  a  
Create a connection pool. ``If max_connections`` is set, then this
object raises :py:class:`~redis.exceptions.ConnectionError` when the pool's
limit is reached.

By default, TCP connections are created unless ``connection_class``
is specified. Use class:`.UnixDomainSocketConnection` for
unix sockets.

Any additional keyword arguments are passed to the constructor of
``connection_class``.
c                sp    \        V4      pRV9   d   VR,          VR&   VP                  V4       V ! R/ VB # )a1  
Return a connection pool configured from the given URL.

For example::

    redis://[[username]:[password]]@localhost:6379/0
    rediss://[[username]:[password]]@localhost:6379/0
    unix://[username@]/path/to/socket.sock?db=0[&password=password]

Three URL schemes are supported:

- `redis://` creates a TCP socket connection. See more at:
  <https://www.iana.org/assignments/uri-schemes/prov/redis>
- `rediss://` creates a SSL wrapped TCP socket connection. See more at:
  <https://www.iana.org/assignments/uri-schemes/prov/rediss>
- ``unix://``: creates a Unix Domain Socket connection.

The username, password, hostname, path and all querystring values
are passed through urllib.parse.unquote in order to replace any
percent-encoded values with their corresponding characters.

There are several ways to specify a database number. The first value
found will be used:

    1. A ``db`` querystring option, e.g. redis://localhost?db=0
    2. If using the redis:// or rediss:// schemes, the path argument
       of the url, e.g. redis://localhost/0
    3. A ``db`` keyword argument to this function.

If none of these options are specified, the default db=0 is used.

All querystring options are cast to their appropriate Python types.
Boolean arguments can be specified with string values "True"/"False"
or "Yes"/"No". Values that cannot be properly cast cause a
``ValueError`` to be raised. Once parsed, the querystring arguments
and keyword arguments are passed to the ``ConnectionPool``'s
class initializer. In the case of conflicting arguments, querystring
arguments always win.
rA  rL   )rD  update)ZclsrC  r~   Zurl_optionss   &&, r8   from_urlZConnectionPool.from_url  s?    R  n'.45G.HK*+k"}V}r/   Nc                sF   < V ^8  d   QhRS[ S[,          RS[ S[,          /# )r2   r@  cache_factory)r   r   r   r4   r7   r8   r9   ConnectionPool.__annotate__  s+     0 0 "#0   56	0r/   c                s>   T;'       g    Rp\        V\        4      '       d   V^ 8  d   \        R4      hWn        W@n        W n        RV n        W0n        VP                  R4      '       g   VP                  R4      '       d   VP                  R4      R	9  d   \        R4      hV P                  P                  R4      pVe)   \        V\        4      '       g   \        R4      hWPn        MeV P                  e!   V P                  P                  4       V n        M7\        V P                  P                  R4      4      P                  4       V n        VP                  RR4       VP                  RR4       \        P                  ! 4       V n        V P#                  4        R# )
r2   z,"max_connections" must be a positive integerNZcache_configr  r   z4Client caching is only supported with RESP version 3z#Cache must implement CacheInterfacel        )r   r   )r=   r   r   rA  connection_kwargsr@  r  _cache_factoryr   r#   r   Z	get_cacher   popr	  r
  
_fork_lockreset)rG   rA  r@  rH  rJ  r  s   &&&&, r8   r^   ZConnectionPool.__init__  sR    *22U/3//?Q3FKLL 0!2.
+  004E4I4I'4R4R $$Z0@ !WXX**..w7E !%88$%JKK"
&&2!%!4!4!>!>!@DJ!-..22>B"ik J 	gt,nd3 $..*

r/   c                s&   < V ^8  d   QhRS[ S[ 3/# r   r>   r4   r7   r8   r9   rI  4  s     
 
3* 
r/   c                s    R \        V 4      P                   R\        V 4      P                   R\        V P                  ! R/ V P
                  B 4       R2# )r   r   r   r   rL   )ZtyperN   rM   ZreprrA  rJ  rh   ri   r8   r   ZConnectionPool.__repr__4  sS    T
%%&aT
(;(;'<T**DT-C-CDEFbJ	
r/   c                s:    V P                   P                  RR4      # )z
Returns:
    The RESP protocol version, or ``None`` if the protocol is not specified,
    in which case the server default will be used.
r   N)rJ  r   rh   ri   r8   r   ZConnectionPool.get_protocol:  s     %%))*d;;r/   c                rV   rW   rL   r4   r7   r8   r9   rI  B  s      t r/   c                s    \         P                  ! 4       V n        ^ V n        . V n        \        4       V n        \        P                  ! 4       V n	        R# )r    N)
r	  r
  _lock_created_connections_available_connectionsr  _in_use_connectionsr   r   r   rh   ri   r8   rN  ZConnectionPool.resetB  s9    ^^%
$%!&(##&5  99;r/   c                rV   rW   rL   r4   r7   r8   r9   rI  S  s     -* -*4 -*r/   c                s   V P                   \        P                  ! 4       8w  d|   V P                  P	                  ^R7      pV'       g   \
        h V P                   \        P                  ! 4       8w  d   V P                  4        V P                  P                  4        R# R#   T P                  P                  4        i ; i)i   )r   N)r   r   r   rM  Zacquirer    rN  release)rG   Zacquiredr   r8   	_checkpidZConnectionPool._checkpidS  s    F 88ryy{"..q.9H***88ryy{*JJL'') # '')s   4B" "B>c                r"  )r2   command_namerX   r   rO  r4   r7   r8   r9   rI    s      3 \ r/   c                s   V P                  4        V P                  ;_uu_ 4         V P                  P                  4       pV P                  P                  V4       RRR4        XP                  4         VP                  4       '       d   V P                  f   \        R4      hV#   \         d    T P                  4       p Li ; i  + '       g   i     Lt; i  \        \        3 dF    TP                  4        TP                  4        TP                  4       '       d   \        R4      h T# i ; i  \         d    T P                  X4       h i ; i)zGet a connection from the poolNConnection has dataConnection not ready)rU  rP  rR  rL  Z
IndexErrormake_connectionrS  Zaddrt   r   r  r!   r   rx   r   rT  rG   rV  r  Zoptions
connection   &&*, r8   get_connectionZConnectionPool.get_connection  s+   ZZZ4!88<<>
 $$((4 	 
B&&((TZZ-?)*?@@ 3  4!113
4 Z" $W- B%%'""$&&(()*@AA ) B
  	 LL$		se   CB'C%D4 6C C 'CCCCC	AD1"D1-D4 0D11D4 4Ec                r1   r   )r   r4   r7   r8   r9   rI    s     
 
W 
r/   c                s    V P                   p\        VP                  RR4      VP                  RR4      VP                  RR4      R7      # )z,Return an encoder based on encoding settingsr   r   r   r   r   F)r   r   r   )rJ  r   r   )rG   r~   r   r8   get_encoderZConnectionPool.get_encoder  sF    ''ZZ
G4"JJ'8(C#ZZ(:EB
 	
r/   c                rV   )r2   rX   rf   rL   r4   r7   r8   r9   rI    s     ? ?!6 ?r/   c                sJ   V P                   V P                  8  d   \        R4      hV ;P                   ^,          un         V P                  e<   \	        V P
                  ! R/ V P                  B V P                  V P                  4      # V P
                  ! R/ V P                  B # )zCreate a new connectionzToo many connectionsrL   )rQ  r@  r!   r  r  rA  rJ  rP  rh   ri   r8   rY  ZConnectionPool.make_connection  s    $$(<(<<!"899!!Q&!::!'%%?(>(>?TZZ  $$>t'='=>>r/   c                "   < V ^8  d   QhRRRR/# )r2   r[  r   rX   NrL   r4   r7   r8   r9   rI    s      , 4 r/   c                s   V P                  4        V P                  ;_uu_ 4         V P                  P                  V4       V P                  V4      '       d   V P                  P                  V4       M4V ;P                  ^,          un        VP                  4         RRR4       R#  RRR4       R#   \         d     Li ; i  + '       g   i     R# ; i)z(Releases the connection back to the poolN)
rU  rP  rS  r   ZKeyErrorowns_connectionrR  rB   rQ  rx   rG   r[  rn   r8   rT  ZConnectionPool.release  s    ZZZ((//
; ##J//++22:>
 ))Q.)%%'! Z ? Z    ZZs5   CB4CAC4C?CCCC	c                s$   < V ^8  d   QhRRRS[ /# )r2   r[  r   rX   )r   r4   r7   r8   r9   rI    s     * *, *3 *r/   c                s4    VP                   V P                   8H  # rY   )r   ra  rn   r8   r`  ZConnectionPool.owns_connection  s    ~~))r/   c                r"  )r2   inuse_connectionsrX   N)r   r4   r7   r8   r9   rI    s     ( (D (D (r/   c                s$   V P                  4        V P                  ;_uu_ 4        V'       d"   \        V P                  V P                  4      pMV P                  pV F  pVP                  4        K  	  RRR4       R#   + '       g   i     R# ; i)z
Disconnects connections in the pool

If ``inuse_connections`` is True, disconnect connections that are
current in use, potentially by other threads. Otherwise only disconnect
connections that are idle in the pool.
N)rU  rP  r   rR  rS  rx   )rG   rb  Zconnectionsr[  s   &&  r8   rx   ZConnectionPool.disconnect  sd     	ZZZ #//1I1I #99)
%%' * ZZZs   AA>>B	c                rV   rW   rL   r4   r7   r8   r9   rI    s      t r/   c                r   )z-Close the pool, disconnecting all connectionsNr   rh   ri   r8   r   ZConnectionPool.close  r   r/   c                r_  )r2   r   r&   rX   NrL   r4   r7   r8   r9   rI    s      w 4 r/   c                s    V P                   P                  R V/4       V P                   F	  pWn        K  	  V P                   F	  pWn        K  	  R# )r   N)rJ  rF  rR  r   rS  )rG   r   r  r   r8   	set_retryZConnectionPool.set_retry  sE    %%w&67//DJ 0,,DJ -r/   )rR  rK  rQ  rM  rS  rP  r  rA  rJ  r@  r   r   )rM   rN   rO   rP   r   ZclassmethodrG  r   r^   r   r   rN  rU  r]  r^  rY  rT  r`  rx   r   rc  rQ   rR   rS   rT   r8   rE  rE    s      . .d $)-9=	0 0d
 
< "-* -*^ B
 
? ? ** *( ((  r/   rE  c                   s`   a a ] tR tRt oRt^2^]]3V 3R lltR tR t	R t
R tR tR	tVtV ;t# )
BlockingConnectionPooli  a  
Thread-safe blocking connection pool::

    >>> from redis.client import Redis
    >>> client = Redis(connection_pool=BlockingConnectionPool())

It performs the same function as the default
:py:class:`~redis.ConnectionPool` implementation, in that,
it maintains a pool of reusable connections that can be shared by
multiple redis clients (safely across threads if required).

The difference is that, in the event that a client tries to get a
connection from the pool when all of connections are in use, rather than
raising a :py:class:`~redis.ConnectionError` (as the default
:py:class:`~redis.ConnectionPool` implementation does), it
makes the client wait ("blocks") for a specified number of seconds until
a connection becomes available.

Use ``max_connections`` to increase / decrease the pool size::

    >>> pool = BlockingConnectionPool(max_connections=10)

Use ``timeout`` to tell it either how many seconds to wait for a connection
to become available, or to block forever:

    >>> # Block forever.
    >>> pool = BlockingConnectionPool(timeout=None)

    >>> # Raise a ``ConnectionError`` after five seconds if a connection is
    >>> # not available.
    >>> pool = BlockingConnectionPool(timeout=5)
c                sH   < W@n         W n        \        SV `  ! RR VRV/VB  R# )rA  r@  NrL   )queue_classr   r   r^   )rG   r@  r   rA  re  rJ  r   s   &&&&&,r8   r^   ZBlockingConnectionPool.__init__  s7     ' 	
-	
+	
  	
r/   c                s    V P                  V P                  4      V n          V P                  P                  R4       K    \         d     Mi ; i. T n        \        P                  ! 4       T n        R# )TN)	re  r@  pool
put_nowaitr   _connectionsr   r   r   rh   ri   r8   rN  ZBlockingConnectionPool.reset#  s_    $$T%9%9:			$$T* 
  99;s   A   AAc                s   V P                   e=   \        V P                  ! R/ V P                  B V P                   V P                  4      pMV P                  ! R/ V P                  B pV P
                  P                  V4       V# )zMake a fresh connection.rL   )r  r  rA  rJ  rP  rh  rB   ra  r   r8   rY  Z&BlockingConnectionPool.make_connection;  sn    ::!-%%?(>(>?TZZJ ..H1G1GHJ  ,r/   c                s2   V P                  4        Rp V P                  P                  RV P                  R7      pTf   T P                  4       p TP                  4         TP                  4       '       d   \        R4      h T#   \         d    \        R4      hi ; i  \
        \        3 dF    TP                  4        TP                  4        TP                  4       '       d   \        R4      h T# i ; i  \         d    T P                  T4       h i ; i)a  
Get a connection, blocking for ``self.timeout`` until a connection
is available from the pool.

If the connection returned is ``None`` then creates a new connection.
Because we use a last-in first-out queue, the existing connections
(having been returned to the pool after the initial ``None`` values
were added) will be returned before ``None`` values. This means we only
create new connections when we need to, i.e.: the actual number of
connections will only increase in response to demand.
NT)Zblockr   zNo connection available.rW  rX  )rU  rf  r   r   r   r!   rY  rt   r   r   rx   r   rT  rZ  r\  r8   r]  Z%BlockingConnectionPool.get_connectionF  s    	 
	>T4<<HJ --/J	 
B&&(()*?@@ ) =  	> ""<==	>( $W- B%%'""$&&(()*@AA ) B
  	LL$	sB   'B C8 !B 7B BAC5&C51C8 4C55C8 8Dc                s
   V P                  4        V P                  V4      '       g.   VP                  4        V P                  P	                  R4       R#  V P                  P	                  V4       R#   \
         d     R# i ; i)z)Releases the connection back to the pool.N)rU  r`  rx   rf  rg  r   ra  rn   r8   rT  ZBlockingConnectionPool.releasez  sm     	##J//
 !!#II  &	II  , 	 	s   A3 3BBc                sl    V P                  4        V P                   F  pVP                  4        K  	  R# )z(Disconnects all connections in the pool.N)rU  rh  rx   ra  r   r8   rx   Z!BlockingConnectionPool.disconnect  s(    ++J!!# ,r/   )rh  r   rf  re  r   )rM   rN   rO   rP   r   r   r   r^   rN  rY  r]  rT  rx   rQ   rR   r  r  r  r8   rd  rd    s=     F #
 0	2h*$ $r/   rd  c                s    V ^8  d   Qh/ ^ \         9   d+   \        \        \        \        \
        3,          ,          ;R&   # )r2   r   )__conditional_annotations__r   r   r   r   r   )r5   s   "r8   r9   r9      s,    x G FtE,nDEF Fy r/   )Z0ZFZFALSEZNZNO)]ri  r   r   r   r)  rF   r	  r   Zabcr   Z	itertoolsr   Zqueuer   r   r   r   Ztypingr   r   r	   r
   r   r   r   Zurllib.parser   r   r   Zredis.cacher   r   r   r   r   r   Z_parsersr   r   r   r   Zbackoffr   Zcredentialsr   r   Z
exceptionsr   r   r    r!   r"   r#   r$   r%   r   r&   Zutilsr'   r(   r)   r*   r+   r,   r-   r.   rC   ra   re   rc   r_   r   Zobjectr   r   r0   rU   rf   r   r   r  r%  r;  r>  r?  r   r   ZlistrB  rD  rE  rd  r9   )ri  rT   r8   <module>rj     s    	  
 
     ( (  C C C 4 4  J I  O	 	 	 	 	 	 
	 8 F"M M $0 0fB BJJ), J)ZC*# C*LE:. E:PfJ fR!3 > / 	#eedsS'u 6rk k\	b$^ b$r/   