� J�gs�� ��UddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZddlmZddlmZmZmZmZmZmZmZddlmZmZmZddlmZmZmZm Z m!Z!m"Z"d d l#m$Z$m%Z%m&Z&m'Z'd d l(m)Z)d d l*m+Z+m,Z,d d l-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5d dl6m7Z7d dl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@e:rddlAZAdZBdZCdZDdZEdZFeG��ZHeee&e'e%feId<e:re%ZJne&ZJGd�d��ZKGd�d��ZLGd�d��ZMGd�deM��ZNGd�deN��ZOGd �d!eM��ZPGd"�d#eO��ZQGd$�d%eN��ZRd&ZSd'�ZTeUeVeVeTeTeWeUeUeTeVd(� ZXd)�ZYGd*�d+��ZZGd,�d-eZ��Z[dS).�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_bytes�*�$s ��� DefaultParserc��eZdZdefd�ZdS)�HiredisRespSerializer�argsc�"�g}t|dt��rEt|d��������|dd�z}n<d|dvr2t|d�����|dd�z} |�t j|����nG#t$r:tj ��\}}}t|��� |���wxYw|S��2Pack a series of arguments into the Redis protocolrrN� ) � isinstance�str�tuple�encode�split�append�hiredis� pack_command� TypeError�sys�exc_infor%�with_traceback)�selfr9�output�_�value� tracebacks �`/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/redis/connection.py�packzHiredisRespSerializer.packEs����� �d�1�g�s� #� #� 5���a����)�)�/�/�1�1�2�2�T�!�"�"�X�=�D�D� �T�!�W�_�_���a������)�)�D����H�4�D� =� �M�M�'�.�t�4�4� 5� 5� 5� 5��� =� =� =�"%�,�.�.� �A�u�i��E�"�"�1�1�)�<�<� <� =����� s � 'C�AD N)�__name__� __module__� __qualname__r rP�r4rOr8r8Ds/�������$������r4r8c��eZdZdd�Zd�ZdS)�PythonRespSerializer�returnNc�"�||_||_dS�N)�_buffer_cutoffrA)rJ� buffer_cutoffrAs rO�__init__zPythonRespSerializer.__init__Ws��+����� � � r4c �\�g}t|dt��rEt|d��������|dd�z}n<d|dvr2t|d�����|dd�z}t �ttt|�������tf��}|j }t|j|��D�]}t|��}t|��|ks||kst|t��ryt �|tt|�����tf��}|�|��|�|��t}��t �|tt|�����t|tf��}�� |�|��|Sr;)r>r?r@rArB� SYM_EMPTY�join�SYM_STAR�len�SYM_CRLFrZ�map� memoryview� SYM_DOLLARrC)rJr9rK�buffr[�arg� arg_lengths rOrPzPythonRespSerializer.pack[s����� �d�1�g�s� #� #� 5���a����)�)�/�/�1�1�2�2�T�!�"�"�X�=�D�D� �T�!�W�_�_���a������)�)�D����H�4�D��~�~�x��S��Y�Y���)>�)>�)@�)@�(�K�L�L���+� ��t�{�D�)�)� � �C��S���J��D� � �M�)�)�� �-�-��c�:�.�.�.�!�~�~��:�s�:���'=�'=�'?�'?��J����� � �d�#�#�#�� � �c�"�"�"���� �~�~��"��J���.�.�0�0� �� � � � ��� � � �d����� r4�rWN)rQrRrSr\rPrTr4rOrVrVVs7����������+�+�+�+�+r4rVc��eZdZed���Zed���Zed���Zed���Zed���Zed���Z ed���Z ed���Z edd ���Z ed ���Z edd ���Ze dd dd�d���Zed���Zed���Zeedeeeefeeefffd�����ZdS)�ConnectionInterfacec��dSrYrT�rJs rO� repr_pieceszConnectionInterface.repr_pieces���� �r4c��dSrYrT�rJ�callbacks rO�register_connect_callbackz-ConnectionInterface.register_connect_callback�ror4c��dSrYrTrqs rO�deregister_connect_callbackz/ConnectionInterface.deregister_connect_callback�ror4c��dSrYrT�rJ� parser_classs rO� set_parserzConnectionInterface.set_parser�ror4c��dSrYrTrms rO�connectzConnectionInterface.connect�ror4c��dSrYrTrms rO� on_connectzConnectionInterface.on_connect�ror4c��dSrYrT�rJr9s rO� disconnectzConnectionInterface.disconnect�ror4c��dSrYrTrms rO� check_healthz ConnectionInterface.check_health�ror4Tc��dSrYrT�rJ�commandr�s rO�send_packed_commandz'ConnectionInterface.send_packed_command�ror4c��dSrYrT�rJr9�kwargss rO� send_commandz ConnectionInterface.send_command�ror4rc��dSrYrT�rJ�timeouts rO�can_readzConnectionInterface.can_read�ror4F��disconnect_on_error� push_requestc��dSrYrT)rJ�disable_decodingr�r�s rO� read_responsez!ConnectionInterface.read_response�s �� �r4c��dSrYrTrs rOrEz ConnectionInterface.pack_command�ror4c��dSrYrT�rJ�commandss rO� pack_commandsz!ConnectionInterface.pack_commands�ror4rWc��dSrYrTrms rO�handshake_metadataz&ConnectionInterface.handshake_metadata�s �� �r4N�T�r�F)rQrRrSrrnrsruryr{r}r�r�r�r�r�r�rEr��propertyrr �bytesr?r�rTr4rOrkrk�s�������� � ��^� �� � ��^� �� � ��^� �� � ��^� �� � ��^� �� � ��^� �� � ��^� �� � ��^� �� � � ��^� �� � ��^� �� � � ��^� ��� �!��  � � � ��^� �� � ��^� �� � ��^� ��� �E�$�u�e�|�*<�d�3��8�n�*L�$M� � � ��^��X� � � r4rkc*���eZdZdZdddddedddedddde��ddddd dfd ed ee d ee d ee de de de de dededee dee dee dee de e dfdeegdfdeedeedeegdff&d�Zd�Zed���Zd �Zd!�Zd"�Zd#�Zd$�Zd%�Zed&���Zed'���Zd(�Zd)�Zd*�Zd+�Zd,�Z d-�Z!d;d/�Z"d0�Z#d<d1�Z$ d=d.dd2�d3�Z%d4�Z&d5�Z'd6epe fd7�Z(e)d6e e*e+e+fe*e e fffd8���Z,e,j-d9e e*e+e+fe*e e fffd:���Z,dS)>�AbstractConnectionz0Manages communication to and from a Redis serverrNF�utf-8�strictizredis-pyr5�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�retry�redis_connect_func�credential_provider�protocol�command_packerc�X�|s|r|�td���tj��|_||_| |_||_||_||_||_ ||_ ||_ |�|}||_ ||_ |turg}|r|�t ��||_|s|rX|�"t%t'��d��|_nt+j|��|_|j�|��n!t%t'��d��|_| |_d|_||_t7||| ��|_d|_d|_| |_|� | ��g|_!d|_" tG|��}n/#tH$r tJ}YntL$rtOd���wxYw|dks|dkrtOd ���||_(n'#|dks|dkrtOd ���||_(wxYw|�)|��|_*dS) a2 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'rripzprotocol must be an integerr5�zprotocol must be either 2 or 3)+r%�os�getpid�pidr�r�r�r�r�r�r�r�r�r��SENTINELrCr(�retry_on_errorr)rr��copy�deepcopy�update_supported_errorsr��next_health_checkr�r�encoderr��_sock�_socket_read_sizery�_connect_callbacksrZ�intrF�DEFAULT_RESP_VERSION� ValueErrorr$r��_construct_command_packer�_command_packer)rJr�r�r�r�r�r�r�r�r�rxr�r�r�r�r�r�r�r�r�r�r��ps rOr\zAbstractConnection.__init__�st��> � �� �&9�&E��+��� � �9�;�;������&��� �� �&���#6�� � �� � �� �,��� !� )�%3� "�&<��#� 0��� �X� %� %��N� � 0� � !� !�,� /� /� /�,��� � /�N� /��}�"�9�;�;��2�2�� � �"�]�5�1�1�� � �J� .� .�~� >� >� >� >��y�{�{�A�.�.�D�J�%:��"�!"���"4����x��:J�K�K�� �"&����� �!1��� ��� �%�%�%�"$���"��� ��H� � �A�A��� %� %� %�$�A�A�A�� A� A� A�!�"?�@�@� @� A�����1�u�u��A���%�&F�G�G�G��D�M�M���1�u�u��A���%�&F�G�G�G��D�M� � � � �#�=�=�n�M�M����s*�F�G)�G�(G)�*G�G)�)$H c��d�d�|���D����}d|jj�d|jj�d|�d�S)N�,c�"�g|] \}}|�d|���� S)�=rT)�.0�k�vs rO� <listcomp>z/AbstractConnection.__repr__.<locals>.<listcomp>,s&��H�H�H�T�Q���j�j�Q�j�j�H�H�Hr4�<�.�(�)>)r_rn� __class__rRrQ)rJ� repr_argss rO�__repr__zAbstractConnection.__repr__+sY���H�H�H�H�T�5E�5E�5G�5G�H�H�H�I�I� �V�4�>�,�V�V�t�~�/F�V�V��V�V�V�Vr4c��dSrYrTrms rOrnzAbstractConnection.repr_pieces/ror4c�R� |���dS#t$rYdSwxYwrY)r�� Exceptionrms rO�__del__zAbstractConnection.__del__3s?�� � �O�O� � � � � ��� � � � �D�D� ���s �� &�&c�r�|�|Strt��St|j|jj��SrY)r+r8rVrZr�rA)rJ�packers rOr�z,AbstractConnection._construct_command_packer9s:�� � ��M� � R�(�*�*� *�'��(;�T�\�=P�Q�Q� Qr4c�x�tj|��}||jvr|j�|��dSdS)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�rC)rJrr�wms rOrsz,AbstractConnection.register_connect_callbackAsG��� �� )� )�� �T�,� ,� ,� � #� *� *�2� .� .� .� .� .� -� ,r4c�� |j�tj|����dS#t$rYdSwxYw)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�rqs rOruz.AbstractConnection.deregister_connect_callbackMsQ��  � � #� *� *�7�+=�h�+G�+G� H� H� H� H� H��� � � � �D�D� ���s �,0� >�>c�2�||j���|_dS)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��_parserrws rOryzAbstractConnection.set_parserXs�� $�|�T�5K�L�L�L�� � � r4c�*���jrdS �j��fd��fd���}nQ#tj$rt d���t $r'}t��|�����d}~wwxYw|�_ �j ��� ��n�� ���n##t$r�� ���wxYwd��j D���_ �j D]}|��}|r |����dS)z5Connects to the Redis server if not already connectedNc�,������SrY)�_connectrms�rO�<lambda>z,AbstractConnection.connect.<locals>.<lambda>fs���� � ���r4c�.����|��SrY�r�)�errorrJs �rOr�z,AbstractConnection.connect.<locals>.<lambda>fs���t���u�7M�7M�r4zTimeout connecting to serverc�&�g|]}|��� |��SrTrT)r��refs rOr�z.AbstractConnection.connect.<locals>.<listcomp>}s#��"S�"S�"S�3�S�S�U�U�"S�3�"S�"S�"Sr4)r�r��call_with_retry�socketr�r(�OSErrorr$�_error_messager�r}r&r�r�)rJ�sock�er�rrs` rOr{zAbstractConnection.connect`sp��� �:� � �F� :��:�-�-�'�'�'�'�)M�)M�)M�)M���D�D���~� ?� ?� ?��=�>�>� >�� :� :� :�!�$�"5�"5�a�"8�"8�9�9� 9����� :������ � ��&�.����!�!�!�!��'�'��-�-�-���� � � � �O�O� � � � � ����#T�"S�$�2I�"S�"S�"S����*� � �C��s�u�u�H�� �������� � s!�!.�'A<�"A7�7A<�1B9�9 Cc��dSrYrTrms rOr�zAbstractConnection._connect�ror4c��dSrYrTrms rO� _host_errorzAbstractConnection._host_error�ror4c�F�t|���|��SrY)r/r�)rJ� exceptions rOr�z!AbstractConnection._error_message�s��#�D�$4�$4�$6�$6� �B�B�Br4c���|j�|��|j}d}|js|js|jr5|jpt |j|j��}|���}|r�|jdvr�t|jt��rE|� t��|j |j_ |j�|��t|��dkr d|dg}|jd|jdg|�R�|���|_�n|r�|jdg|�Rdd i� |���}nB#t"$r5|�d|d d � ��|���}YnwxYwt%|��d krt'd ���n�|jdvr�t|jt��rE|� t��|j |j_ |j�|��|�d|j��|���|_|j�d��|jkr2|j�d��|jkrt+d���|jrP|�dd|j��t%|�����d krt+d��� |jr1|�ddd|j��|���n#t0$rYnwxYw |jr1|�ddd|j��|���n#t0$rYnwxYw|jrO|�d|j��t%|�����d krt+d���dSdS)z=Initialize the connection, authenticate and select a databaseN)r5�2r�defaultr�HELLO�AUTHr�F������r��OKzInvalid Username or Passwordsproto�protozInvalid RESP version�CLIENT�SETNAMEzError setting client name�SETINFOzLIB-NAMEzLIB-VER�SELECTzInvalid Database)r�r}r�r�r�r �get_credentialsr�r>rryr�EXCEPTION_CLASSESrar�r�r�r"r1r!�getr$r�r�r'r�r�)rJ�parser� auth_args� cred_provider� auth_responses rOr}zAbstractConnection.on_connect�s3�� � ����%�%�%����� � � #� 8�� � 8��� 8��(�T�5�d�m�T�]�S�S� �&�5�5�7�7�I� �- >���h�6�6��$�,� �5�5� .���� �-�-�-�17�1I�� �.�� �'�'��-�-�-��9�~�~��"�"�&� �!� �5� � �D� �g�t�}�f� I�y� I� I� I� I�&*�&8�&8�&:�&:�D� #� #� � >� �D� �f� E�y� E� E� E�u� E� E� E� 5� $� 2� 2� 4� 4� � ��7� 5� 5� 5� �!�!�&�)�B�-�e�!�L�L�L� $� 2� 2� 4� 4� � � �  5�����M�*�*�d�2�2�)�*H�I�I�I�3��]�(� *� *��$�,� �5�5� .���� �-�-�-�17�1I�� �.�� �'�'��-�-�-� � � �g�t�}� 5� 5� 5�&*�&8�&8�&:�&:�D� #��'�+�+�H�5�5���F�F��+�/�/��8�8�D�M�I�I�%�&<�=�=�=� � � C� � � �h� �4�3C� D� D� D��D�.�.�0�0�1�1�T�9�9�%�&A�B�B�B� ��}� %��!�!�(�I�z�4�=�Q�Q�Q��"�"�$�$�$���� � � � �D� ���� ��� %��!�!�(�I�y�$�BR�S�S�S��"�"�$�$�$���� � � � �D� ���� �7� :� � � �h��� 0� 0� 0��D�.�.�0�0�1�1�T�9�9�%�&8�9�9�9� :� :�9�9s6�9E�<F � F �<8L5�5 M�M�8M?�? N � N c�P�|j���|j}d|_|�dStj��|jkr8 |�tj��n#ttf$rYnwxYw |� ��dS#t$rYdSwxYw)z!Disconnects from the Redis serverN) r�� on_disconnectr�r�r�r��shutdownr�� SHUT_RDWRr�rF�close)rJr9� conn_socks rOr�zAbstractConnection.disconnect�s��� � �"�"�$�$�$��J� ��� � � � �F� �9�;�;�$�(� "� "� ��"�"�6�#3�4�4�4�4���Y�'� � � ��� ���� � �O�O� � � � � ��� � � � �D�D� ���s$� A)�)A=�<A=�B� B%�$B%c��|�dd���t|�����dkrtd���dS)z Send PING, expect PONG in return�PINGFr�PONGz#Bad response from PING health checkN)r�r1r�r$rms rO� _send_pingzAbstractConnection._send_ping�sQ�� ���&�u��5�5�5� ��*�*�,�,� -� -�� 7� 7�!�"G�H�H� H� 8� 7r4c�.�|���dS)z Function to call when PING failsNr�)rJr�s rO� _ping_failedzAbstractConnection._ping_failed��� �������r4c��|jr>t��|jkr)|j�|j|j��dSdSdS)z3Check the health of the connection with a PING/PONGN)r�rr�r�r�rrrms rOr�zAbstractConnection.check_healthsT�� � %� K�$�&�&�4�3I�*I�*I� �J� &� &�t���8I� J� J� J� J� J� K� K�*I�*Ir4Tc�r�|js|���|r|��� t|t��r|g}|D]}|j�|���dS#t j$r$|���td���t$rq}|���t|j ��dkrd|j d}}n|j d}|j d}td|�d|�d����d}~wt$r|����wxYw) z2Send an already packed command to the Redis serverzTimeout writing to socketr�UNKNOWNrzError z while writing to socket. r�N)r�r{r�r>r?�sendallr�r�r�r(r�rar9r$� BaseException)rJr�r��itemr��errno�errmsgs rOr�z&AbstractConnection.send_packed_command sk���z� � �L�L�N�N�N� � � � � � � � � ��'�3�'�'� $�"�)��� )� )��� �"�"�4�(�(�(�(� )� )���~� <� <� <� �O�O� � � ��:�;�;� ;�� W� W� W� �O�O� � � ��1�6�{�{�a��� )�1�6�!�9�v�����q� �������!�"U�5�"U�"U�F�"U�"U�"U�V�V� V������ � � � �O�O� � � � �  ���s�7A,�,;D6�'A,D�#D6c�v�|�|jj|�|�dd�����dS)z+Pack and send a command to the Redis serverr�TrN)r�r�rPr r�s rOr�zAbstractConnection.send_command*sJ�� � � � %�D� � %�t� ,����N�D�9�9� !� � � � � r4c��|j}|s|���|���} |j�|��S#t $r3}|���td|�d|j�����d}~wwxYw)z8Poll the socket to see if there's data that can be read.�Error while reading from z: N) r�r{r�r�r�r�r�r$r9)rJr�r�� host_errorr�s rOr�zAbstractConnection.can_read1s����z��� � �L�L�N�N�N��%�%�'�'� � V��<�(�(��1�1� 1��� V� V� V� �O�O� � � �!�"T�j�"T�"T�A�F�"T�"T�U�U� U����� V���s�A � B �.B�B r�c�r�|���} |jdvr$ts|j�||���}n|j�|���}n�#t j$r)|r|���td|�����t$r5}|r|���td|�d|j �����d}~wt$r|r|����wxYw|j rt��|j z|_t!|t"��r |�#~wxYw|S)z0Read the response from a previously sent command)�3r�)r�r�)r�zTimeout reading from r)z : N)r�r�r+r�r�r�r�r�r(r�r$r9r#r�rr�r>r')rJr�r�r�r*�responser�s rOr�z AbstractConnection.read_response?s����%�%�'�'� � ��}��(�(�1B�(��<�5�5�%5�L�6����� �<�5�5�GW�5�X�X�����~� E� E� E�"� "����!�!�!��C�z�C�C�D�D� D�� � � �"� "����!�!�!�!�G�J�G�G�q�v�G�G��� ������ � � �#� "����!�!�!� �  ���� � %� I�%)�V�V�d�.H�%H�D� "� �h� � .� .� � ����� � � � ��s%�AA�AC4�0C�%C4�/D1�1D4c� �|jj|�S)r<)r�rPrs rOrEzAbstractConnection.pack_commandms��(�t�#�(�$�/�/r4c��g}g}d}|j}|D]�}|jj|�D]�}t|��}||ks||kst |t ��r3|r-|�t�|����d}g}||kst |t ��r|�|����|�|��||z }����|r-|�t�|����|S)z.Pack multiple commands into the Redis protocolr) rZr�rPrar>rdrCr^r_) rJr�rK�pieces� buffer_lengthr[�cmd�chunk�chunklens rOr�z AbstractConnection.pack_commandsqs(������� ��+� �� .� .�C�2��-�2�C�8� .� .���u�:�:��!�M�1�1��-�/�/�!�%��4�4�0��>�� � �i�n�n�V�&<�&<�=�=�=�$%�M��F��m�+�+�z�%��/L�/L�+��M�M�%�(�(�(�(��M�M�%�(�(�(�!�X�-�M�M�! .�$ � 2� �M�M�)�.�.��0�0� 1� 1� 1�� r4rWc��|jSrY)r�rms rO� get_protocolzAbstractConnection.get_protocol�s ���}�r4c��|jSrY��_handshake_metadatarms rOr�z%AbstractConnection.handshake_metadata�s ���'�'r4rMc��||_dSrYr8)rJrMs rOr�z%AbstractConnection.handshake_metadata�s��#(�� � � r4r�r�r�).rQrRrS�__doc__r�r6r0r�r r?�float�boolrr r rr\r�rrnr�r�rsruryr{r�r�r�r}r�rrr�r�r�r�r�rEr�r6r�r r�r��setterrTr4rOr�r��s ������6�6��"&�*.�26�!&���'�!&�"� %�%&�%)�",�%4�_�%6�%6�"&�"&�;?�<@�"#�7;�-XN�XN� �XN��3�-�XN�!��� XN� !)��� XN� � XN��XN��XN��XN��XN� #�XN��c�]�XN��3�-�XN� �c�]�!XN�"�3�-�#XN�$�S�$�Y��%XN�&%�X�b�$�h�%7�8�'XN�(&�&8�9�)XN�*�3�-�+XN�,!��"�d�(�!3�4�-XN�XN�XN�XN�tW�W�W�� � ��^� ���� R�R�R� /� /� /� � � �M�M�M�!�!�!�F� � ��^� �� � ��^� �C�C�C�X:�X:�X:�t���(I�I�I� ���K�K�K� ����> � � � V� V� V� V� �,�!�� ,�,�,�,�,�\0�0�0����<�c�j�S������(�E�$�u�e�|�*<�d�3��8�n�*L�$M�(�(�(��X�(���)��d�5�%�<�.@�$�s�C�x�.�.P�(Q�)�)�)���)�)�)r4r�c�@��eZdZdZ d �fd� Zd�Zd �Zd �Z�xZS) � Connectionz4Manages TCP communication to and from a Redis server� localhost��FNrc ���||_t|��|_||_|pi|_||_t ��jdi|��dS�NrT)�hostr��port�socket_keepalive�socket_keepalive_options� socket_type�superr\)rJrErFrGrHrIr�r�s �rOr\zConnection.__init__�sY����� ���I�I�� � 0���(@�(F�B��%�&��������"�"�6�"�"�"�"�"r4c��d|jfd|jfd|jfg}|jr|�d|jf��|S)NrErFr�r�)rErFr�r�rC�rJr0s rOrnzConnection.repr_pieces�sL���4�9�%��� �':�T�4�7�O�L�� � � =� �M�M�=�$�*:�;� <� <� <�� r4c��d}tj|j|j|jtj��D�]<}|\}}}}}d} tj|||��}|�tjtjd��|j rk|�tj tj d��|j � ��D]&\} } |�tj| | ���'|�|j��|�|��|�|j��|cS#t$$r#} | }|�|���Yd} ~ ��6d} ~ wwxYw|�|�t%d���)zCreate a TCP socket connectionNrz)socket.getaddrinfo returned an empty list)r�� getaddrinforErFrI� SOCK_STREAM� setsockopt� IPPROTO_TCP� TCP_NODELAYrG� SOL_SOCKET� SO_KEEPALIVErH�items� settimeoutr�r{r�r�r) rJ�err�res�family�socktyper� canonname�socket_addressr�r�r�rLs rOr�zConnection._connect�s��� ���%� �I�t�y�$�"2�F�4F� � � !� !�C�BE� >�F�H�e�Y���D� !��}�V�X�u�=�=������ 2�F�4F��J�J�J��(�B��O�O�F�$5�v�7J�A�N�N�N� $� =� C� C� E� E�B�B���1�����(:�A�q�A�A�A�A����� ;�<�<�<�� � �^�,�,�,����� 3�4�4�4�� � � ��� !� !� !����#��J�J�L�L�L���������� !���� �?��I��A�B�B�Bs�C=E� E.� E)�)E.c�$�|j�d|j��S)N�:)rErFrms rOr�zConnection._host_error�s���)�)�)�d�i�)�)�)r4)rArBFNr� rQrRrSr;r\rnr�r�� __classcell__�r�s@rOr@r@�s��������:�:�� ��!%�� #�#�#�#�#�#� ��� 'C�'C�'C�R*�*�*�*�*�*�*r4r@c�J�eZdZdZdZdZdededej fd�Z d�Z d �Z d �Z d �Zd �Zd �Zd�Zd�Zd#d�Zd�Zd$d�Z d%ddd�d�Zd�Zd�Zedeeeefeeefffd���Zd�Zd�Z deddfd�Z!d �Z"d!e#eee$e#effd"�Z%dS)&�CacheProxyConnectionsfooz7.4.0�redis�conn�cache� pool_lockc�F�tj��|_||_|jj|_|jj|_|jj|_||_||_tj ��|_ d|_ d|_ |�|j��dSrY)r�r�r��_connr�rErF� _pool_lock�_cache� threading�Lock� _cache_lock�_current_command_cache_key�_current_optionsrs�_enable_tracking_callback)rJrerfrgs rOr\zCacheProxyConnection.__init__�s��� �9�;�;����� ��Z�%�� ��J�O�� ��J�O�� �#����� �$�>�+�+���*.��'� $��� �&�&�t�'E�F�F�F�F�Fr4c�4�|j���SrY)rirnrms rOrnz CacheProxyConnection.repr_pieces�s���z�%�%�'�'�'r4c�:�|j�|��dSrY)rirsrqs rOrsz.CacheProxyConnection.register_connect_callback�s�� � �,�,�X�6�6�6�6�6r4c�:�|j�|��dSrY)rirurqs rOruz0CacheProxyConnection.deregister_connect_callback�s�� � �.�.�x�8�8�8�8�8r4c�:�|j�|��dSrY)riryrws rOryzCacheProxyConnection.set_parsers�� � ���l�+�+�+�+�+r4c��|j���|jj�dd��}|� |jj�dd��}|jj�dd��}|� |jj�dd��}|�|�t d���t |��}t |��}||jkst||j��dkrt d���dS)Nsserver�serversversion�versionz0Cannot retrieve information about server versionrziTo maximize compatibility with all Redis products, client-side caching is supported by Redis 7.4 or later) rir{r�r r$r.�DEFAULT_SERVER_NAMEr-�MIN_ALLOWED_VERSION)rJ� server_name� server_vers rOr{zCacheProxyConnection.connects�� � �������j�3�7�7� �4�H�H� � � ��*�7�;�;�H�d�K�K�K��Z�2�6�6�z�4�H�H� � � ���6�:�:�9�d�K�K�J� � ��!3�!�"T�U�U� U�"�:�.�.� �#�K�0�0� � �4�3� 3� 3�� �D�,D�E�E��J�J�!�{��� �K�Jr4c�8�|j���dSrY)rir}rms rOr}zCacheProxyConnection.on_connects�� � �������r4c��|j5|j���ddd��n #1swxYwY|jj|�dSrY)rnrk�flushrir�rs rOr�zCacheProxyConnection.disconnects��� � � � � �K� � � � � � � � � � � � � � � � ���� � � � ��� ��t�$�$�$�$s �.�2�2c�8�|j���dSrY)rir�rms rOr�z!CacheProxyConnection.check_health#s�� � ���!�!�!�!�!r4Tc�:�|j�|��dSrY)rir�r�s rOr�z(CacheProxyConnection.send_packed_command&s �� � �&�&�w�/�/�/�/�/r4c �T�|���|j5|j�t |dd�����s'd|_|jj|i|�� ddd��dS ddd��n #1swxYwY|�d���td���t |dt|�d�������|_|j5|j�|j��r�|j�|j��}|j |jkrl|j 5|j � ��r4|j �d���|j � ���4ddd��n #1swxYwY ddd��dS|j�t!|j|jt$j|j�����ddd��n #1swxYwY|jj|i|��dS) NrrT)r�� redis_keys�keyszCannot create cache key.T�r�)� cache_key� cache_value�status�connection_ref)�_process_pending_invalidationsrnrk� is_cachablerrorir�r r�r@r�rjr�r��setr�DUMMY_CACHE_VALUEr� IN_PROGRESS)rJr9r��entrys rOr�z!CacheProxyConnection.send_command+s6�� �+�+�-�-�-� � � � ��;�*�*�8�D��G�PR�+S�+S�+S�T�T� �26��/�'�� �'��8��8�8�8��  � � � � � � � � � � � � � � � � � � � ���� � � � � �:�:�f� � � %��7�8�8� 8�+3���G��f�j�j��.@�.@�(A�(A�+ �+ �+ ��'�� � � ��{���t�>�?�?� �� ����(G�H�H���'�4�:�5�5���R�R�#�2�;�;�=�=�R�!�0�>�>�D�>�Q�Q�Q�$�2�;�;�=�=�R�R�R�R�R�R�R�R�R�R�R�R����R�R�R�R�� � � � � � � � � �K�O�O��"�=� $� 6�+�7�#'�:� ��� � � �! � � � � � � � � � � ���� � � � �6 �� ���0��0�0�0�0�0sQ�A B�B�B�2AH �AF"� H �"F& �&H �)F& �*H �;AH � H�Hrc�6�|j�|��SrY)rir�r�s rOr�zCacheProxyConnection.can_read[s���z�"�"�7�+�+�+r4Fr�c� �|j5|j��|j�|j���t|j�|j��jt jkrBtj|j�|j��j ��cddd��Sddd��n #1swxYwY|j � |||���}|j5|j�|cddd��S|�.|j� |jg��|cddd��S|j�|j��}|�2t j |_||_ |j�|��ddd��n #1swxYwY|S)N)r�r�r�)rnrorkr r�rr�r�r�r�rir��delete_by_cache_keys�VALIDr�)rJr�r�r�r-� cache_entrys rOr�z"CacheProxyConnection.read_response^sS��� � � ��/�;��K�O�O�D�$C�D�D�P��K�O�O�D�$C�D�D�K�#�/�0�0��}��K�O�O�D�$C�D�D�P��� � � � � � � � � � � � � � � � � � � ���� � � � ��:�+�+�-� 3�%�,� � �� � � -� -��.�6�� -� -� -� -� -� -� -� -� ��� �0�0�$�2Q�1R�S�S�S�� -� -� -� -� -� -� -� -��+�/�/�$�*I�J�J�K��&�%5�%;� �"�*2� �'�� ��� �,�,�,�! -� -� -� -� -� -� -� -� -� -� -���� -� -� -� -�$�s1�BB/�/B3�6B3� F�4#F�$AF�F� Fc� �|jj|�SrY)rirErs rOrEz!CacheProxyConnection.pack_command�s��&�t�z�&��-�-r4c�6�|j�|��SrY)rir�r�s rOr�z"CacheProxyConnection.pack_commands�s���z�'�'��1�1�1r4rWc��|jjSrY)rir�rms rOr�z'CacheProxyConnection.handshake_metadata�s ���z�,�,r4c�8�|j���dSrY)rir�rms rOr�zCacheProxyConnection._connect�s�� � �������r4c�8�|j���dSrY)rir�rms rOr�z CacheProxyConnection._host_error�s�� � ��� � � � � r4Nc��|�ddd��|���|j�|j��dS)Nr�TRACKING�ON)r�r�r��set_invalidation_push_handler�_on_invalidation_callback)rJres rOrqz.CacheProxyConnection._enable_tracking_callback�sK�� ���(�J��5�5�5� ������ � �2�2�4�3Q�R�R�R�R�Rr4c��|���r1|j�d���|����/dSdS)NTr�)r�rir�rms rOr�z3CacheProxyConnection._process_pending_invalidations�sQ���m�m�o�o� 8� �J� $� $�$� $� 7� 7� 7��m�m�o�o� 8� 8� 8� 8� 8r4�datac���|j5|d�|j���n |j�|d��ddd��dS#1swxYwYdS)Nr)rnrkr�delete_by_redis_keys)rJr�s rOr�z.CacheProxyConnection._on_invalidation_callback�s��� � � :� :��A�w��� �!�!�#�#�#�#�� �0�0��a��9�9�9�  :� :� :� :� :� :� :� :� :� :� :� :���� :� :� :� :� :� :s�AA�A�Ar�r�r�)&rQrRrSr�rzryrkrrlrmr\rnrsruryr{r}r�r�r�r�r�r�rEr�r�rr r�r?r�r�r�rqr�r r r�rTr4rOrcrc�s"��������!��!��G�!�G��G��>� G�G�G�G�$(�(�(�7�7�7�9�9�9�,�,�,����. � � �%�%�%� "�"�"�0�0�0�0� .1�.1�.1�`,�,�,�,� %�'�=A�PU�'�'�'�'�'�R.�.�.�2�2�2��-�E�$�u�e�|�*<�d�3��8�n�*L�$M�-�-�-��X�-����!�!�!�S�.A�S�d�S�S�S�S� 8�8�8�:�d�5��h�t�E�{�>S�9S�3T�.U�:�:�:�:�:�:r4rcc�P��eZdZdZ d�fd� Z�fd�Zd�Z�xZS) � SSLConnectionz�Manages 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�requiredFc ����tstd���||_||_|� tj}nWt |t��rBtjtjtj d�}||vrtd|�����||}||_ ||_ ||_ ||_ ||_||_| |_| |_| |_| |_| |_||_t-��jdi|��dS)aConstructor 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 supportN)�none�optionalr�z+Invalid SSL Certificate Requirements Flag: rT)r,r&�keyfile�certfile�ssl� CERT_NONEr>r?� CERT_OPTIONAL� 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_ciphersrJr\)rJ� ssl_keyfile� ssl_certfile� ssl_cert_reqs� ssl_ca_certs� ssl_ca_data�ssl_check_hostname� ssl_ca_path� ssl_passwordr�r�r�r�r�r�r�� CERT_REQSr�s �rOr\zSSLConnection.__init__�s���P� E��C�D�D� D�"�� �$�� � � ��M�M�M� � �s� +� +� 5�� ��-��-���I� �I�-�-� �Q�-�Q�Q����&�m�4�M�&���$�� �"�� �"�� �0���$0��!�!2���)B��&� 0���&<��#�.���&��������"�"�6�"�"�"�"�"r4c����t�����} |�|��S#ttf$r|����wxYw)zN Wrap the socket with SSL support, handling potential errors. )rJr��_wrap_socket_with_sslr�r&r)rJr�r�s �rOr�zSSLConnection._connect�sc����w�w���!�!�� ��-�-�d�3�3� 3����$� � � � �J�J�L�L�L� � ���s �8�'Ac�H�tj��}|j|_|j|_|js|jr'|�|j|j|j���|j �|j �|j �'|� |j |j |j ���|j � |j |_|jr|�|j��|jdurt$durt'd���|jr|jrt'd���|�||j���}|j�rd dl}d d lm}|j�Y|j�|jj��}|�|j��|�|j��n|j}|� ||j!��|j�"|tGj#����}|�$��|�%|j|j&f��|�'��|�(��|S|jdurOt$rHd d lm)}|||j|j&|j ��} | �*��r|StWd ���|S)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)�cafile�capath�cadataTFzcryptography is not installed.zKEither an OCSP staple or pure OCSP connection must be validated - not both.)�server_hostnamerr)�ocsp_staple_verifier)� OCSPVerifierzocsp validation error),r��create_default_contextr�r�� verify_moder�r��load_cert_chainr�r�r�r��load_verify_locationsr��minimum_versionr�� set_ciphersr�r*r&r�� wrap_socketrE�OpenSSL�ocspr�r��SSL�Context� SSLv23_METHOD�use_certificate_file�use_privatekey_file�set_ocsp_client_callbackr�r@r�� request_ocspr{rF� do_handshakerr��is_validr$) rJr��context�sslsockr�r�� staple_ctx�conr��os rOr�z#SSLConnection._wrap_socket_with_ssls����,�.�.��!%�!4���"�n��� �=� �D�L� � � #� #���� ��2� $� � � � �M� %��|�'��|�'� � )� )��}�T�\�$�,� *� � � � � � +�&*�&:�G� #� � � 2� � � �� 0� 1� 1� 1� � !�T� )� )�.D��.M�.M��=�>�>� >� � )� �d�.D� ����� � �%�%�d�D�I�%�F�F�� � )� � �N�N�N� 2� 2� 2� 2� 2� 2��$�,�$�[�0�0���1J�K�K� ��/�/�� �>�>�>��.�.�t�|�<�<�<�<�!�2� � � /� /�$�d�&A� � � � �+�(�(��V�]�_�_�E�E�C� � � � � � � �K�K���D�I�.� /� /� /� � � � � � � �L�L�N�N�N��N� � !�T� )� )�.D� )� *� *� *� *� *� *�� �W�d�i���D�M�J�J�A��z�z�|�|� ?���%�&=�>�>�>��r4)NNr�NNFNNFFNNNN)rQrRrSr;r\r�r�r`ras@rOr�r��s������������ ��� ����"'��#���F#�F#�F#�F#�F#�F#�P � � � � �M�M�M�M�M�M�Mr4r�c�6��eZdZdZd�fd� Zd�Zd�Zd�Z�xZS) �UnixDomainSocketConnectionz4Manages UDS communication to and from a Redis server�Nc �V��t��jdi|��||_||_dSrD)rJr\�pathr�)rJr�r�r�r�s �rOr\z#UnixDomainSocketConnection.__init__Us5��������"�"�6�"�"�"��� �,����r4c�p�d|jfd|jfg}|jr|�d|jf��|S)Nr�r�r�)r�r�r�rCrLs rOrnz&UnixDomainSocketConnection.repr_piecesZsC���4�9�%��d�g��7�� � � =� �M�M�=�$�*:�;� <� <� <�� r4c�>�tjtjtj��}|�|j�� |�|j��n##t$r|����wxYw|�|j ��|S)z&Create a Unix domain socket connection) r��AF_UNIXrOrVr�r{r�r�rr�)rJr�s rOr�z#UnixDomainSocketConnection._connect`s����}�V�^�V�-?�@�@�� ����3�4�4�4� � �L�L��� #� #� #� #��� � � � �J�J�L�L�L� � ���� ����+�,�,�,�� s �A � Bc��|jSrY)r�rms rOr�z&UnixDomainSocketConnection._host_errorms ���y�r4)r�Nr_ras@rOr�r�Rsp�������:�:�-�-�-�-�-�-� ��� � � �������r4r�)�0�F�FALSE�N�NOc��|�|dkrdSt|t��r|���tvrdSt |��S)Nr�F)r>r?�upper� FALSE_STRINGSr=)rMs rO�to_boolr�tsI�� �}��� � ��t��%�����%�+�+�-�-�=�"@�"@��u� ��;�;�r4) r�r�r�rGr�r��max_connectionsr�r�r�c�\�|�d��s9|�d��s$|�d��std���t|��}i}t|j�����D]�\}}|r�t |��dkrnt|d��}t� |��}|r8 ||��||<�[#ttf$rtd|�d����wxYw|||<��|j rt|j ��|d<|j rt|j ��|d <|j d kr)|jrt|j��|d <t|d <n�|jrt|j��|d <|jrt%|j��|d<|jrUd|vrQ t%t|j���dd����|d<n#t(tf$rYnwxYw|j dkr t*|d <|S)Nzredis://z rediss://zunix://zRRedis URL must specify one of the following schemes (redis://, rediss://, unix://)rzInvalid value for 'z' in connection URL.r�r��unixr��connection_classrErFr��/r��rediss)� startswithr�rr�queryrUrar�URL_QUERY_ARGUMENT_PARSERSr rFr�r��schemer�r��hostnamerFr��replace�AttributeErrorr�)�urlr��namerMrs rO� parse_urlr�su�� ���z�"�"� � �>�>�+� &� &� � �>�>�)� $� $� � � 5� � � � �3�-�-�C� �F��� �*�*�0�0�2�2� %� %� ��e� � %�S��Z�Z�!�^�^��E�!�H�%�%�E�/�3�3�D�9�9�F�� %�W�#)�6�%�=�=�F�4�L�L��!�:�.�W�W�W�$�%U�4�%U�%U�%U�V�V�V�W���� %��t� �� �|�3�$�S�\�2�2��z�� �|�3�$�S�\�2�2��z�� �z�V��� �8� /�$�S�X�.�.�F�6�N�%?��!�"�"� �<� 3�$�S�\�2�2�F�6�N� �8� +� ���]�]�F�6�N� �8� ��F�*�*� �"�7�3�8�#4�#4�#<�#<�S�"�#E�#E�F�F��t� � ��"�J�/� � � ��� ���� �:�� !� !�)6�F�%� &� �Ms�C!�!%D�8H�H�Hc���eZdZdZed���Zeddfdeedee fd�Z de e ffd�Z d �Z dd �Zdd �Zd e dd fd�Zdefd�Zdd�Zdd�Zdd defd�Zddeddfd�Zdd�Zd d�ZdS)!�ConnectionPoola� 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 �x�t|��}d|vr |d|d<|�|��|di|��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. r�rT)r�update)�clsrr�� url_optionss rO�from_urlzConnectionPool.from_url�sP��R ��n�n� � �� '� '�.4�5G�.H�K�*� +�� � �k�"�"�"��s�}�}�V�}�}�r4Nr�� cache_factoryc �P�|pd}t|t��r|dkrtd���||_||_||_d|_||_|�d��s|�d��r�|�d��dvrtd���|j�d��}|�,t|t��std ���||_nd|j�|j� ��|_n>t|j�d����� ��|_|� dd��|� dd��tj��|_|���dS) Nlrz,"max_connections" must be a positive integer� cache_configrfr�)r�r,z4Client caching is only supported with RESP version 3z#Cache must implement CacheInterface)r>r�r�r��connection_kwargsr�rf�_cache_factoryr r&r� get_cacher�poprlrm� _fork_lock�reset)rJr�r�r rrfs rOr\zConnectionPool.__init__s���*�2�U���/�3�/�/� M�?�Q�3F�3F��K�L�L� L� 0���!2���.����� �+��� � � �� 0� 0� "�4E�4I�4I�'�4R�4R� "� �$�$�Z�0�0��@�@� �!W�X�X�X��*�.�.�w�7�7�E�� �!�%��8�8�L�$�%J�K�K�K�"�� � ��&�2�!%�!4�!>�!>�!@�!@�D�J�J�!-��.�2�2�>�B�B�"�"��i�k�k��J� ���g�t�,�,�,����n�d�3�3�3�$�.�*�*��� � � � � � � � r4rWc ��dt|��j�dt|��j�dt|jdi|j�����d�S)Nr�r�r�r�rT)�typerRrQ�reprr�rrms rOr�zConnectionPool.__repr__4so�� J��T� � �%� J� J��T� � �(;� J� J��*�T�*�D�D�T�-C�D�D�E�E� J� J� J� r4c�8�|j�dd��S)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)rr rms rOr6zConnectionPool.get_protocol:s�� �%�)�)�*�d�;�;�;r4c��tj��|_d|_g|_t ��|_tj��|_ dS)Nr) rlrm�_lock�_created_connections�_available_connectionsr��_in_use_connectionsr�r�r�rms rOrzConnectionPool.resetBs@���^�%�%�� �$%��!�&(��#�#&�5�5�� ��9�;�;����r4c�Z�|jtj��kr�|j�d���}|st � |jtj��kr|���|j���dS#|j���wxYwdS)N�)r�)r�r�r�r�acquirer#r�release)rJ�acquireds rO� _checkpidzConnectionPool._checkpidSs���F �8�r�y�{�{� "� "���.�.�q�.�9�9�H�� +�*�*� *��8�r�y�{�{�*�*��J�J�L�L�L���'�'�)�)�)�)�)����'�'�)�)�)�)���� #� "s �0B � B(� command_namer@c��|���|j5 |j���}n$#t$r|���}YnwxYw|j�|��ddd��n #1swxYwY |��� |� ��r|j �td���nb#ttf$rN|� ��|���|� ��rtd���YnwxYwn$#t$r|�|���wxYw|S)zGet a connection from the poolN�Connection has data�Connection not ready)r$rrr� IndexError�make_connectionr�addr{r�rfr$r�r�r#r"�rJr%r��options� connections rO�get_connectionzConnectionPool.get_connection�s��� ������ �Z� 5� 5� 4�!�8�<�<�>�>� � ��� 4� 4� 4�!�1�1�3�3� � � � 4���� � $� (� (�� 4� 4� 4�  5� 5� 5� 5� 5� 5� 5� 5� 5� 5� 5���� 5� 5� 5� 5� � � � � � � �  B��&�&�(�(�A�T�Z�-?�)�*?�@�@�@���#�W�-� B� B� B��%�%�'�'�'��"�"�$�$�$��&�&�(�(�B�)�*@�A�A�A�B�B� B������ � � � � �L�L�� $� $� $� �  ���� �sb�B�8�B�A�B�A�B�B� B�D1�#*C� D1�AD-�*D1�,D-�-D1�1!Ec��|j}t|�dd��|�dd��|�dd�����S)z,Return an encoder based on encoding settingsr�r�r�r�r�F)r�r�r�)rrr )rJr�s rO� get_encoderzConnectionPool.get_encoder�sV���'����Z�Z� �G�4�4�"�J�J�'8�(�C�C�#�Z�Z�(:�E�B�B� � � � r4rkc���|j|jkrtd���|xjdz c_|j�+t |jdi|j��|j|j��S|jdi|j��S)zCreate a new connectionzToo many connectionsrNrT)rr�r$rfrcr�rrrms rOr*zConnectionPool.make_connection�s��� � $��(<� <� <�!�"8�9�9� 9� �!�!�Q�&�!�!� �:� !�'�%��%�?�?��(>�?�?���T�Z��� �%�t�$�>�>�t�'=�>�>�>r4r.c��|���|j5 |j�|��n#t$rYnwxYw|�|��r|j�|��n2|xjdzc_|� �� ddd��dS ddd��dS#1swxYwYdS)z(Releases the connection back to the poolrN) r$rrr��KeyError�owns_connectionrrCrr��rJr.s rOr"zConnectionPool.release�sI�� ������ �Z� � � ��(�/�/� �;�;�;�;��� � � ��� ���� �#�#�J�/�/� ��+�2�2�:�>�>�>�>� �)�)�Q�.�)�)��%�%�'�'�'��! � � � � � � � �?� � � � � � � � � � � � ���� � � � � � s2�B9�9�B9� A�B9�A�AB9�9B=�B=c�"�|j|jkSrY)r�r6s rOr5zConnectionPool.owns_connection�s���~���)�)r4T�inuse_connectionsc���|���|j5|rt|j|j��}n|j}|D]}|���� ddd��dS#1swxYwYdS)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)r$rrrrr�)rJr8� connectionsr.s rOr�zConnectionPool.disconnect�s��� ������ �Z� (� (� � :�#��/��1I��� � �#�9� �)� (� (� ��%�%�'�'�'�'� (� (� (� (� (� (� (� (� (� (� (� (� (���� (� (� (� (� (� (s�>A(�(A,�/A,c�.�|���dS)z-Close the pool, disconnecting all connectionsNr�rms rOrzConnectionPool.close�rr4r�r)c��|j�d|i��|jD] }||_� |jD] }||_� dS)Nr�)rr rr�r)rJr�res rO� set_retryzConnectionPool.set_retry�s^�� ��%�%�w��&6�7�7�7��/� � �D��D�J�J��,� � �D��D�J�J� � r4ri)rWrk)r.r@rWNr�)r�r)rWN)rQrRrSr;� classmethodr r@r r�rr\r?r�r6rr$r/rr1r*r"r5r=r�rr=rTr4rOrr�s������� � ��.�.��[�.�d$�)-�9=� 0�0�"�#��0� � 5�6� 0�0�0�0�d �3��*� � � � � <�<�<�����"-*�-*�-*�-*�^�3��\�����B �W� � � � � ?� ?� ?� ?�����**�,�*�3�*�*�*�*�(�(�D�(�D�(�(�(�(�(���������r4rc�J��eZdZdZddeef�fd� Zd�Zd�Zd�Z d�Z d �Z �xZ S) �BlockingConnectionPoola 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) �2�c �\��||_||_t��jd||d�|��dS)N)r�r�rT)� queue_classr�rJr\)rJr�r�r�rDrr�s �rOr\zBlockingConnectionPool.__init__sS���'����� ������ �-�+� � � � � � � � r4c���|�|j��|_ |j�d��n#t$rYnwxYw�-g|_t j��|_dSrY) rDr��pool� put_nowaitr� _connectionsr�r�r�rms rOrzBlockingConnectionPool.reset#s���$�$�T�%9�:�:�� � � �� �$�$�T�*�*�*�*��� � � ��� ���� �����9�;�;����s�=� A � A c���|j�,t|jdi|j��|j|j��}n|jdi|j��}|j�|��|S)zMake a fresh connection.NrT)rfrcr�rrrHrCr6s rOr*z&BlockingConnectionPool.make_connection;sv�� �:� !�-�%��%�?�?��(>�?�?���T�Z���J�J�/��.�H�H��1G�H�H�J� �� � ��,�,�,��r4c�`�|���d} |j�d|j���}n#t$rt d���wxYw|�|���} |��� |���rt d���nb#t tf$rN|� ��|���|���rt d���YnwxYwn$#t$r|� |���wxYw|S)a7 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)�blockr�zNo connection available.r'r() r$rFr r�rr$r*r{r�r�r�r#r"r,s rOr/z%BlockingConnectionPool.get_connectionFsz�� ������� � >�����T�4�<��H�H�J�J��� >� >� >�"�"<�=�=� =� >���� � ��-�-�/�/�J� � � � � � � �  B��&�&�(�(�A�)�*?�@�@�@�A��#�W�-� B� B� B��%�%�'�'�'��"�"�$�$�$��&�&�(�(�B�)�*@�A�A�A�B�B� B������ � � � � �L�L�� $� $� $� � ���� �s:�!:�A�.D �#B'�&D �'AD�D �D�D � !D+c��|���|�|��s0|���|j�d��dS |j�|��dS#t $rYdSwxYw)z)Releases the connection back to the pool.N)r$r5r�rFrGrr6s rOr"zBlockingConnectionPool.releasezs��� �������#�#�J�/�/� � � !� !� #� #� #� �I� � �� &� &� &� �F� � �I� � �� ,� ,� ,� ,� ,��� � � � �D�D� ���s�A7�7 B�Bc�j�|���|jD]}|����dS)z(Disconnects all connections in the pool.N)r$rHr�r6s rOr�z!BlockingConnectionPool.disconnect�sC�� �������+� $� $�J� � !� !� #� #� #� #� $� $r4) rQrRrSr;r@rr\rr*r/r"r�r`ras@rOr@r@�s����������F��#��  � � � � � � ���0 � � �2�2�2�h���*$�$�$�$�$�$�$r4r@)\r�r�r�r�rGrlr��abcr� itertoolsr�queuerrrr�typingr r r r r rr� urllib.parserrr� redis.cacherrrrrr�_parsersrrrr�backoffr� credentialsrr � exceptionsr!r"r#r$r%r&r'r(r�r)�utilsr*r+r,r-r.r/r0r1rDr`rerbr^r��objectr��__annotations__r6r8rVrkr�r@rcr�r�r�r�r�r<�listr�rrr@rTr4rO�<module>r\s�� � � � � � � � � � � � � � � � � � � � � ���������������������(�(�(�(�(�(�(�(�(�(�������C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�4�4�4�4�4�4�4�4�4�4�����������������J�I�I�I�I�I�I�I�I�I�I�I�������O�O�O�O�O�O�O�O� � � � � � � � � � � � � � � � � � � � ������� � � � � � � � � � � � � � � � � � � � ����N�N�N� �� � � �� � ��� �6�8�8���E�,� �n�D�E�F�F�F�F��!�"�M�M� �M���������$0�0�0�0�0�0�0�0�fB �B �B �B �B �B �B �B �JJ)�J)�J)�J)�J)�,�J)�J)�J)�ZC*�C*�C*�C*�C*�#�C*�C*�C*�LE:�E:�E:�E:�E:�.�E:�E:�E:�Pf�f�f�f�f�J�f�f�f�R�����!3����>/� ���� ��#����� �!�� � ��6�6�6�rk�k�k�k�k�k�k�k�\ b$�b$�b$�b$�b$�^�b$�b$�b$�b$�b$r4
Memory