
    j                        U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z' dd	l(m)Z) e)rd dl*Z*d d
l*m+Z+m,Z,m-Z- ndZ*dZ,dZ+dZ-ddl.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl(m6Z6m7Z7 ej8        dk    rd dl m9Z: nd dl:m9Z: d dl;m<Z<m=Z=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZF d dlGmHZHmIZI d dlJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZR d dlSmTZT d dlUmVZV d dlWmXZXmYZY ddlZm[Z[m\Z\m]Z]m^Z^m_Z_ dZ`dZadZbdZcdZd G d  d!eje                  Zfefjg        Zheee^e_e]f                  eid"<   eXre]Zjne^Zj G d# d$e          Zk G d% d&e          Zleekelf         Zm G d' d(          Zn G d) d*en          Zo G d+ d,eo          Zp G d- d.          Zq G d/ d0en          Zrd1Zsd2eet         fd3Zud4 Zv eewexexeueueweweuevevexd5          Zyeezed6e{f         f         eid7<    G d8 d9ed:;          Z|d<ezd2e|fd=Z} ed>d?@          Z~ G dA d?          Z G dB dCe          ZdS )D    N)abstractmethod)chain)MappingProxyType)AnyCallableIterableListMappingOptionalProtocolSetTupleType	TypedDictTypeVarUnion)ParseResultparse_qsunquoteurlparse   )DB_CLIENT_CONNECTION_POOL_NAMEDB_CLIENT_CONNECTION_STATEAttributeBuilderConnectionStateget_pool_name)SSL_AVAILABLE)
SSLContext
TLSVersionVerifyFlags)TokenInterface)
DriverInforesolve_driver_info)!AsyncAfterConnectionReleasedEventEventDispatcher)deprecated_argsformat_error_message)      r(   )timeout)record_connection_closedrecord_connection_countrecord_connection_create_timerecord_connection_wait_timerecord_error_count)Retry)	NoBackoff)DEFAULT_RESP_VERSION)CredentialProvider"UsernamePasswordCredentialProvider)AuthenticationError$AuthenticationWrongNumberOfArgsErrorConnectionError	DataErrorMaxConnectionsError
RedisErrorResponseErrorTimeoutError)CloseReason)
EncodableT)HIREDIS_AVAILABLEstr_if_bytes)
BaseParserEncoder_AsyncHiredisParser_AsyncRESP2Parser_AsyncRESP3Parser   *   $s   
   
    c                   "    e Zd Z e            ZdS )	_SentinelN)__name__
__module____qualname__objectsentinel rI   c/DATA/AppData/hermes/projects/honcho/.venv/lib/python3.11/site-packages/redis/asyncio/connection.pyrK   rK   d   s        vxxHHHrI   rK   DefaultParserc                       e Zd ZddZdS )ConnectCallbackProtocol
connectionAbstractConnectionc                     d S NrQ   selfrV   s     rR   __call__z ConnectCallbackProtocol.__call__s   s      rI   NrV   rW   rL   rM   rN   r\   rQ   rI   rR   rU   rU   r   s        ======rI   rU   c                       e Zd ZddZdS )AsyncConnectCallbackProtocolrV   rW   c                 
   K   d S rY   rQ   rZ   s     rR   r\   z%AsyncConnectCallbackProtocol.__call__w   s
        rI   Nr]   r^   rQ   rI   rR   r`   r`   v   s        CCCCCCrI   r`   c            1          e Zd ZdZdZ eddgd          ddddd	ed
dd	edddddddddeddddde	e
ef         dee
         dee         dee         dede	eef         de
de
dedee         dededee
         dee
         dee
         dee         dee
         dee         dee         d ee         d!ee         d"ee         d#ee         f.d$            Zefd%efd&Zd' Zd( Zed)             Ze d*             Z!d+ Z"d, Z#dee         d-dfd.Z$d/ Z%	 d[d1ed2efd3Z&d4 Z'd5 Z(d6 Z)ed7             Z*ed-e
fd8            Z+d9e,d-e
fd:Z-d; Z.d\d<Z/d]d1ed-dfd=Z0	 	 	 	 d^d>ed?ee1         d@ee         dAed-df
dBZ2dC Z3dD Z4dE Z5dFe6e7         d-dfdGZ8	 d]dFe	e7e
e6e7         f         d1ed-dfdHZ9dIedJed-dfdKZ:dL Z;	 	 d_d0d	dMdNedOee         dPedQee         fdRZ<dIe=d-e>e7         fdSZ?dTe6e6e=                  d-e>e7         fdUZ@dV ZAdW ZBdXeCfdYZDdZ ZEdS )`rW   z0Manages communication to and from a Redis server)dbusernameclient_namelib_namelib_versioncredential_providerpasswordsocket_timeoutsocket_connect_timeoutredis_connect_funcretry_on_timeoutretry_on_errorhealth_check_intervalnext_health_checklast_active_atencoderssl_contextprotocol_reader_writer_parser_connect_callbacks_buffer_cutoff_lock_socket_read_size__dict__rf   rg   zbUse 'driver_info' parameter instead. lib_name and lib_version will be removed in a future version.)args_to_warnreasonr   NFutf-8stricti   r   )rc   ri   rj   rk   rm   rn   encodingencoding_errorsdecode_responsesparser_classsocket_read_sizero   re   rf   rg   driver_inford   retryrl   encoder_classrh   rt   event_dispatcherrc   ri   rj   rk   rm   rn   r   r   r   r   r   ro   re   r   rd   r   rl   r   rh   rt   r   c                ~   |s|r|t          d          |t                      | _        n|| _        || _        || _        t          |||          | _        || _        || _        || _	        || _
        ||}|| _        || _        |t          u rg }|rX|                    t                     |                    t           j                   |                    t$          j                   || _        |s|rX|s"t)          t+                      d          | _        nt/          j        |          | _        | j                            |           n!t)          t+                      d          | _        || _        d| _         ||||	          | _        || _        d| _        d| _        || _         | !                    |
           g | _"        d| _#        d| _$        d| _%        	 tM          |          }|dk     s|d	k    rtO          d
          n/# tP          $ r
 tR          }Y ntT          $ r tO          d          w xY w|| _+        dS )ag  
        Initialize a new async Connection.

        Parameters
        ----------
        driver_info : DriverInfo, optional
            Driver metadata for CLIENT SETINFO. If provided, lib_name and lib_version
            are ignored. If not provided, a DriverInfo will be created from lib_name
            and lib_version (or defaults if those are also None).
        lib_name : str, optional
            **Deprecated.** Use driver_info instead. Library name for CLIENT SETINFO.
        lib_version : str, optional
            **Deprecated.** Use driver_info instead. Library version for CLIENT SETINFO.
        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'   r   ip  Fr   r(   zprotocol must be either 2 or 3zprotocol must be an integer),r8   r%   _event_dispatcherrc   re   r#   r   rh   ri   rd   rj   rk   rm   SENTINELappendr<   socketr*   asynciorn   r0   r1   r   copydeepcopyupdate_supported_errorsro   rp   rr   rl   ru   rv   r{   
set_parserrx   ry   _re_auth_token_should_reconnectintr7   	TypeErrorr2   
ValueErrorrt   )r[   rc   ri   rj   rk   rm   rn   r   r   r   r   r   ro   re   rf   rg   r   rd   r   rl   r   rh   rt   r   ps                            rR   __init__zAbstractConnection.__init__   s   \  	 	&9&E+   #%4%6%6D""%5D"& /{HkRR#6   ,!)%3"&<# 0X%%N 	8!!,///!!&.111!!'"6777, 		/N 		/ 2"9;;22

 "]511
J..~>>>>y{{A..DJ%:"(*$}X@PQQ"47;7;!1%%%NP"8<!&	HHA 1uuA%&FGGG   	% 	% 	%$AAA 	A 	A 	A!"?@@@	A
 s   H H3H3	_warningsc                     t          | dd           r[|                    d| t          |            	 t          j                     |                                  d S # t          $ r Y d S w xY wd S )Nrv   zunclosed Connection )source)getattrwarnResourceWarningr   get_running_loop_closeRuntimeError)r[   r   s     rR   __del__zAbstractConnection.__del__  s     4D)) 
	NN/t//    (***   
	 
	s   'A 
A*)A*c                 f    | j         r)| j                                          dx| _         | _        dS dS )zR
        Internal method to silently close the connection without waiting
        N)rv   closeru   r[   s    rR   r   zAbstractConnection._close  s>     < 	/L   *..DL4<<<	/ 	/rI   c                     d                     d |                                 D                       }d| j        j         d| j        j         d| dS )N,c              3   *   K   | ]\  }}| d | V  dS )=NrQ   ).0kvs      rR   	<genexpr>z.AbstractConnection.__repr__.<locals>.<genexpr>&  s0      HHTQjjQjjHHHHHHrI   <.(z)>)joinrepr_pieces	__class__rM   rL   )r[   	repr_argss     rR   __repr__zAbstractConnection.__repr__%  sY    HHHHT5E5E5G5GHHHII	V4>,VVt~/FVVVVVVrI   c                     d S rY   rQ   r   s    rR   r   zAbstractConnection.repr_pieces)      rI   c                 &    | j         d uo| j        d uS rY   )ru   rv   r   s    rR   is_connectedzAbstractConnection.is_connected-  s    |4'DDL,DDrI   c                 x    t          j        |          }|| j        vr| j                            |           dS dS )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
WeakMethodrx   r   )r[   callbackwms      rR   register_connect_callbackz,AbstractConnection.register_connect_callback1  sG     ))T,,,#**2..... -,rI   c                     	 | j                             t          j        |                     dS # t          $ r Y dS w xY w)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)rx   remover   r   r   )r[   r   s     rR   deregister_connect_callbackz.AbstractConnection.deregister_connect_callback=  sQ    	#**7+=h+G+GHHHHH 	 	 	DD	s   ,0 
>>returnc                 2     || j                   | _        dS )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{   rw   )r[   r   s     rR   r   zAbstractConnection.set_parserH  s     $|T5KLLLrI   c                 ^    K    j                              fd fdd           d{V  dS )z5Connects to the Redis server if not already connectedc                  2                          dd          S )NTF)check_healthretry_socket_connect)connect_check_healthr   s   rR   <lambda>z,AbstractConnection.connect.<locals>.<lambda>U  s!    D--! .   rI   c                 2                         | |          S N)errorfailure_count
disconnect)r   r   r[   s     rR   r   z,AbstractConnection.connect.<locals>.<lambda>X  s    = *9 * * rI   Twith_failure_countN)r   call_with_retryr   s   `rR   connectzAbstractConnection.connectP  s}       j((        $ ) 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rI   Tr   r   c                    	K    j         rd S d		 fd}	 |r' j                             fd|d           d {V  n                                  d {V  n=# t          j        $ r  t          j        t          j        f$ rj t          d          }t          t           dd           t           dd           t           dd           t           dd           |	d	
           d {V  |t          $ r}t                               |                    }t          t           dd           t           dd           t           dd           t           dd           |	d	
           d {V  |d }~wt          $ r}t          |          |d }~ww xY w	  j        s                     |           d {V  nIt	          j         j                  r                                 d {V n                                 n)# t$          $ r                                   d {V   w xY wd  j        D              _         j        D ]5} |            } |           }|rt+          j        |          r| d {V  6d S )Nr   c                 6    |                     | |          S r   r   )r   r   actual_retry_attemptsr[   s     rR   failure_callbackzAAbstractConnection.connect_check_health.<locals>.failure_callbackf  s    $1!??m?LLLrI   c                  ,                                      S rY   )_connectr   s   rR   r   z9AbstractConnection.connect_check_health.<locals>.<lambda>n  s    DMMOO rI   Tr   zTimeout connecting to serverhostportF)server_addressserver_portnetwork_peer_addressnetwork_peer_port
error_typeretry_attemptsis_internalr   c                 &    g | ]} |            |S rQ   rQ   )r   refs     rR   
<listcomp>z;AbstractConnection.connect_check_health.<locals>.<listcomp>  s#    "S"S"S3SSUU"S3"S"S"SrI   )r   r   r   r   r   CancelledErrorr   r*   r<   r/   r   OSErrorr7   _error_message	Exceptionrl   on_connect_check_healthiscoroutinefunctionr:   r   rx   inspectisawaitable)
r[   r   r   r   eexcr   r   taskr   s
   `        @rR   r   z'AbstractConnection.connect_check_health^  s       	F !	M 	M 	M 	M 	M 	M
$	0# &j00++++$'+ 1           mmoo%%%%%%%% 	 	 	 45 	 	 	;<<A$&tVT::#D&$77%,T64%@%@")$"="=4!          G 	 	 	 3 3A 6 677A$&tVT::#D&$77%,T64%@%@")$"="=4!          G 	0 	0 	0!#&&C/	0	* 	222MMMMMMMMMM
 243JKK7$11$7777777770066 	 	 	//#########	 #T"S$2I"S"S"S* 	 	CsuuH8D>>D +D11 






		 	s3   AA BF8A<E44FFFA-H &H.c                     d| _         d S )NTr   r   s    rR   mark_for_reconnectz%AbstractConnection.mark_for_reconnect  s    !%rI   c                     | j         S rY   r   r   s    rR   should_reconnectz#AbstractConnection.should_reconnect  s    %%rI   c                     d| _         d S )NFr   r   s    rR   reset_should_reconnectz)AbstractConnection.reset_should_reconnect  s    !&rI   c                 
   K   d S rY   rQ   r   s    rR   r   zAbstractConnection._connect  s      rI   c                     d S rY   rQ   r   s    rR   _host_errorzAbstractConnection._host_error  r   rI   	exceptionc                 F    t          |                                 |          S rY   )r'   r   )r[   r  s     rR   r   z!AbstractConnection._error_message  s    #D$4$4$6$6	BBBrI   c                     | j         S rY   )rt   r   s    rR   get_protocolzAbstractConnection.get_protocol  s
    }rI   c                 B   K   |                      d           d{V  dS )z=Initialize the connection, authenticate and select a databaseTr   N)r   r   s    rR   
on_connectzAbstractConnection.on_connect  s5      ***===========rI   c                 	  K   | j                             |            | j         }d }| j        s| j        s| j        r;| j        pt          | j        | j                  }|                                 d {V }|r%| j        dvrt          | j         t                    rE| 
                    t                     |j        | j         _        | j                             |            t          |          dk    r
d|d         g} | j        d| j        dg|R ddi d {V  |                                  d {V }|                    d	          t#          | j                  k    r:|                    d
          t#          | j                  k    rt%          d          nK|r | j        dg|R ddi d {V  	 |                                  d {V }nN# t&          $ rA |                     d|d         d           d {V  |                                  d {V }Y nw xY wt)          |          dk    rt+          d          n| j        dvrt          | j         t                    rE| 
                    t                     |j        | j         _        | j                             |            |                     d| j        |           d {V  |                                  d {V }| j        r^|                     dd| j        |           d {V  t)          |                                  d {V           dk    rt%          d          d}d}| j        r8| j        j        r,|                     ddd| j        j        |           d {V  d}| j        r8| j        j        r,|                     ddd| j        j        |           d {V  d}| j        r#|                     d| j        |           d {V  t7          t9          ||g                    D ]-}		 |                                  d {V  # t:          $ r Y *w xY w| j        r:t)          |                                  d {V           dk    rt%          d          d S d S )N)r   2r   defaultr   HELLOAUTHr   Fs   protoprotozInvalid RESP versionr   r   OKzInvalid Username or PasswordCLIENTSETNAMEzError setting client nameSETINFOzLIB-NAMETzLIB-VERSELECTzInvalid Database)rw   r  rh   rd   ri   r4   get_credentials_asyncrt   
isinstancerD   r   rE   EXCEPTION_CLASSESlensend_commandread_responsegetr   r7   r6   r@   r5   re   r   formatted_namerg   rc   rangesumr;   )
r[   r   parser	auth_argscred_providerresponseauth_responselib_name_sentlib_version_sent_s
             rR   r   z*AbstractConnection.on_connect_check_health  s3     %%%	# 	D 	D 	D( T5dmT]SS  ,AACCCCCCCCI  ,	2h66$,(9:: . 1222171I.''---9~~""&	!5	 $$#1:  IN         "//11111111H||H%%T]););;;A AT]##A$ A$ &&<===  	2#$#FKYKKKUKKKKKKKKK;&*&8&8&:&: : : : : : :7 ; ; ;
 ''	"E'RRRRRRRRR&*&8&8&:&: : : : : : :; M**d22)*HIII 3 ](**$,(9:: . 1222171I.''---##GT]#VVVVVVVVV!//11111111H  	C## )	 $          $"4"4"6"6666666774??%&ABBB   	! 0 ? 	!## /) $          !M 	$ 0 < 	$## ,) $           $ 7 	R##HdgL#QQQQQQQQQ sM+;<==>> 	 	A((**********     7 	:$"4"4"6"6666666774??%&8999	: 	:??s%   8G AHHP66
QQnowaitr   r   health_check_failedc           
        K   	 t          | j                  4 d{V  | j                                         |                                  | j        s	 ddd          d{V  dS 	 | j                                         |s| j                                         d{V  n# t          $ r Y nw xY wd| _
        d| _        n# d| _
        d| _        w xY w	 ddd          d{V  n# 1 d{V swxY w Y   n+# t          j        $ r t          d| j                   dw xY w|r|rt          j        }nt          j        }|t|| j                                        k    rWt%          t'          | dd          t'          | dd          t'          | dd          t'          | dd          ||           d{V  t)          ||           d{V  dS t)          t          j                   d{V  dS )z!Disconnects from the Redis serverNz#Timed out closing connection after r   r   )r   r   r   r   r   r   )close_reasonr   )r'  )async_timeoutrk   rw   on_disconnectr   r   rv   r   wait_closedr   ru   r   r<   r=   HEALTHCHECK_FAILEDERRORr   get_retriesr/   r   r+   APPLICATION_CLOSE)r[   r$  r   r   r%  r'  s         rR   r   zAbstractConnection.disconnect9  sl     	$T%@AA ( ( ( ( ( ( ( (**,,,++---( ( ( ( ( ( ( ( ( ( ( ( ( ( (
(L&&((( " 9"l66888888888   D $(DL#'DLL $(DL#'DL'''''!( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (" # 	 	 	Sd6QSS 	
  	" 1*=*0(]TZ=S=S=U=U-U-U(#*4#>#> 'fd ; ;)0vt)D)D&-dFD&A&A$#0          +)            
 +(:           sj   C: 6C(C: (:B#"C#
B0-C/B00C3C(CC(C: (
C22C: 5C26C: :(D"c                    K   |                      dd           d{V  t          |                                  d{V           dk    rt          d          dS )z Send PING, expect PONG in returnPINGFr   NPONGz#Bad response from PING health check)r  r@   r  r7   r   s    rR   
_send_pingzAbstractConnection._send_pingq  sy      U;;;;;;;;;d002222222233v==!"GHHH >=rI   c                 F   K   |                      ||d           d{V  dS )z Function to call when PING failsT)r   r   r%  Nr   )r[   r   r   s      rR   _ping_failedzAbstractConnection._ping_failedw  sP      oo}$  
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rI   c                    K   | j         r]t          j                                                    | j        k    r1| j                            | j        | j        d           d{V  dS dS dS )z3Check the health of the connection with a PING/PONGTr   N)	ro   r   r   timerp   r   r   r2  r4  r   s    rR   r   zAbstractConnection.check_health}  s       &	(**//11D4JJJ*,,!2t -           		 	JJrI   commandc                 |   K   | j                             |           | j                                          d {V  d S rY   )rv   
writelinesdrain)r[   r7  s     rR   _send_packed_commandz'AbstractConnection._send_packed_command  sH      (((l  """""""""""rI   c                   K   | j         s|                     d           d {V  |r|                                  d {V  	 t          |t                    r|                                }t          |t                    r|g}| j        r5t          j	        | 
                    |          | j                   d {V  d S | j                            |           | j                                         d {V  d S # t          j        $ r- |                     d           d {V  t          d          d t           $ rz}|                     d           d {V  t#          |j                  dk    rd|j        d         }}n|j        d         }|j        d         }t'          d	| d
| d          |d }~wt(          $ r |                     d           d {V   w xY w)NFr   Tr$  zTimeout writing to socketr   UNKNOWNr   zError z while writing to socket. r   )r   r   r   r  strencodebytesrj   r   wait_forr;  rv   r9  r:  r<   r   r   r  argsr7   BaseException)r[   r7  r   r   err_noerrmsgs         rR   send_packed_commandz&AbstractConnection.send_packed_command  s        	@+++????????? 	&##%%%%%%%%%	'3'' +!..**'5)) $")" +&--g668K           ''000l((***********# 	F 	F 	F///.........:;;E 		 		 		///.........16{{a!*AF1I!DDD6DDD   	 	 	
 ///.........	s!   A;C;  9C; ;AG?A5F44+GrC  kwargsc                 |   K   |                       | j        | |                    dd                     d{V  dS )z+Pack and send a command to the Redis serverr   Tr   N)rG  pack_commandr  )r[   rC  rH  s      rR   r  zAbstractConnection.send_command  sh      &&Dt$6::nd3S3S ' 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rI   c                    K   	 | j                                          d{V S # t          $ rO}|                     d           d{V  |                                 }t          d| d|j                   d}~ww xY w)z8Poll the socket to see if there's data that can be read.NTr=  Error while reading from z: )rw   can_read_destructiver   r   r   r7   rC  )r[   r   
host_errors      rR   rM  z'AbstractConnection.can_read_destructive  s      	V::<<<<<<<<< 	V 	V 	V///.........))++J!"Tj"T"TAF"T"TUUU	Vs   # 
A<A
A77A<)disconnect_on_errorpush_requestdisable_decodingr*   rO  rP  c                ~  K   ||n| j         }|                                 }	 |e| j        dv r\t          |          4 d{V  | j                            ||           d{V }ddd          d{V  n# 1 d{V swxY w Y   n|[t          |          4 d{V  | j                            |           d{V }ddd          d{V  n# 1 d{V swxY w Y   nM| j        dv r#| j                            ||           d{V }n!| j                            |           d{V }n# t          j        $ r6 |Y dS |r|                     d           d{V  t          d|           t          $ r=}|r|                     d           d{V  t          d| d	|j                   d}~wt          $ r  |r|                     d           d{V   w xY w| j        r4t          j                                                    | j        z   }	|	| _        t#          |t$                    r|d|S )
z0Read the response from a previously sent commandN)3r(   )rQ  rP  )rQ  Tr=  zTimeout reading from rL  z : )rj   r   rt   r(  rw   r  r   r<   r   r   r7   rC  rD  ro   r   r6  rp   r  r;   )
r[   rQ  r*   rO  rP  read_timeoutrN  r  r   	next_times
             rR   r  z AbstractConnection.read_response  sK      #*"5ww4;N%%''
%	'DMX,E,E(66        %)\%?%?)9 &@ & &            H                           )(66        %)\%?%?)9 &@ & &            H                           (**!%!;!;%5L "< " "       "&!;!;%5 "< " "       # 	E 	E 	E"tt" 3ooTo222222222CzCCDDD 	W 	W 	W" 3ooTo222222222!"Uj"U"UQV"U"UVVV 	 	 	 # 3ooTo222222222	 % 	/0227799D<VVI%.D"h.. 	%$sf    D5 #A8&D5 8
BD5 BD5 !"CD5 
CD5 "C#AD5 5G'	9G'8F::-G'c           	         g }t          |d         t                    rJ t          |d         t                    rEt          |d                                                                                   |dd         z   }n<d|d         v r2t          |d                                                   |dd         z   }t                              t          t          t          |                                                    t          f          }| j        }t          | j        j        |          D ]}t          |          }t          |          |k    s||k    st          |t                    ryt                              |t          t          |                                          t          f          }|                    |           |                    |           t          }t                              |t          t          |                                          t          |t          f          }	|                    |           |S )z2Pack a series of arguments into the Redis protocolr   r   N    )r  floatr?  tupler@  split	SYM_EMPTYr   SYM_STARr  SYM_CRLFry   maprr   
memoryview
SYM_DOLLARr   )r[   rC  outputbuffbuffer_cutoffarg
arg_lengths          rR   rJ  zAbstractConnection.pack_command  s    d1gu-----d1gs## 	5a))//1122T!""X=DDT!W__a))DH4D~~xSYY)>)>)@)@(KLL+t|*D11 	 	C SJD		M))--c:.. . !~~:s:'='='?'?J  d###c""" ~~"J..00  	 	 	drI   commandsc                    g }g }d}| j         }|D ]} | j        | D ]}t          |          }||k    s||k    st          |t                    r3|r-|                    t                              |                     d}g }||k    st          |t                    r|                    |           |                    |           ||z  }|r-|                    t                              |                     |S )z.Pack multiple commands into the Redis protocolr   )ry   rJ  r  r  r_  r   r[  r   )	r[   rf  ra  piecesbuffer_lengthrc  cmdchunkchunklens	            rR   pack_commandsz AbstractConnection.pack_commands+  s%     + 	. 	.C**C0 . .u::!M11-//!%44 0  >innV&<&<===$%MFm++z%/L/L+MM%((((MM%(((!X-MM!.$  	2MM)..00111rI   c                 <    t          | j        j                  dk    S )zCheck if the socket is emptyr   )r  ru   _bufferr   s    rR   _socket_is_emptyz#AbstractConnection._socket_is_emptyI  s    4<'((A--rI   c                    K   |                                  s2|                     d           d {V  |                                  0d S d S )NT)rP  )rp  r  r   s    rR   process_invalidation_messagesz0AbstractConnection.process_invalidation_messagesM  sm      '')) 	8$$$$777777777 '')) 	8 	8 	8 	8 	8rI   tokenc                     || _         d S rY   )r   )r[   rs  s     rR   set_re_auth_tokenz$AbstractConnection.set_re_auth_tokenQ  s    #rI   c                    K   | j         o|                     d| j                             d          | j                                                    d {V  |                                  d {V  d | _         d S d S Nr  oid)r   r  try_get	get_valuer  r   s    rR   re_authzAbstractConnection.re_authT  s      *###++E22#--//        
 $$&&&&&&&&&"&D +*rI   )TTr   NT)FNNF)FN)FrL   rM   rN   __doc__	__slots__r&   r   rS   rB   r   r?  r   r   rX  boollistrK   r   rA   r"   r0   ConnectCallbackTr3   r%   r   warningsr   r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   rD  r   r  r  r   r   r   r2  r4  r   r   rA  r;  rG  r  rM  r  r>   r	   rJ  rm  rp  rr  r!   ru  r{  rQ   rI   rR   rW   rW   }   sB       ::I: _ -0H    "&*.26!&19'!&)6 %'(%)"&%),0"&!%9='.<@"#6:3i i i #s(Oi 3-	i
 !i !)i i dIo.i i i i :&i i  %i c]i  3-!i" c]#i$ j)%i& 3-'i( )i* %%56+i, G}-i. &&89/i0 3-1i2 #?33i i i 
iV (0       / / /W W W   ^ E E XE
/ 
/ 
/	 	 	MtJ'7 MD M M M M
 
 
 GKK K K?CK K K KZ& & && & &' ' '   ^ S    ^C C# C C C C  > > > >q: q:$ q:$ q: q: q: q:j %)'+$)6 66 	"6  }	6
 "6 
6 6 6 6pI I I
 
 
  #(5/ #d # # # #
 QU' 'UC%89'IM'	' ' ' 'R
 
s 
t 
 
 
 
V V V "'#'8
 %)',8 8 88 %8
 "8 tn8 8 8 8t,* ,e , , , ,\hx
/C&D e    <. . .8 8 8$~ $ $ $ $' ' ' ' 'rI   rW   c                        e Zd ZdZddddddded	eeef         d
edee	eeee
f         f                  def
 fdZd Zde	fdZd ZdefdZ xZS )
Connectionz4Manages TCP communication to and from a Redis server	localhosti  FNr   )r   r   socket_keepalivesocket_keepalive_optionssocket_typer   r   r  r  r  c                    || _         t          |          | _        || _        |pi | _        || _         t                      j        di | d S NrQ   )r   r   r   r  r  r  superr   )r[   r   r   r  r  r  rH  r   s          rR   r   zConnection.__init__b  sY     	II	 0(@(FB%&""6"""""rI   c                     d| j         fd| j        fd| j        fg}| j        r|                    d| j        f           |S )Nr   r   rc   re   )r   r   rc   re   r   r[   rh  s     rR   r   zConnection.repr_piecess  sL    49%	':T47OL 	=MM=$*:;<<<rI   r   c                      | j         | j        dS )Nr   r   r  r   s    rR   _connection_argumentsz Connection._connection_argumentsy  s    	49555rI   c                   K   t          | j                  4 d{V  t          j        di |                                  d{V \  }}ddd          d{V  n# 1 d{V swxY w Y   || _        || _        |j                            d          }|r|	                    t          j        t          j        d           	 | j        rk|	                    t          j        t          j        d           | j                                        D ](\  }}|	                    t          j        ||           'dS dS # t&          t(          f$ r |                                  w xY wdS )zCreate a TCP socket connectionNr   r   rQ   )r(  rk   r   open_connectionr  ru   rv   	transportget_extra_info
setsockoptr   IPPROTO_TCPTCP_NODELAYr  
SOL_SOCKETSO_KEEPALIVEr  itemsSOL_TCPr   r   r   )r[   readerwritersockr   r   s         rR   r   zConnection._connect|  s      !<== 	 	 	 	 	 	 	 	#*#: $ $,,..$ $      NFF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ..x88 	OOF.0BAFFF( >OOF$5v7JANNN $ = C C E E > >11====> >> > Y'    		 	s   -A
A&)A&A2D9 9'E c                 $    | j          d| j         S )N:r  r   s    rR   r   zConnection._host_error  s    )))di)))rI   )rL   rM   rN   r~  r?  r   r   r  r   r
   rA  r   r   r  r   r   __classcell__r   s   @rR   r  r  _  s       ::
   $!&NR# # # # CHo	#
 # #+73c5j8I3I+J"K# # # # # # #"  6w 6 6 6 6  0*S * * * * * * * *rI   r  c                       e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 ddee         dee         deeej        f         dee	d	                  d
ee	d	                  dee         dee         dee         de
dee         dee         dee         f fdZdef fdZed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Z xZS )SSLConnectionzManages 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)
    NrequiredTssl_keyfilessl_certfilessl_cert_reqsssl_include_verify_flagsssl.VerifyFlagsssl_exclude_verify_flagsssl_ca_certsssl_ca_datassl_ca_pathssl_check_hostnamessl_min_versionssl_ciphersssl_passwordc                     t           st          d          t          |||||||||	|
||          | _         t	                      j        di | d S )N$Python wasn't built with SSL support)keyfilecertfile	cert_reqsinclude_verify_flagsexclude_verify_flagsca_certsca_dataca_pathcheck_hostnamemin_versionciphersri   rQ   )r   r:   RedisSSLContextrs   r  r   )r[   r  r  r  r  r  r  r  r  r  r  r  r  rH  r   s                 rR   r   zSSLConnection.__init__  s}       	ECDDD,;!#!9!9!-'!-
 -
 -
 	""6"""""rI   r   c                     t                                                      }| j                                        |d<   |S )Nssl)r  r  rs   r  )r[   rH  r   s     rR   r  z#SSLConnection._connection_arguments  s5    ..00(,,..urI   c                     | j         j        S rY   )rs   r  r   s    rR   r  zSSLConnection.keyfile      ''rI   c                     | j         j        S rY   )rs   r  r   s    rR   r  zSSLConnection.certfile      ((rI   c                     | j         j        S rY   )rs   r  r   s    rR   r  zSSLConnection.cert_reqs  s    ))rI   c                     | j         j        S rY   )rs   r  r   s    rR   r  z"SSLConnection.include_verify_flags      44rI   c                     | j         j        S rY   )rs   r  r   s    rR   r  z"SSLConnection.exclude_verify_flags  r  rI   c                     | j         j        S rY   )rs   r  r   s    rR   r  zSSLConnection.ca_certs  r  rI   c                     | j         j        S rY   )rs   r  r   s    rR   r  zSSLConnection.ca_data  r  rI   c                     | j         j        S rY   )rs   r  r   s    rR   r  zSSLConnection.check_hostname  s    ..rI   c                     | j         j        S rY   )rs   r  r   s    rR   r  zSSLConnection.min_version  s    ++rI   )NNr  NNNNNTNNN)rL   rM   rN   r~  r   r?  r   r  
VerifyModer	   r  r   r   r
   r  r  r  r  r  r  r  r  r  r  r  r  r  s   @rR   r  r    sD         &*&*4>FJFJ&*%)%)#'04%)&*!# !#c]!# sm!# S#.01	!#
 #+40A+B"C!# #+40A+B"C!# sm!# c]!# c]!# !!# "*-!# c]!# sm!# !# !# !# !# !#Fw      
 ( ( X( ) ) X) * * X* 5 5 X5 5 5 X5 ) ) X) ( ( X( / / X/ , , X, , , , ,rI   r  c                   &   e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 ddee         dee         deeeej        f                  dee	d                  d	ee	d                  d
ee         dee         dee         de
dee         dee         dee         fdZdefdZdS )r  )r  r  r  r  r  r  r  r  contextr  r  r  ri   NFr  r  r  r  r  r  r  r  r  r  r  r  ri   c                    t           st          d          || _        || _        |t          j        }nWt          |t                    rBt          j        t          j        t          j	        d}||vrt          d|           ||         }|| _
        || _        || _        || _        || _        || _        | j
        t          j        k    r|	nd| _        |
| _        || _        || _        d | _        d S )Nr  )noneoptionalr  z+Invalid SSL Certificate Requirements Flag: F)r   r:   r  r  r  	CERT_NONEr  r?  CERT_OPTIONALCERT_REQUIREDr  r  r  r  r  r  r  r  r  ri   r  )r[   r  r  r  r  r  r  r  r  r  r  r  ri   	CERT_REQSs                 rR   r   zRedisSSLContext.__init__  s
     	ECDDD II	3'' 
	--- I
 	)) M)MM   "),I"$8!$8! "n==NN5 	 ' -1rI   r   c                 T   | j         st          j                    }| j        |_        | j        |_        | j        r| j        D ]}|xj        |z  c_        | j        r| j        D ]}|xj        | z  c_        | j	        s| j
        r'|                    | j	        | j
        | j                   | j        s| j        s| j        r'|                    | j        | j        | j                   | j        | j        |_        | j        |                    | j                   || _         | j         S )N)r  r  ri   )cafilecapathcadata)r  r  create_default_contextr  r  verify_moder  verify_flagsr  r  r  load_cert_chainri   r  r  r  load_verify_locationsr  minimum_versionr  set_ciphers)r[   r  flags      rR   r  zRedisSSLContext.get+  sc   | 	#022G%)%8G""&.G( 1 5 1 1D((D0(((( 2 5 2 2D((TE1(((}  ''!] L!] (   
 }   --=dl .    +*.*:'|'##DL111"DL|rI   )NNNNNNNNFNNN)rL   rM   rN   r  r   r?  r   r  r  r	   r  r   r   r   r  rQ   rI   rR   r  r    s4       I$ "&"&:>BFBF"&!%!%$,0!%"&-2 -2#-2 3--2 E#s~"567	-2
 't,='>?-2 't,='>?-2 3--2 #-2 #-2 -2 j)-2 #-2 3--2 -2 -2 -2^Z      rI   r  c                   x     e Zd ZdZdddef fdZdeeeeee	f         f                  fdZ
d Zdefd	Z xZS )
UnixDomainSocketConnectionz4Manages UDS communication to and from a Redis server pathr  c                H    || _          t                      j        di | d S r  )r  r  r   )r[   r  rH  r   s      rR   r   z#UnixDomainSocketConnection.__init__K  s-    	""6"""""rI   r   c                 p    d| j         fd| j        fg}| j        r|                    d| j        f           |S )Nr  rc   re   )r  rc   re   r   r  s     rR   r   z&UnixDomainSocketConnection.repr_piecesO  sC    49%dg7 	=MM=$*:;<<<rI   c                   K   t          | j                  4 d {V  t          j        | j                   d {V \  }}d d d           d {V  n# 1 d {V swxY w Y   || _        || _        |                                  d {V  d S )Nr  )r(  rk   r   open_unix_connectionr  ru   rv   r  )r[   r  r  s      rR   r   z#UnixDomainSocketConnection._connectU  sJ      !<== 	P 	P 	P 	P 	P 	P 	P 	P#*#?TY#O#O#OOOOOOONFF	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Poos   $A
A Ac                     | j         S rY   r  r   s    rR   r   z&UnixDomainSocketConnection._host_error\  s
    yrI   )rL   rM   rN   r~  r?  r   r   r   r   r   r   r   r   r  r  s   @rR   r  r  H  s        ::&( # # # # # # # # #XeCsCx,@&AB         S        rI   r  )0FFALSENNOr   c                     | | dk    rd S t          | t                    r|                                 t          v rdS t	          |           S )Nr  F)r  r?  upperFALSE_STRINGSr  )values    rR   to_boolr  c  sI    }t% %++--="@"@u;;rI   c                 T   |                      dd                               dd          }g }|                    d          D ]e}|                                }t          t          |          st          d|           |                    t          t          |                     f|S )N[r  ]r   zInvalid ssl verify flag: )replacerZ  striphasattrr    r   r   r   )r  verify_flags_strr  r  s       rR   parse_ssl_verify_flagsr  k  s     }}S"--55c2>>L &&s++ 8 8zz||{D)) 	A???@@@GK667777rI   )rc   rj   rk   r  rm   max_connectionsro   r  r  r  r*   .URL_QUERY_ARGUMENT_PARSERSc                   b    e Zd ZU eed<   eed<   ee         ed<   eed<   eed<   eed<   eed<   dS )	ConnectKwargsrd   ri   connection_classr   r   rc   r  N)rL   rM   rN   r?  __annotations__r   rW   r   rQ   rI   rR   r  r    sX         MMMMMM-....
III
IIIGGG
IIIIIrI   r  F)totalurlc                    t          |           }i }t          |j                                                  D ]\  }}|rt	          |          dk    rnt          |d                   }t                              |          }|r8	  ||          ||<   [# t          t          f$ r t          d| d          w xY w|||<   |j
        rt          |j
                  |d<   |j        rt          |j                  |d<   |j        dk    r)|j        rt          |j                  |d<   t          |d<   n|j        d	v r|j        rt          |j                  |d
<   |j        rt#          |j                  |d<   |j        rUd|vrQ	 t#          t          |j                                      dd                    |d<   n# t&          t          f$ r Y nw xY w|j        dk    r
t(          |d<   nd}t          d| d          |S )Nr   zInvalid value for 'z' in connection URL.rd   ri   unixr  r  )redisredissr   r   rc   /r  r  zredis://, rediss://, unix://z5Redis URL must specify one of the following schemes ())r   r   queryr  r  r   r  r  r   r   rd   ri   schemer  r  hostnamer   r   r  AttributeErrorr  )r
  parsedrH  name
value_listr  r  valid_schemess           rR   	parse_urlr    sW   "3--FF$V\2288:: 
% 
%j 		%#j//A--JqM**E/33D99F %W#)6%==F4LL!:. W W W$%U4%U%U%UVVVW  %t 6$V_55z 6$V_55z }; 	2$V[11F6N%?!""	-	-	-? 	6$V_55F6N; 	. --F6N ; 	4v--"76;#7#7#?#?R#H#HIIt"J/    =H$$)6F%& 7TMTTT
 
 	
 Ms   B%B88F; ;GG_CPConnectionPool)boundc                   j   e Zd ZdZedee         dedefd            Ze	dfdee
         dee         fd	Z eh d
          Zd Zd Zd'dZdefdZ edgdd          d(d            Zd Zd Zd Zde
fdZde
fdZd)defdZd Zd'dZd*d!Zd"e fd#Z!d$e"fd%Z#de$e%ee&f                  fd&Z'dS )+r  a  
    Create a connection pool. ``If max_connections`` is set, then this
    object raises :py:class:`~redis.ConnectionError` when the pool's
    limit is reached.

    By default, TCP connections are created unless ``connection_class``
    is specified. Use :py:class:`~redis.UnixDomainSocketConnection` for
    unix sockets.
    :py:class:`~redis.SSLConnection` can be used for SSL enabled connections.

    Any additional keyword arguments are passed to the constructor of
    ``connection_class``.
    clsr
  r   c                 Z    t          |          }|                    |            | di |S )a  
        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.
        rQ   )r  update)r  r
  rH  url_optionss       rR   from_urlzConnectionPool.from_url  s4    V  nnk"""s}}V}}rI   Nr  r  c                    |pd}t          |t                    r|dk     rt          d          || _        || _        || _        g | _        t                      | _        | j        	                    dt                    | _        t          j                    | _        | j        	                    dd           | _        | j        t!                      | _        d S d S )Nl        r   z,"max_connections" must be a positive integerr   r   )r  r   r   r  connection_kwargsr  _available_connectionsset_in_use_connectionsr  rB   r   r   Lockrz   r   r%   )r[   r  r  r$  s       rR   r   zConnectionPool.__init__
  s     *2U/3// 	M?Q3F3FKLLL 0!2.@B#<?EE !377QQ\^^
!%!7!;!;<NPT!U!U!)%4%6%6D""" *)rI   >   ri   rd   r  rh   c                      d                      fd j                                        D                       }d j        j         d j        j         d j        j         d j        j         d| dS )Nr   c                 :    g | ]\  }}| d |j         v rdn| S )r   z
<REDACTED>)SENSITIVE_REPR_KEYS)r   r   r   r[   s      rR   r   z+ConnectionPool.__repr__.<locals>.<listcomp>,  sL       Aq MMqD,D'D'D||!MM  rI   r   r   z(<r   z)>)>)r   r$  r  r   rM   rL   r  )r[   conn_kwargss   ` rR   r   zConnectionPool.__repr__*  s    hh    288::  
 
") " "DN,C " "&1" "484I4R" "" " "	
rI   c                    t          | d          rt          | d          rt          | j                  }t          | j                  }|dk    s|dk    rSt	          |           }ddlm} |dk    r ||t          j        |            |dk    r ||t          j	        |            g | _        t          j                    | _        d S )Nr%  r'  r   r,   	pool_nameconnection_statecounter)r   r  r%  r'  r   redis.observability.recorderr,   r   IDLEUSEDr   WeakSetr[   
idle_countin_use_countr0  sync_record_connection_counts        rR   resetzConnectionPool.reset7  s    4122 	w'8
 8
 	 T899Jt788LA~~!1!1)$//	      >>00"+)8)=!+   
  !##00"+)8)=!-    ')##*?#4#4   rI   c                    	 t          | d          rt          | d          sdS t          | j                  }t          | j                  }|dk    s|dk    rUt	          |           }ddlm} |dk    r ||t          j        |            |dk    r ||t          j	        |            dS dS dS # t          $ r Y dS w xY w)zCClean up connection pool and record metrics when garbage collected.r%  r'  Nr   r.  r/  )r   r  r%  r'  r   r3  r,   r   r4  r5  r   r7  s        rR   r   zConnectionPool.__del__V  s>   	4!9:: '+C C  T899Jt788LA~~!1!1)$//	      >>00"+)8)=!+   
  !##00"+)8)=!-      "2!1 $#  	 	 	DD	s    B1 BB1 1
