� J�g�7��@�ddlZddlZddlZddlmZmZmZmZmZm Z m Z ddl m Z ddl mZmZmZmZddlmZddlmZmZmZmZddlmZGd�d e��ZGd �d e��ZGd �d e��ZGd�dee��ZGd�de��ZGd�de��Z dS)�N)� AsyncIterator�Iterable�Mapping�Optional�Sequence�Tuple�Type)�Redis)� Connection�ConnectionPool� EncodableT� SSLConnection)�AsyncSentinelCommands)�ConnectionError� ReadOnlyError� ResponseError� TimeoutError)� str_if_bytesc��eZdZdS)�MasterNotFoundErrorN��__name__� __module__� __qualname__���f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/redis/asyncio/sentinel.pyrr��������Drrc��eZdZdS)�SlaveNotFoundErrorNrrrrr r rrr c ���eZdZ�fd�Zd�Z�fd�Zd�Zd�Z dddd �d ed e e d e e d e ef�fd�Z �xZ S)�SentinelManagedConnectionc �n��|�d��|_t��jdi|��dS)N�connection_poolr)�popr$�super�__init__)�self�kwargs� __class__s �rr'z"SentinelManagedConnection.__init__s;���%�z�z�*;�<�<��������"�"�6�"�"�"�"�"rc��d|jj�d|jj��}|jrd|j�d|j��}||z }|dzS)N�<�.z,host=z,port=z)>)r*rr�host�port)r(�s� host_infos r�__repr__z"SentinelManagedConnection.__repr__sV�� E���)� E� E�D�N�,C� E� E�� �9� �=���=�=�$�)�=�=�I� ��N�A��4�x�rc��<�K�|\|_|_t������d{V��|jjrU|�d���d{V��t|����d{V����dkrtd���dSdS)N�PING�PONGz PING failed) r.r/r&�connectr$�check_connection� send_commandr� read_responser)r(�addressr*s �r� connect_toz$SentinelManagedConnection.connect_to&s������&��� �4�9��g�g�o�o���������� � � 0� 5��#�#�F�+�+� +� +� +� +� +� +� +��$�"4�"4�"6�"6�6�6�6�6�6�6�7�7�6�A�A�%�m�4�4�4� 5� 5�A�Arc��PK�|jrdS|jjr:|�|j����d{V�����d{V��dS|j���23d{V��} |�|���d{V��cS#t $rY�1wxYw6t��N)�_readerr$� is_masterr;�get_master_address� rotate_slavesrr )r(�slaves r�_connect_retryz(SentinelManagedConnection._connect_retry.s���� �<� � �F� � � )� %��/�/��(<�(O�(O�(Q�(Q�"Q�"Q�"Q�"Q�"Q�"Q�R�R� R� R� R� R� R� R� R� R� R�#�3�A�A�C�C� � � � � � � �e��!%����!7�!7�7�7�7�7�7�7�7�7�7��&�����H����� D� %� $s�+B �3B� B�Bc��TK�|j�|jd����d{V��S)Nc�*�tjd��S)Nr)�asyncio�sleep)�errors r�<lambda>z3SentinelManagedConnection.connect.<locals>.<lambda>>s��'�-��*�*�r)�retry�call_with_retryrC�r(s rr6z!SentinelManagedConnection.connect;sJ�����Z�/�/� � � *� *� � � � � � � � � rFNT)�disconnect_on_error� push_request�disable_decoding�timeoutrMrNc����K� t���||||����d{V��S#t$r7|jjr)|����d{V��t d����wxYw)N)rOrPrMrNz"The previous master is now a slave)r&r9rr$r?� disconnectr)r(rOrPrMrNr*s �rr9z'SentinelManagedConnection.read_responseAs������ ����.�.�!1��$7�)� /��������� �� � � � ��#�-� L� �o�o�'�'�'�'�'�'�'�'�'�%�&J�K�K�K� � ���s �*0�AA1)FN) rrrr'r2r;rCr6�boolr�floatr9� __classcell__�r*s@rr"r"s��������#�#�#�#�#����5�5�5�5�5� %� %� %� � � �"'�#'�� 04�',� ������%��� &�e�_� � �t�n� ���������rr"c��eZdZdS)�SentinelManagedSSLConnectionNrrrrrXrX\rrrXc�T��eZdZdZ�fd�Zd�Z�fd�Zdef�fd� Zd�Z de fd �Z �xZ S) �SentinelConnectionPoolz� Sentinel backed connection pool. If ``check_connection`` flag is set to True, SentinelManagedConnection sends a PING command right after establishing the connection. c ���|�d|�dd��rtnt��|d<|�dd��|_|�dd��|_t ��jdi|��tj |��|j d<||_ ||_ d|_ d|_dS) N�connection_class�sslFr?Tr7r$r)�getr%rXr"r?r7r&r'�weakref�proxy�connection_kwargs� service_name�sentinel_manager�master_address�slave_rr_counter)r(rbrcr)r*s �rr'zSentinelConnectionPool.__init__hs����%+�Z�Z� ��:�:�e�U�+�+�/�,�,�.� & �& ��!�"� ���K��6�6��� &� � �+=�u� E� E��������"�"�6�"�"�"�4;�M�$�4G�4G���0�1�(��� 0���"��� $����rc �d�d|jj�d|jj�d|j�d|jrdpd�d� S)Nr,r-z (service=�(�masterrBz))>)r*rrrbr?rLs rr2zSentinelConnectionPool.__repr__zsf�� X���)� X� X�D�N�,C� X� X��)� X� X�,0�N�,G�x�,R�7� X� X� X� rc�d��t�����d|_d|_dSr=)r&�resetrdre)r(r*s �rrjzSentinelConnectionPool.reset�s*��� ��� � ����"��� $����r� connectionc���|j p|jo|j|j|jfk}|o t ���|��Sr=)r?rdr.r/r&�owns_connection)r(rk�checkr*s �rrmz&SentinelConnectionPool.owns_connection�sO����N�"� � �N� X�t�2�z�� ��6X�X� ��<����0�0��<�<�<rc��K�|j�|j���d{V��}|jr.|j|kr#||_|�d����d{V��|S)NF)�inuse_connections)rc�discover_masterrbr?rdrR)r(rds rr@z)SentinelConnectionPool.get_master_address�s����#�4�D�D�T�EV�W�W�W�W�W�W�W�W�� �>� ?��"�n�4�4�&4��#��o�o��o�>�>�>�>�>�>�>�>�>��r�returnc��K�|j�|j���d{V��}|r�|j�*t jdt |��dz ��|_tt |����D]3}|jdzt |��z|_||j}|WV��4 |����d{V��WV�n#t$rYnwxYwtd|j�����)zRound-robin slave balancerNr�zNo slave found for ) rc�discover_slavesrbre�random�randint�len�ranger@rr )r(�slaves�_rBs rrAz$SentinelConnectionPool.rotate_slaves�s!�����,�<�<�T�=N�O�O�O�O�O�O�O�O�� � ��$�,�(.��q�#�f�+�+��/�(J�(J��%��3�v�;�;�'�'� � ��)-�)>��)B�c�&�k�k�(Q��%��t�4�5��� � � � � � ��/�/�1�1�1�1�1�1�1�1� 1� 1� 1� 1� 1��"� � � � �D� ���� �!L�t�7H�!L�!L�M�M�Ms�,C � C�C) rrr�__doc__r'r2rjr rmr@rrArUrVs@rrZrZ`s����������%�%�%�%�%�$ � � � %�%�%�%�%� =�*�=�=�=�=�=�=� ���N�]�N�N�N�N�N�N�N�NrrZc��eZdZdZ dd�Zd�Zd�Zdeded e fd �Z defd �Z d e e d eeeeffd �Zded eeeeffd�Zeefdedeedeefd�Zeefdedeedeefd�ZdS)�Sentinela~ Redis Sentinel cluster client >>> from redis.sentinel import Sentinel >>> sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1) >>> master = sentinel.master_for('mymaster', socket_timeout=0.1) >>> await master.set('foo', 'bar') >>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1) >>> await slave.get('foo') b'bar' ``sentinels`` is a list of sentinel nodes. Each node is represented by a pair (hostname, port). ``min_other_sentinels`` defined a minimum number of peers for a sentinel. When querying a sentinel, if it doesn't meet this threshold, responses from that sentinel won't be considered valid. ``sentinel_kwargs`` is a dictionary of connection arguments used when connecting to sentinel instances. Any argument that can be passed to a normal Redis connection can be specified here. If ``sentinel_kwargs`` is not specified, any socket_timeout and socket_keepalive options specified in ``connection_kwargs`` will be used. ``connection_kwargs`` are keyword arguments that will be used when establishing a connection to a Redis server. rNc ���|�d�|���D��}|�_�fd�|D���_|�_|�_dS)Nc�D�i|]\}}|�d���||��S)�socket_)� startswith)�.0�k�vs r� <dictcomp>z%Sentinel.__init__.<locals>.<dictcomp>�s?�������A�a�l�l�9�>U�>U���1���rc�>��g|]\}}td||d��j����S))r.r/r)r �sentinel_kwargs)r��hostnamer/r(s �r� <listcomp>z%Sentinel.__init__.<locals>.<listcomp>�sE��� � � ���$� � C�x�d� C� C�d�.B� C� C� � � r)�itemsr�� sentinels�min_other_sentinelsra)r(r�r�r�ras` rr'zSentinel.__init__�s���� � "���!2�!8�!8�!:�!:����O� /��� � � � �"+� � � ���$7�� �!2����rc��T��K�t��dd����}d����vr��d��|r+t j|j��j�i����d{V��n(��fd�|jD��}tj |��d{V��dS)z� Execute Sentinel command in sentinel nodes. once - If set to True, then execute the resulting command on a single node at random, rather than across the entire sentinel cluster. �onceFNc �N��g|]!}tj|j�i�������"Sr)rF�Task�execute_command)r��sentinel�argsr)s ��rr�z,Sentinel.execute_command.<locals>.<listcomp>�sF�������� �5�X�5�t�F�v�F�F�G�G���rT) rSr^�keysr%rv�choicer�r�rF�gather)r(r�r)r��taskss `` rr�zSentinel.execute_command�s������� �F�J�J�v�u�-�-�.�.�� �V�[�[�]�]� "� "� �J�J�v� � � � � )�?�&�-���/�/�?��P��P�P� P� P� P� P� P� P� P� P������ $�����E��.�%�(� (� (� (� (� (� (� (��trc���g}|jD]<}|�|jjd�d|jjd�����=d|j�d|jj�dd�|���d�S) Nr.�:r/r,r-z (sentinels=[�,z])>)r��appendr$rar*r�join)r(�sentinel_addressesr�s rr2zSentinel.__repr__�s������� � �H� � %� %��+�=�f�E�H�H��+�=�f�E�H�H� � � � �  =��� =� =���!8� =� =��8�8�$6�7�7� =� =� =� r�staterbrrc�`�|dr|ds|drdS|d|jkrdSdS)Nr?�is_sdown�is_odownFznum-other-sentinelsT)r�)r(r�rbs r�check_master_statezSentinel.check_master_state�sJ���[�!� �U�:�%6� �%� �:K� ��5� �&� '�$�*B� B� B��5��trc��>K�t��}t|j��D]�\}} |����d{V��}n8#tt f$r$}|�|�d|����Yd}~�Qd}~wwxYw|�|��}|rH|�||��r2||jdc|jd<|j|<|d|dfcS��d}t|��dkrdd� |����}td |�|�����) z� Asks sentinel servers for the Redis master's address corresponding to the service labeled ``service_name``. Returns a pair (address, port) or raises MasterNotFoundError if no master is found. Nz - r�ipr/�z : z, zNo master found for ) �list� enumerater��sentinel_mastersrrr�r^r�rxr�r) r(rb�collected_errors� sentinel_nor��masters�er�� error_infos rrqzSentinel.discover_mastersn���� �6�6��%.�t�~�%>�%>� 2� 2� !�K�� � (� 9� 9� ;� ;�;�;�;�;�;�;����#�\�2� � � � �'�'�8�(=�(=��(=�(=�>�>�>���������� �����K�K� �-�-�E�� 2��0�0�� �E�E� 2���N�1�%�?���q�!�4�>�+�#>��T�{�E�&�M�1�1�1�1��� � �� � �1� $� $�<�t�y�y�)9�:�:�<�<�J�!�"U��"U��"U�"U�V�V�Vs�A�A;�A6�6A;rzc�|�g}|D]6}|ds|dr�|�|d|df���7|S)z1Remove slaves that are in an ODOWN or SDOWN stater�r�r�r/)r�)r(rz� slaves_aliverBs r� filter_slaveszSentinel.filter_slavess^��� �� >� >�E��Z� � �E�*�$5� �� � � ��t��e�F�m� <� =� =� =� =��rc���K�|jD]W} |�|���d{V��}n#tttf$rY�8wxYw|�|��}|r|cS�XgS)z;Returns a list of alive slaves for service ``service_name``N)r��sentinel_slavesrrrr�)r(rbr�rzs rruzSentinel.discover_slaves*s������� � �H� �'�7�7� �E�E�E�E�E�E�E�E����#�]�L�A� � � ��� �����'�'��/�/�F�� �� � � � �� s�)�A�A� redis_class�connection_pool_classc ��d|d<t|j��}|�|��|||fi|��}|�|��S)a� Returns a redis client instance for the ``service_name`` master. A :py:class:`~redis.sentinel.SentinelConnectionPool` class is used to retrieve the master's address before establishing a new connection. NOTE: If the master's address has changed, any cached connections to the old master are closed. By default clients will be a :py:class:`~redis.Redis` instance. Specify a different class to the ``redis_class`` argument if you desire something different. The ``connection_pool_class`` specifies the connection pool to use. The :py:class:`~redis.sentinel.SentinelConnectionPool` will be used by default. All other keyword arguments are merged with any connection_kwargs passed to this class and passed to the connection pool as keyword arguments to be used to initialize Redis connections. Tr?��dictra�update� from_pool�r(rbr�r�r)rar$s r� master_forzSentinel.master_for8sb��:#��{�� ��!7�8�8��� � ��(�(�(�/�/� �d�X�X�FW�X�X���$�$�_�5�5�5rc ��d|d<t|j��}|�|��|||fi|��}|�|��S)a� Returns redis client instance for the ``service_name`` slave(s). A SentinelConnectionPool class is used to retrieve the slave's address before establishing a new connection. By default clients will be a :py:class:`~redis.Redis` instance. Specify a different class to the ``redis_class`` argument if you desire something different. The ``connection_pool_class`` specifies the connection pool to use. The SentinelConnectionPool will be used by default. All other keyword arguments are merged with any connection_kwargs passed to this class and passed to the connection pool as keyword arguments to be used to initialize Redis connections. Fr?r�r�s r� slave_forzSentinel.slave_for]sb��0$��{�� ��!7�8�8��� � ��(�(�(�/�/� �d�X�X�FW�X�X���$�$�_�5�5�5r)rN)rrrr|r'r�r2r��strrSr�rqrrrrr r�rur rZr r�r�rrrr~r~�s���������>�� 3�3�3�3�,���(  �  �  ����C��D�����W�#�W�W�W�W�: ��w�'� � �%� �J�.�/� 0� � � � � �� � �%� �J�.�/� 0� � � � �"$)�>T� #6�#6��#6��%�[�#6� $�$:�;� #6�#6�#6�#6�P$)�>T� 6�6��6��%�[�6� $�$:�;� 6�6�6�6�6�6rr~)!rFrvr_�typingrrrrrrr �redis.asyncio.clientr �redis.asyncio.connectionr r r r�redis.commandsr�redis.exceptionsrrrr� redis.utilsrrr r"rXrZr~rrr�<module>r�s������ � � � �����T�T�T�T�T�T�T�T�T�T�T�T�T�T�T�T�T�T�&�&�&�&�&�&������������� 1�0�0�0�0�0�X�X�X�X�X�X�X�X�X�X�X�X�$�$�$�$�$�$� � � � � �/� � � � � � � � �� � � �?�?�?�?�?� �?�?�?�D � � � � �#<�m� � � �DN�DN�DN�DN�DN�^�DN�DN�DN�NT6�T6�T6�T6�T6�$�T6�T6�T6�T6�T6r
Memory