B?>B?c                 J    | j         pt          | j                  | j        k     S )z;Return True if a connection can be retrieved from the pool.)r%  r  r'  r  r   s    rR   can_get_connectionz!ConnectionPool.can_get_connectionu  s+     ' D4+,,t/CC	
rI   *)Use get_connection() without args instead5.3.0r}   r~   versionc                 @  K   | j         4 d{V  t          | j                  t          | j                  z   }t	          j                    }|                                 }t          | j                  t          | j                  z   }||k    }ddd          d{V  n# 1 d{V swxY w Y   t          |           }	|r#t          |	t          j
        d           d{V  nDt          |	t          j        d           d{V  t          |	t          j
        d           d{V  	 |                     |           d{V  |r+t          | t	          j                    |z
             d{V  |S # t          $ r |                     |           d{V   w xY w)z(Get a connected connection from the poolNr   r/  r   connection_poolduration_seconds)rz   r  r%  r'  r6  	monotonicget_available_connectionr   r,   r   r5  r4  ensure_connectionr-   rD  release)
r[   command_namekeysoptionsconnections_beforestart_time_createdrV   connections_after
is_createdr0  s
             rR   get_connectionzConnectionPool.get_connection|  s      : 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@!$T%@!A!AC(E E " "&!1!16688J #D$? @ @3(D D ! +-??J		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ 		@ "$''	 	)#!0!5           *#!0!5         
 *#!0!5         	((444444444 3$(%)^%5%58J%J         
  	 	 	,,z*********	s   B B""
B,/B,,A	E6 6'Fc                    	 | j                                         }nQ# t          $ rD t          | j                  | j        k    rt          d          d|                                 }Y nw xY w| j                            |           |S )zCGet a connection from the pool, without making sure it is connectedzToo many connectionsN)	r%  pop
IndexErrorr  r'  r  r9   make_connectionaddrZ   s     rR   rI  z'ConnectionPool.get_available_connection  s    	0488::JJ 	0 	0 	04+,,0DDD)*@AAtK--//JJJ	0 	 $$Z000s    AA*)A*c                     | j         }|                     |                    dd          |                    dd          |                    dd                    S )z,Return an encoder based on encoding settingsr   r   r   r   r   F)r   r   r   )r$  r   r  )r[   rH  s     rR   get_encoderzConnectionPool.get_encoder  s\    '!!ZZ
G44"JJ'8(CC#ZZ(:EBB " 
 
 	
rI   c                 &     | j         di | j        S )z=Create a new connection.  Can be overridden by child classes.rQ   )r  r$  r   s    rR   rW  zConnectionPool.make_connection  s      %t$>>t'=>>>rI   rV   c                   K   |                                  d{V  	 |                                 d{V rt          d          ddS # t          t          t          f$ rb |                                 d{V  |                                  d{V  |                                 d{V rt          d          dY dS w xY w)z8Ensure that the connection object is connected and validNzConnection has datazConnection not ready)r   rM  r7   r<   r   r   rZ   s     rR   rJ  z ConnectionPool.ensure_connection  s,       """""""""
	H4466666666 G%&;<<$FG Gw7 	H 	H 	H'')))))))))$$&&&&&&&&&4466666666 H%&<==4GH H H	Hs   *A
 
A5CCc                   K   | j                             |           |                                r|                                 d{V  | j                            |           | j                            t          |                     d{V  t          |           }t          |t          j        d           d{V  t          |t          j        d           d{V  dS )z(Releases the connection back to the poolNr   r/  r   )r'  r   r   r   r%  r   r   dispatch_asyncr$   r   r,   r   r5  r4  )r[   rV   r0  s      rR   rK  zConnectionPool.release  sO      	 ''
333&&(( 	*'')))))))))#**:666$33-j99
 
 	
 	
 	
 	
 	
 	
 	

 "$''	%,1
 
 
 	
 	
 	
 	
 	
 	
 	

 &,1
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
rI   Tinuse_connectionsc                    K   |rt          | j        | j                  }n| j        }t          j        d |D             ddi d{V }t          d |D             d          }|r|dS )z
        Disconnects connections in the pool

        If ``inuse_connections`` is True, disconnect connections that are
        current in use, potentially by other tasks. Otherwise only disconnect
        connections that are idle in the pool.
        c              3   >   K   | ]}|                                 V  d S rY   r   )r   rV   s     rR   r   z,ConnectionPool.disconnect.<locals>.<genexpr>	  s.      DD*j##%%DDDDDDrI   return_exceptionsTNc              3   D   K   | ]}t          |t                    |V  d S rY   )r  rD  )r   rs     rR   r   z,ConnectionPool.disconnect.<locals>.<genexpr>  s1      DD!z!]'C'CDADDDDDDrI   )r   r%  r'  r   gathernext)r[   r_  connectionsrespr   s        rR   r   zConnectionPool.disconnect  s        	68=+T-E9 9KK 5K^DDDDD
"
 
 
 
 
 
 
 

 DDtDDDdKK 	I	 	rI   c                    K   | j         4 d{V  | j        D ]}|                                 	 ddd          d{V  dS # 1 d{V swxY w Y   dS )z<
        Mark all active connections for reconnect.
        N)rz   r'  r   )r[   conns     rR   'update_active_connections_for_reconnectz6ConnectionPool.update_active_connections_for_reconnect  s       : 	* 	* 	* 	* 	* 	* 	* 	*0 * *''))))*	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   A
AAc                 >   K   |                                   d{V  dS )z-Close the pool, disconnecting all connectionsNr   r   s    rR   aclosezConnectionPool.aclose  s.      oorI   r   r0   c                 J    | j         D ]	}||_        
| j        D ]	}||_        
d S rY   )r%  r   r'  )r[   r   rj  s      rR   	set_retryzConnectionPool.set_retry  sB    / 	 	DDJJ, 	 	DDJJ	 	rI   rs  c                 f   K    j         4 d {V   j        D ]Qj                            fd fd           d {V  j                            fd fd           d {V  R j        D ]                               	 d d d           d {V  d S # 1 d {V swxY w Y   d S )Nc                  |                          d                    d                                                    S rw  )r  ry  rz  )rj  rs  s   rR   r   z1ConnectionPool.re_auth_callback.<locals>.<lambda>'  s4    D--e 4 4eoo6G6G  rI   c                 .                         |           S rY   _mockr   r[   s    rR   r   z1ConnectionPool.re_auth_callback.<locals>.<lambda>*  s    $**U"3"3 rI   c                  ,                                      S rY   )r  )rj  s   rR   r   z1ConnectionPool.re_auth_callback.<locals>.<lambda>-  s    D..00 rI   c                 .                         |           S rY   rs  ru  s    rR   r   z1ConnectionPool.re_auth_callback.<locals>.<lambda>-  s    

5@Q@Q rI   )rz   r%  r   r   r'  ru  )r[   rs  rj  s   ``@rR   re_auth_callbackzConnectionPool.re_auth_callback#  s     : 	. 	. 	. 	. 	. 	. 	. 	.3 	 	j00     4333	         j0000002Q2Q2Q2Q          0 . .&&u----.	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   A9B  
B*-B*r   c                 
   K   dS )z
        Dummy functions, needs to be passed as error callback to retry object.
        :param error:
        :return:
        NrQ   )r[   r   s     rR   rt  zConnectionPool._mock2  s       	rI   c                 b   t          j                    }t          |           |t          <   |                                }|                                }t
          j        j        |t          <   t
          j	        j        |t          <   t          | j                  |ft          | j                  |fgS )zD
        Returns a connection count (both idle and in use).
        )r   build_base_attributesr   r   r   r   r4  r  r   r5  r  r%  r'  )r[   
attributesfree_connections_attributesin_use_connections_attributess       rR   get_connection_countz#ConnectionPool.get_connection_count:  s     &;==
5B45H5H
12&0oo&7&7#(2(9(9%  & 	$$>?  & 	&&@A
 ,--/JK)**,IJ
 	
rI   r|  rY   r}  )r   r0   r   N)(rL   rM   rN   r~  classmethodr   r  r?  r"  r  rW   r   r   r   	frozensetr+  r   r;  r   r  r>  r&   rS  rI  rZ  rW  rJ  rK  r   rk  rm  ro  r!   rx  r:   rt  r	   rY  dictr  rQ   rI   rR   r  r    sf         ,d3i ,c , , , , [,` 6@)-7 7127 "#7 7 7 7. $)	
 	
 	
 
 
 
5 5 5>   >
D 
 
 
 
 _U:  
2 2 2 
2h	 	 	
 
 
? ? ?H2D H H H H 
(: 
 
 
 
6 $    .* * *          .N . . . .    
d5d+;&< 
 
 
 
 
 
rI   c            
            e Zd ZdZddeej        fdedee	         de
e         de
ej                 f fdZ ed	gd
d          d fd	            Zdef fdZ xZS )BlockingConnectionPoola  
    A blocking connection pool::

        >>> from redis.asyncio import Redis, BlockingConnectionPool
        >>> client = Redis.from_pool(BlockingConnectionPool())

    It performs the same function as the default
    :py:class:`~redis.asyncio.ConnectionPool` implementation, in that,
    it maintains a pool of reusable connections that can be shared by
    multiple async redis clients.

    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.asyncio.ConnectionPool` implementation does), it
    blocks the current `Task` 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)
    2      r  r*   r  queue_classc                 ~     t                      j        d||d| t          j                    | _        || _        d S )N)r  r  rQ   )r  r   r   	Condition
_conditionr*   )r[   r  r*   r  r  r$  r   s         rR   r   zBlockingConnectionPool.__init__r  sW     	 	
-+	
 	
  	
 	
 	

 "+--rI   r?  r@  rA  rB  Nc                   K   t          j                    }	 | j        4 d{V  t          | j                  4 d{V  | j                            | j                   d{V  t          | j                  t          | j	                  z   }t          j                    }t                                                      }t          | j                  t          | j	                  z   }||k    }	ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   n'# t          j        $ r}
t          d          |
d}
~
ww xY w	 |                     |           d{V  |	r+t!          | t          j                    |z
             d{V  t#          t%          |           t          j                    |z
             d{V  |S # t&          $ r |                     |           d{V   w xY w)z@Gets a connection from the pool, blocking until one is availableNzNo connection available.rE  )r0  rG  )r6  rH  r  r(  r*   rB  r>  r  r%  r'  r  rI  r   r<   r7   rJ  r-   r.   r   rD  rK  )r[   rL  rM  rN  start_time_acquiredrO  rP  rV   rQ  rR  errr   s              rR   rS  z%BlockingConnectionPool.get_connection  s      #n..	G H H H H H H H H(66 H H H H H H H H/2243JKKKKKKKKK),T-H)I)IC0M M *& *.)9)9&!&!A!A!C!CJ(+D,G(H(H30L L )% "35G!GJH H H H H H H H H H H H H H H H H H H H H H H H H H HH H H H H H H H H H H H H H H H H H H H H H H H H H H # 	G 	G 	G!"<==3F	G	((444444444 3$(%)^%5%58J%J         
 .'--!%!1!14G!G         
  	 	 	,,z*********	sl   D8 D& B1D1D&
D	D&D	D&D8 &
D00D8 3D04D8 8EEE BG" "'H	rV   c                    K   | j         4 d{V  t                                          |           d{V  | j                                          ddd          d{V  dS # 1 d{V swxY w Y   dS )z)Releases the connection back to the pool.N)r  r  rK  notify)r[   rV   r   s     rR   rK  zBlockingConnectionPool.release  s	     ? 	% 	% 	% 	% 	% 	% 	% 	%''//*---------O""$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   AA%%
A/2A/rY   )rL   rM   rN   r~  r  r   	LifoQueuer   r   rX  r   rW   Queuer   r&   rS  rK  r  r  s   @rR   r  r  P  s        F  "#%5?+2+<  % 12	
 '-(       _U:  
( ( ( ( ( 
(T%(: % % % % % % % % % %rI   r  )r   r   enumr   r   sysr6  r  r   abcr   	itertoolsr   typesr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   urllib.parser   r   r   r   observability.attributesr   r   r   r   r   utilsr   r  r   r   r    
auth.tokenr!   r   r"   r#   eventr$   r%   r&   r'   version_infor*   r(  $redis.asyncio.observability.recorderr+   r,   r-   r.   r/   redis.asyncio.retryr0   redis.backoffr1   redis.connectionr2   redis.credentialsr3   r4   redis.exceptionsr5   r6   r7   r8   r9   r:   r;   r<   redis.observability.metricsr=   redis.typingr>   redis.utilsr?   r@   _parsersrA   rB   rC   rD   rE   r\  r`  r]  SYM_LFr[  EnumrK   rP   r   r  rS   rU   r`   r  rW   r  r  r  r  r  r  r  r  r   rX  r  r?  rO   r  r  r  r  r  rQ   rI   rR   <module>r     sT        



                " " " " " "                              B A A A A A A A A A A A              " ! ! ! ! ! JJJ77777777777
CJJK ' ' ' ' ' ' 9 9 9 9 9 9 9 9 F F F F F F F F 9 9 9 9 9 9 9 9 z!!0000000666666              & % % % % % # # # # # # 1 1 1 1 1 1 T T T T T T T T	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 4 3 3 3 3 3 # # # # # # 7 7 7 7 7 7 7 7              
		    	     E+->@SSTU U U U &'MM%M> > > > >h > > >D D D D D8 D D D 02NNO _' _' _' _' _' _' _' _'D6* 6* 6* 6* 6*# 6* 6* 6*rP, P, P, P, P,J P, P, P,fZ Z Z Z Z Z Z Zz    !3   0 /htn       CSBR"'##!$%$:$: C C GC#v+)>$>?   "    IU    23 2= 2 2 2 2j ge+,,,A
 A
 A
 A
 A
 A
 A
 A
He% e% e% e% e%^ e% e% e% e% e%rI   