� J�g�����ddlZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z m Z m Z mZddlmZddlmZmZmZmZddlmZmZddlmZmZmZmZddlmZm Z m!Z!m"Z"dd l#m$Z$dd l%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,dd l-m.Z.dd l/m0Z0dd l1m2Z2m3Z3m4Z4m5Z5m6Z6dZ7dZ8dZ9Gd�de:��Z;Gd�d��Z<Gd�deee��Z=e=Z>Gd�d��Z?Gd�d��Z@Gd�dejA��ZBGd�de=��ZCdS)�N)�chain)�Any�Callable�Dict�List�Optional�Type�Union)�Encoder)�_RedisCallbacks�_RedisCallbacksRESP2�_RedisCallbacksRESP3�bool_ok)� CacheConfig�CacheInterface)� CoreCommands�RedisModuleCommands�SentinelCommands� list_or_args)�AbstractConnection�ConnectionPool� SSLConnection�UnixDomainSocketConnection)�CredentialProvider)�ConnectionError�ExecAbortError� PubSubError� RedisError� ResponseError� TimeoutError� WatchError��Lock)�Retry)�HIREDIS_AVAILABLE�_set_info_logger�get_lib_version�safe_str� str_if_bytes��EMPTY_RESPONSE� NEVER_DECODEc�v��eZdZdZdeeefddfd�Z�fd�Z�fd�Z�fd�Z d �fd � Z �fd �Z �fd �Z �xZ S) �CaseInsensitiveDictz?Case insensitive dict implementation. Assumes string keys only.�data�returnNc�h�|���D]\}}|||���<�dS�N)�items�upper)�selfr/�k�vs �\/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/redis/client.py�__init__zCaseInsensitiveDict.__init__;s:���J�J�L�L� � �D�A�q��D������O�O� � r*c�j��t���|�����Sr2)�super� __contains__r4�r5r6� __class__s �r8r<z CaseInsensitiveDict.__contains__?s#����w�w�#�#�A�G�G�I�I�.�.�.r*c�n��t���|�����dSr2)r;� __delitem__r4r=s �r8r@zCaseInsensitiveDict.__delitem__Bs)��� �����A�G�G�I�I�&�&�&�&�&r*c�j��t���|�����Sr2)r;� __getitem__r4r=s �r8rBzCaseInsensitiveDict.__getitem__Es#����w�w�"�"�1�7�7�9�9�-�-�-r*c�l��t���|���|��Sr2)r;�getr4)r5r6�defaultr>s �r8rDzCaseInsensitiveDict.getHs#����w�w�{�{�1�7�7�9�9�g�.�.�.r*c�p��t���|���|��dSr2)r;� __setitem__r4)r5r6r7r>s �r8rGzCaseInsensitiveDict.__setitem__Ks+��� �����A�G�G�I�I�q�)�)�)�)�)r*c�h��t|��}t���|��dSr2)r.r;�update)r5r/r>s �r8rIzCaseInsensitiveDict.updateNs,���"�4�(�(�� �����t�����r*r2)�__name__� __module__� __qualname__�__doc__r�strr9r<r@rBrDrGrI� __classcell__�r>s@r8r.r.8s��������E�E� �T�#�s�(�^� �� � � � �/�/�/�/�/�'�'�'�'�'�.�.�.�.�.�/�/�/�/�/�/�*�*�*�*�*���������r*r.c��eZdZdS)� AbstractRedisN)rJrKrL�r*r8rRrRSs�������Dr*rRc-�\�eZdZdZededdfd���Zededdeddfd���Z dd d d d d d d d d d d d d ddd dd d dd d d dd ddd d d d d dd d de ��d d d d dd d f-de e de e de ede edd f d�Zdefd�Zd>d�Zdefd�Zde dfd�Zd?d�Zded edd fd!�Zd@d"�ZdAdBd%�Zd&ed$gd fdd fd'�Z dCd)ed*e ed+ed,ed-e ed.ed efd/efd0�Z d1�Z!d2�Z"d3�Z#d4�Z$d5�Z%d6�Z&d7�Z'd8�Z(d9�Z)d:�Z*d;�Z+d<�Z,de efd=�Z-d S)D�Redisa� Implementation of the Redis protocol. This abstract class provides a Python interface to all Redis commands and an implementation of the Redis protocol. Pipelines derive from this, implementing how the commands are sent and received to the Redis server. Based on configuration, an instance will either use a ConnectionPool, or Connection object to talk to redis. It is not safe to pass PubSub or Pipeline objects between threads. �urlr0c �~�|�dd��}tj|fi|��}|||���}d|_|S)a Return a Redis client object 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. �single_connection_clientF��connection_poolrXT)�popr�from_url�auto_close_connection_pool)�clsrV�kwargsrXrZ�clients r8r\zRedis.from_urlfs]��T$*�:�:�.H�%�#P�#P� �(�1�#�@�@��@�@����+�%=� � � ��-1��)�� r*r^rZc�,�||���}d|_|S)z� Return a Redis client from the given connection pool. The Redis client will take ownership of the connection pool and close it when the Redis client is closed. )rZT)r])r^rZr`s r8� from_poolzRedis.from_pool�s,����+� � � ��-1��)�� r*� localhosti�rNzutf-8�strictF�requiredzredis-py��credential_provider�protocol�cache� cache_configc.�d�| �sN| �#tjtd����| } |�#tjtd����|} |sg}|dur|�t��id|�d|'�d|�d|�d | �d | �d |�d |�d t j|(���d|!�d|#�d|$�d|%�d|&�d|)�d|*�d|+�}.| �|.�| td���ng|.�|||||d���|r*|.�t|||||||||||||| d���|-s|,r|+dvr|.�|,|-d���tdi|.��} d|_ nd|_ | |_ |-s|,r*|j � ��dvrtd���d|_|"r|j �d��|_t#t$��|_|j j�d��dvr!|j�t,��dS|j�t.��dS) a� Initialize a new Redis client. 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`. Args: single_connection_client: if `True`, connection pool is not used. In that case `Redis` instance use is not thread safe. Nz/"charset" is deprecated. Use "encoding" insteadz5"errors" is deprecated. Use "encoding_errors" insteadT�db�username�password�socket_timeout�encoding�encoding_errors�decode_responses�retry_on_error�retry�max_connections�health_check_interval� client_name�lib_name� lib_version�redis_connect_funcrgrh)�path�connection_class)�host�port�socket_connect_timeout�socket_keepalive�socket_keepalive_options)r|� ssl_keyfile� ssl_certfile� ssl_cert_reqs� ssl_ca_certs� ssl_ca_data�ssl_check_hostname� ssl_password� ssl_ca_path�ssl_validate_ocsp_stapled�ssl_validate_ocsp�ssl_ocsp_context�ssl_ocsp_expected_cert�ssl_min_version� ssl_ciphers)��3)rirjFz4Client caching is only supported with RESP version 3�_)r�r�rS)�warnings�warn�DeprecationWarning�appendr �copy�deepcopyrIrrrr]rZ� get_protocolr� connection�get_connectionr.r �response_callbacks�connection_kwargsrDrr )/r5r}r~rlrnrorr�r�rZ�unix_socket_pathrprq�charset�errorsrr�retry_on_timeoutrs�sslr�r�r�r�r�r�r�r�r�r�r�r�r�r�rurXrvrwrxryrmrtrzrgrhrirjr_s/ r8r9zRedis.__init__�s{��z�X 4��"�� �&�I������ #���!�� �&�O������ #)��!� $�!#���4�'�'��%�%�l�3�3�3���b���H���H��!�.� � �H� � "�?� �#�$4��!�.�����u�-�-��"�?��(�)>���{���H���{��%�&8�� &�':�!�"�H�#�F�( �+�� � � 0�,F�������� � � $� $�2H�,<�4L� ��������M�M�0=�+6�,8�-:�,8�+6�2D�,8�+6�9R�1B�0@�6L�/>�+6������&!��E��x�8�/C�/C��M�M�%*�,8������ -�6�6�v�6�6�O�.2�D� +� +�.3�D� +�.��� � U�E� U�t�';�'H�'H�'J�'J�S �( �( ��S�T�T� T���� #� G�"�2�A�A�#�F�F�D�O�"5�o�"F�"F��� � � 1� 5� 5�j� A� A�X� M� M� � #� *� *�+?� @� @� @� @� @� � #� *� *�+?� @� @� @� @� @r*c��dt|��j�dt|��j�dt|j���d�S)N�<�.�(z)>)�typerKrJ�reprrZ�r5s r8�__repr__zRedis.__repr__SsS�� /��T� � �%� /� /��T� � �(;� /� /��T�)�*�*� /� /� /� r*r c�4�|j���S)z!Get the connection pool's encoder)rZ� get_encoderr�s r8r�zRedis.get_encoderYs���#�/�/�1�1�1r*c��|jjS)z'Get the connection's key-word arguments)rZr�r�s r8�get_connection_kwargszRedis.get_connection_kwargs]s���#�5�5r*r$c�P�|����d��S�Nrt)r�rDr�s r8� get_retryzRedis.get_retryas"���)�)�+�+�/�/��8�8�8r*rtc��|����d|i��|j�|��dSr�)r�rIrZ� set_retry)r5rts r8r�zRedis.set_retrydsD�� �"�"�$�$�+�+�W�e�,<�=�=�=� ��&�&�u�-�-�-�-�-r*�command�callbackc��||j|<dS)zSet a custom Response CallbackN)r�)r5r�r�s r8�set_response_callbackzRedis.set_response_callbackhs��+3����(�(�(r*c�(�t|||��dS)a This function can be used to add externally defined redis modules, and their namespaces to the redis client. funcname - A string containing the name of the function to create func - The function, being added to this class. ex: Assume that one has a custom redis module named foomod that creates command named 'foo.dothing' and 'foo.anotherthing' in redis. To load function functions into this namespace: from redis import Redis from foomodule import F r = Redis() r.load_external_module("foo", F) r.foo().dothing('your', 'arguments') For a concrete example see the reimport of the redisjson module in tests/test_connection.py::test_loading_external_modules N)�setattr)r5�funcname�funcs r8�load_external_modulezRedis.load_external_modulels��* ��h��%�%�%�%�%r*T�Pipelinec�:�t|j|j||��S)a_ Return a new pipeline object that can queue multiple commands for later execution. ``transaction`` indicates whether all commands should be executed atomically. Apart from making a group of operations atomic, pipelines are useful for reducing the back-and-forth overhead between the client and server. )r�rZr�)r5� transaction� shard_hints r8�pipelinezRedis.pipeline�s%��� � �$�"9�;� � � � r*r�c��|�dd��}|�dd��}|�dd��}|�d|��5} |r |j|�||��}|���} |r|n| cddd��S#t$r|�|dkrt j|��Y�hwxYw#1swxYwYdS)z� Convenience method for executing the callable `func` as a transaction while watching all keys specified in `watches`. The 'func' callable should expect a single argument which is a Pipeline object. r�N�value_from_callableF� watch_delayTr)r[r��watch�executer!�time�sleep) r5r��watchesr_r�r�r��pipe� func_value� exec_values r8r�zRedis.transaction�s>���Z�Z� �d�3�3� �$�j�j�)>��F�F���j�j���5�5� � �]�]�4�� ,� ,� �� � ��-�"�� �G�,�,�!%��d���J�!%�����J�)<�L�:�:�*�L� � � � � � � � ��"����"�.�;��?�?�� �;�/�/�/��H����� � � � ���� � � � � � s0�C�0B�&C�C�C�C�C � C 皙�����?�name�timeoutr��blocking�blocking_timeout� lock_class� thread_localc �8�|�t}||||||||���S)aL Return a new Lock object using key ``name`` that mimics the behavior of threading.Lock. If specified, ``timeout`` indicates a maximum life for the lock. By default, it will remain locked until release() is called. ``sleep`` indicates the amount of time to sleep per loop iteration when the lock is in blocking mode and another client is currently holding the lock. ``blocking`` indicates whether calling ``acquire`` should block until the lock has been acquired or to fail immediately, causing ``acquire`` to return False and the lock not being acquired. Defaults to True. Note this value can be overridden by passing a ``blocking`` argument to ``acquire``. ``blocking_timeout`` indicates the maximum amount of time in seconds to spend trying to acquire the lock. A value of ``None`` indicates continue trying forever. ``blocking_timeout`` can be specified as a float or integer, both representing the number of seconds to wait. ``lock_class`` forces the specified lock implementation. Note that as of redis-py 3.0, the only lock class we implement is ``Lock`` (which is a Lua-based lock). So, it's unlikely you'll need this parameter, unless you have created your own custom lock class. ``thread_local`` indicates whether the lock token is placed in thread-local storage. By default, the token is placed in thread local storage so that a thread only sees its token, not a token set by another thread. Consider the following timeline: time: 0, thread-1 acquires `my-lock`, with a timeout of 5 seconds. thread-1 sets the token to "abc" time: 1, thread-2 blocks trying to acquire `my-lock` using the Lock instance. time: 5, thread-1 has not yet completed. redis expires the lock key. time: 5, thread-2 acquired `my-lock` now that it's available. thread-2 sets the token to "xyz" time: 6, thread-1 finishes its work and calls release(). if the token is *not* stored in thread local storage, then thread-1 would see the token value as "xyz" and would be able to successfully release the thread-2's lock. In some use cases it's necessary to disable thread local storage. For example, if you have code where one thread acquires a lock and passes that lock instance to a worker thread to release later. If thread local storage isn't disabled in this case, the worker thread won't see the token set by the thread that acquired the lock. Our assumption is that these cases aren't common and as such default to using thread local storage.N)r�r�r�r�r�r")r5r�r�r�r�r�r�r�s r8�lockz Redis.lock�s>��| � ��J��z� � ����-�%� � � � r*c �&�t|jfi|��S)z� Return a Publish/Subscribe object. With this object, you can subscribe to channels and listen for messages that get published to them. )�PubSubrZ)r5r_s r8�pubsubz Redis.pubsub�s�� �d�*�5�5�f�5�5�5r*c�*�t|j��Sr2)�MonitorrZr�s r8�monitorz Redis.monitor�s���t�+�,�,�,r*c�:�|�|jd���S)NTrY)r>rZr�s r8r`z Redis.client�s%���~�~� �0�4�� � � r*c��|Sr2rSr�s r8� __enter__zRedis.__enter__���� r*c�.�|���dSr2��close�r5�exc_type� exc_value� tracebacks r8�__exit__zRedis.__exit__��� � � � � � � � r*c�.�|���dSr2r�r�s r8�__del__z Redis.__del__r�r*c���t|d��sdS|j}|r!d|_|j�|��|jr|j���dSdS)Nr�)�hasattrr�rZ�releaser]� disconnect�r5�conns r8r�z Redis.close sx���t�\�*�*� � �F���� � /�"�D�O� � � (� (�� .� .� .� � *� .� � � +� +� -� -� -� -� -� .� .r*c�:�|j|i|��|j||fi|��S)z7 Send a command and parse the response )� send_command�parse_response)r5r�� command_name�args�optionss r8�_send_command_parse_responsez"Redis._send_command_parse_responses9�� ���4�+�7�+�+�+�"�t�"�4��A�A��A�A�Ar*c��|���|j�$t|t|j����dur|�dS)z� Close the connection and raise an exception if retry_on_error is not set or the error is not one of the specified error types NF)r�rs� isinstance�tuple�r5r��errors r8�_disconnect_raisezRedis._disconnect_raise sK�� ������ � � '��%��t�':�!;�!;�<�<��E�E��K�F�Er*c��|j|i|��Sr2)�_execute_command�r5r�r�s r8�execute_commandzRedis.execute_command.s��$�t�$�d�6�g�6�6�6r*c� �������j}�d��jp |j�fi���� �j������fd���fd����js|����SS#�js|����wwxYw)z.Execute a command and return a parsed responserc�(���j��g��Ri���Sr2�r��r�r�r�r�r5s�����r8�<lambda>z(Redis._execute_command.<locals>.<lambda>8s6���9��9��,��)-����18���r*c�0�����|��Sr2)r��r�r�r5s ��r8rz(Redis._execute_command.<locals>.<lambda>;s���d�4�4�T�5�A�A�r*)rZr�r�rt�call_with_retryr�)r5r�r��poolr�r�s``` @@r8r�zRedis._execute_command1s���������#���A�w� ���N�"5�$�"5�l�"N�"N�g�"N�"N�� #��:�-�-���������B�A�A�A�A� ���?� #�� � �T�"�"�"�"� #��4�?� #�� � �T�"�"�"�"� #���s �%A.�.B c �� t|vr1|�d���}|�t��n|���}n'#t$rt|vr|tcYS�wxYwt|vr|�t��|�dd��||jvr|j||fi|��S|S)z'Parses a response from the Redis serverT)�disable_decoding�keysN)r,� read_responser[rr+r�)r5r�r�r��responses r8r�zRedis.parse_responseAs��� ��w�&�&�%�3�3�T�3�J�J��� � �L�)�)�)�)�%�3�3�5�5����� � � ���(�(��~�.�.�.�.� � ���� �W� $� $� �K�K�� '� '� '� � � �F�D�!�!�!� �4�2� 2� 2�8�4�*�<�8��M�M�W�M�M� M��s�AA� A5�3A5c��|jjSr2)rZrir�s r8� get_cachezRedis.get_cacheXs���#�)�)r*)r0r )rtr$r0N�r0N)TN�r0r�)Nr�TNNT).rJrKrLrM� classmethodrNr\r rrbr'rr�intrrr9r�r�rr�r�r�rr�r�r�r��float�boolr rr�r�r�r`r�r�r�r�r�r�rr�r�rrSr*r8rUrUWs������ � ��0�3�0�W�0�0�0��[�0�d� � �'�]� �'� � � � � ��[� �"� � ���#��!%���� ������ ��� ���� ���"'��#����!&����#�O�%�%����<@�"#�*.�.2�]hA�hA�V&�&8�9�WhA�X�3�-�YhA�Z��'�[hA�\�{�+�]hA�^ �_hA�hA�hA�hA�T �#� � � � � 2�2�2�2�6�t�6�6�6�6�9�8�G�,�9�9�9�9�.�.�.�.�4�S�4�H�4��4�4�4�4�&�&�&�&�.  �  �  �  �  ���j�\�4�/�0�� �����6$(���,0�'+�!�H �H ��H ��%��H �� H � � H � #�5�/� H ��$��)�$�H ��H �H �H �H �T6�6�6�-�-�-� � � � ��������� .� .� .�B�B�B� � � �7�7�7�#�#�#� ���.*�8�N�3�*�*�*�*�*�*r*rUc�p�eZdZdZejd��Zejd��Zd�Zd�Z d�Z d�Z d�Z d S) r�z� Monitor is useful for handling the MONITOR command to the redis server. next_command() method returns one command from monitor listen() method yields commands from monitor. z\[(\d+) (.*?)\] (.*)z"(.*?)(?<!\\)"c�R�||_|j�d��|_dS)N�MONITOR)rZr�r�)r5rZs r8r9zMonitor.__init__is&��.����.�=�=�i�H�H����r*c��|j�d��|j���}t|��st d|�����|S)NrzMONITOR failed: )r�r�rrr�r5rs r8r�zMonitor.__enter__msW�� ��$�$�Y�/�/�/��?�0�0�2�2���x� � � <��:��:�:�;�;� ;�� r*c�v�|j���|j�|j��dSr2)r�r�rZr�)r5r�s r8r�zMonitor.__exit__us5�� ��"�"�$�$�$� ��$�$�T�_�5�5�5�5�5r*c��|j���}t|t��r!|jj�|d���}|�dd��\}}|j�|��}|� ��\}}}d� |j � |����}|� dd��}|dkrd}d} d} n?|�d ��rd }|d d �} d } n|�d d��\}} d } t!|��t#|��|| | |d�S)z)Parse the response from a monitor commandT��force� �z\"�"�lua��unix�N�:�tcp)r�rl�client_address� client_port� client_typer�)r�rr��bytes�encoder�decode�split� monitor_re�match�groups�join� command_re�findall�replace� startswith�rsplitrr) r5r� command_time� command_data�m�db_id� client_infor�r*r+r,s r8� next_commandzMonitor.next_commandysW���?�0�0�2�2�� �h�� &� &� L���.�5�5�h�d�5�K�K�H�%-�^�^�C��%;�%;�"� �l� �O� !� !�,� /� /��&'�h�h�j�j�#��{�G��(�(�4�?�2�2�7�;�;�<�<���/�/�%��-�-�� �%� � �"�N��K��K�K� � #� #�F� +� +� �#�N�%�a�b�b�/�K� �K�K�+6�*<�*<�S�!�*D�*D� '�N�K��K��,�'�'��e�*�*�,�&�&��  � � r*c#�6K� |���V��)z)Listen for commands coming to the server.)r?r�s r8�listenzMonitor.listen�s(���� &��#�#�%�%� %� %� %� &r*N) rJrKrLrM�re�compiler1r5r9r�r�r?rArSr*r8r�r�_s��������� ���3�4�4�J����-�.�.�J�I�I�I����6�6�6�! �! �! �F&�&�&�&�&r*r�c ��eZdZdZdZdZdZ d1deded d e de e gdfffd �Z d2d �Z d3d�Zd3d�Zd3d�Zd3d�Zd3d�Zed efd���Zd�Zd3d�Zd3d�Zd�Zd4d�Zd efd�Zd3d�Zd efd�Zd�Zd�Zd �Z d!�Z!dd"�d#�Z"dd"�d$�Z#d%�Z$ d5ded'e%fd(�Z&e&Z'd6d)e e dfd efd*�Z(d7d+�Z) d8d,e%d-ed.ee d d/fd0�Z*dS)9r�a* PubSub provides publish, subscribe and listen support to Redis channels. After subscribing to one or more channels, the listen() method will block until a message arrives on one of the subscribed channels. That message will be returned and it's safe to start listening again. )�message�pmessage�smessage)� unsubscribe� punsubscribe� sunsubscribezredis-py-health-checkNF�ignore_subscribe_messagesr.r �push_handler_funcc���||_||_||_d|_t j��|_||_||_|j�|j� ��|_|j� |j ��|_ |jj rd|j g|_nd|j g|_|j�t��|���dS)N�pong�pong)rZr�rKr�� threading�Event�subscribed_eventr.rLr��encode�HEALTH_CHECK_MESSAGE�health_check_response_brr�health_check_responser&�reset)r5rZr�rKr.rLs r8r9zPubSub.__init__�s��� /���$���)B��&���� )�� 1� 1����� �!2��� �<� ��/�;�;�=�=�D�L�'+�|�':�':�4�;T�'U�'U��$� �<� (� Q�*0�$�2K�)L�D� &� &�*1�4�3O�)P�D� &� � !� )� � � � � � � � � � � � r*r0c��|Sr2rSr�s r8r�zPubSub.__enter__�r�r*c�.�|���dSr2�rWr�s r8r�zPubSub.__exit__�r�r*c�R� |���dS#t$rYdSwxYwr2�rW� Exceptionr�s r8r�zPubSub.__del__�s<�� � �J�J�L�L�L�L�L��� � � � �D�D� ���� �� &�&c��|jr^|j���|j�|j��|j�|j��d|_d|_i|_t��|_ i|_ t��|_ i|_ t��|_ |j���dS)Nr)r�r��deregister_connect_callback� on_connectrZr��health_check_response_counter�channels�set�pending_unsubscribe_channels�shard_channels�"pending_unsubscribe_shard_channels�patterns�pending_unsubscribe_patternsrR�clearr�s r8rWz PubSub.reset�s��� �?� #� �O� &� &� (� (� (� �O� 7� 7��� H� H� H� � � (� (��� 9� 9� 9�"�D�O�-.��*��� �,/�E�E��)� ���25�%�%��/��� �,/�E�E��)� ��#�#�%�%�%�%�%r*c�.�|���dSr2rZr�s r8r�z PubSub.close�r�r*c�����j����j����j����jr2�fd��j���D��}�jdi|���jr2�fd��j���D��}�jdi|���j r4�fd��j ���D��}�j di|��dSdS)zBRe-subscribe to any channels and patterns previously subscribed toc�P��i|]"\}}�j�|d���|��#S�Tr�r.r/��.0r6r7r5s �r8� <dictcomp>z%PubSub.on_connect.<locals>.<dictcomp>��A������:>�!�Q�� �#�#�A�T�#�2�2�A���r*c�P��i|]"\}}�j�|d���|��#Srnrorps �r8rrz%PubSub.on_connect.<locals>.<dictcomp>�rsr*c�P��i|]"\}}�j�|d���|��#Srnrorps �r8rrz%PubSub.on_connect.<locals>.<dictcomp>�sD�������A�q�� �#�#�A�T�#�2�2�A���r*NrS) rerjrirgrcr3� subscriberh� psubscriberf� ssubscribe)r5r�rcrhrfs` r8razPubSub.on_connect�sd��� �)�/�/�1�1�1� �)�/�/�1�1�1� �/�5�5�7�7�7� �=� '�����BF�-�BU�BU�BW�BW����H� �D�N� &� &�X� &� &� &� �=� (�����BF�-�BU�BU�BW�BW����H� �D�O� '� '�h� '� '� '� � � .����� �/�5�5�7�7����N� �D�O� -� -�n� -� -� -� -� -�  .� .r*c�4�|j���S)z@Indicates if there are subscriptions to any channels or patterns)rR�is_setr�s r8� subscribedzPubSub.subscribeds���$�+�+�-�-�-r*c��|j�v|j�d|j��|_|j�|j��|j�+ts$|jj� |j��|j}d|j i}|j s|� ��|j ||j g|�Ri|��dS)z#Execute a publish/subscribe commandNr�� check_health)r�rZr�r��register_connect_callbackrarLr%�_parser�set_pubsub_push_handlerr{�clean_health_check_responses�_executer�)r5r�r�r_s r8rzPubSub.execute_command s��� �?� "�"�2�A�A��$�/���D�O� �O� 5� 5�d�o� F� F� F��%�1�:K�1���'�?�?��@V�W�W�W��_� � �d�o�"5�6���� 0� � -� -� /� /� /��� �j�*�"9�K�D�K�K�K�F�K�K�K�K�Kr*c�|�d}|j}|jdkr�|dkr�|�||j|j���rc|�||j��}|�|��r|xjdzc_n"td�|�����|dz}|jdkr |dk��dSdSdSdS)zG If any health check responses are present, clean them � r�r�r"z>A non health check response was cleaned by execute_command: {}N) r�rbr��can_readror�is_health_check_responser�format)r5�ttlr�rs r8r�z#PubSub.clean_health_check_responses s���������0�1�4�4��q����}�}�T�4�=�$�:M�}�N�N� ��=�=��t�/A�B�B���0�0��:�:���6�6�!�;�6�6�6�%�.�.4�f�X�.>�.>���� �1�H�C��0�1�4�4��q�����4�4���4�4r*c��|���|j�$t|t|j����dur|�|���dS)z� Close the connection and raise an exception if retry_on_error is not set or the error is not one of the specified error types. Otherwise, try to reconnect NF)r�rsr�r��connectr�s r8�_disconnect_raise_connectz PubSub._disconnect_raise_connect2sS�� ������ � � '��%��t�':�!;�!;�<�<��E�E��K� � � �����r*c�T�������j����fd���fd���S)aU Connect manually upon disconnection. If the Redis server is down, this will fail and raise a ConnectionError as desired. After reconnection, the ``on_connect`` callback should have been called by the # connection to resubscribe us to any channels and patterns we were previously listening to c�����i���Sr2rS)r�r�r_s���r8rz!PubSub._execute.<locals>.<lambda>Js���G�G�T�,�V�,�,�r*c�0�����|��Sr2)r�rs ��r8rz!PubSub._execute.<locals>.<lambda>Ks���$�8�8��u�E�E�r*)rtr )r5r�r�r�r_s`````r8r�zPubSub._executeAsD��������z�)�)� ,� ,� ,� ,� ,� ,� E� E� E� E� E� � � r*Trc������|j���td���|������fd�}|��|��}|�|��r|xjdzc_dS|S)z3Parse the response from a publish/subscribe commandN�Npubsub connection not set: did you forget to call subscribe() or psubscribe()?c����s������sdSn������dd���S)Nr�FT)�disconnect_on_error� push_request)r�r�r)�blockr�r�s���r8�try_readz'PubSub.parse_response.<locals>.try_readYsS���� ��}�}�W�}�5�5� ��4� �� � �����%�%�%�d�%�S�S� Sr*r")r�� RuntimeErrorr}r�r�rb)r5r�r�r�rr�s `` @r8r�zPubSub.parse_responseNs��������� �<��F��� � ������ T� T� T� T� T� T� T��=�=��x�0�0�� � (� (�� 2� 2� � � .� .�!� 3� .� .��4��r*c�"�||j|jfvS)z� Check if the response is a health check response. If there are no subscriptions redis responds to PING command with a bulk response, instead of a multi-bulk with "pong" and the response. )rVrUrs r8r�zPubSub.is_health_check_responseis"�� � � &� � (� � � r*c���|j}|�td���|jrKtj��|jkr1|�d|jd���|xjdz c_dSdSdS)Nr��PINGF)r}r")r�r�rvr��next_health_checkr�rTrbr�s r8r}zPubSub.check_healthts������ �<��F��� � � %� 4�$�)�+�+��8N�*N�*N� � � �f�d�&?�e� � T� T� T� � .� .�!� 3� .� .� .� .� 4� 4�*N�*Nr*c�x���|jj�|jj���fd�|���D��S)z� normalize channel/pattern names to be either bytes or strings based on whether responses are automatically decoded. this saves us from coercing the value for each message coming in. c�@��i|]\}}��|����|��SrSrS)rqr6r7r/rSs ��r8rrz*PubSub._normalize_keys.<locals>.<dictcomp>�s1���>�>�>���A���v�v�a�y�y�!�!�1�>�>�>r*)r.rSr/r3)r5r/r/rSs @@r8�_normalize_keyszPubSub._normalize_keys�s?���� ��$����$��>�>�>�>�>������>�>�>�>r*c���|rt|d|dd���}t�|��}|�|��|jdg|����R�}|�|��}|j�|��|js |j � ��d|_ |j � |��|S)aE Subscribe to channel patterns. Patterns supplied as keyword arguments expect a pattern name as the key and a callable as the value. A pattern's callable will be invoked automatically when a message is received on that pattern rather than producing a message via ``listen()``. rr"N� PSUBSCRIBE)r�dict�fromkeysrIrr r�rhr{rRrdrbri�difference_update)r5r�r_� new_patterns�ret_vals r8rwzPubSub.psubscribe�s��� � 3���Q���a�b�b��2�2�D��}�}�T�*�*� ����F�#�#�#�&�$�&�|�J�l�6G�6G�6I�6I�J�J�J���+�+�L�9�9� � � ���\�*�*�*��� 3� � !� %� %� '� '� '�12�D� .� �)�;�;�L�I�I�I��r*c���|rLt|d|dd���}|�t�|����}n|j}|j�|��|jdg|�R�S)zj Unsubscribe from the supplied patterns. If empty, unsubscribe from all patterns. rr"N� PUNSUBSCRIBE)rr�r�r�rhrirIr)r5r�rhs r8rIzPubSub.punsubscribe�s��� � %���Q���a�b�b��2�2�D��+�+�D�M�M�$�,?�,?�@�@�H�H��}�H� �)�0�0��:�:�:�#�t�#�N�:�T�:�:�:�:r*c���|rt|d|dd���}t�|��}|�|��|jdg|����R�}|�|��}|j�|��|js |j � ��d|_ |j � |��|S)aR Subscribe to channels. Channels supplied as keyword arguments expect a channel name as the key and a callable as the value. A channel's callable will be invoked automatically when a message is received on that channel rather than producing a message via ``listen()`` or ``get_message()``. rr"N� SUBSCRIBE)rr�r�rIrr r�rcr{rRrdrbrer�)r5r�r_� new_channelsr�s r8rvzPubSub.subscribe�s��� � 3���Q���a�b�b��2�2�D��}�}�T�*�*� ����F�#�#�#�&�$�&�{�I�\�5F�5F�5H�5H�I�I�I���+�+�L�9�9� � � ���\�*�*�*��� 3� � !� %� %� '� '� '�12�D� .� �)�;�;�L�I�I�I��r*c���|rLt|d|dd���}|�t�|����}n|j}|j�|��|jdg|�R�S)zi Unsubscribe from the supplied channels. If empty, unsubscribe from all channels rr"N� UNSUBSCRIBE)rr�r�r�rcrerIr)r5r�rcs r8rHzPubSub.unsubscribe�s��� � %���Q���a�b�b��2�2�D��+�+�D�M�M�$�,?�,?�@�@�H�H��}�H� �)�0�0��:�:�:�#�t�#�M�9�D�9�9�9�9r*)� target_nodec���|rt|d|dd���}t�|��}|�|��|jdg|����R�}|�|��}|j�|��|js |j � ��d|_ |j � |��|S)az Subscribes the client to the specified shard channels. Channels supplied as keyword arguments expect a channel name as the key and a callable as the value. A channel's callable will be invoked automatically when a message is received on that channel rather than producing a message via ``listen()`` or ``get_sharded_message()``. rr"N� SSUBSCRIBE)rr�r�rIrr r�rfr{rRrdrbrgr�)r5r�r�r_�new_s_channelsr�s r8rxzPubSub.ssubscribe�s��� � 3���Q���a�b�b��2�2�D����t�,�,�����f�%�%�%�&�$�&�|�L�n�6I�6I�6K�6K�L�L�L���-�-�n�=�=�� ��"�"�>�2�2�2��� 3� � !� %� %� '� '� '�12�D� .� �/�A�A�.�Q�Q�Q��r*c���|rLt|d|dd���}|�t�|����}n|j}|j�|��|jdg|�R�S)zu Unsubscribe from the supplied shard_channels. If empty, unsubscribe from all shard_channels rr"N� SUNSUBSCRIBE)rr�r�r�rfrgrIr)r5r�r�� s_channelss r8rJzPubSub.sunsubscribe�s��� � -���Q���a�b�b��2�2�D��-�-�d�m�m�D�.A�.A�B�B�J�J��,�J� �/�6�6�z�B�B�B�#�t�#�N�:�T�:�:�:�:r*c#�K�|jr8|�|�d�����}|�|V�|j�6dSdS)zBListen for messages on channels this client has been subscribed toT)r�N)r{�handle_messager�rs r8rAz PubSub.listen�sc�����o� ��*�*�4�+>�+>�T�+>�+J�+J�K�K�H��#������o� � � � � r*�r�c�,�|js[tj��}|j�|��dur*tj��|z }t d||z ��}ndS|�|du|���}|r|�||��SdS)a Get the next message if one is available, otherwise None. If timeout is specified, the system will wait for `timeout` seconds before returning. Timeout should be specified as a floating point number, or None, to wait indefinitely. Tr�N)r�r�)r{r�rR�wait�maxr�r�)r5rKr�� start_time� time_spentrs r8� get_messagezPubSub.get_messages����� �����J��$�)�)�'�2�2�d�:�:�"�Y�[�[�:�5� ��c�7�Z�#7�8�8����t��&�&�g��o��&�P�P�� � L��&�&�x�1J�K�K� K��tr*rEc�(�|�d|gndg}|j|�S)z' Ping the Redis server Nr��r)r5rEr�s r8�pingz PubSub.ping%s*��%,�$7��� � �f�X��#�t�#�T�*�*r*c�r�|�dSt|t��r|dkrd|gnddg}t|d��}|dkr||d|d|d d �}n'|d kr|dd|dd �}n|d|d|dd �}||jv�r|d krG|d}||jvr5|j�|��|j�|d��n�|d krG|d}||jvr5|j�|��|j �|d��nF|d}||j vr5|j �|��|j �|d��|j s'|js |j s|j � ��||jvr�|dkr"|j�|dd��}nI|dkr"|j �|dd��}n!|j �|dd��}|r ||��dSn|d kr |s|jrdS|S)z� Parses a pub/sub message. If the channel or pattern was subscribed to with a message handler, the handler is invoked instead of a parsed message being returned. NsPONGrOr*rrFr"rfr�)r��pattern�channelr/rNrIrJr�rGr�)r�r-r)�UNSUBSCRIBE_MESSAGE_TYPESri�removerhr[rgrfrercrRrj�PUBLISH_MESSAGE_TYPESrDrK) r5rrK� message_typerEr�� s_channelr��handlers r8r�zPubSub.handle_message,s��� � ��4� �h�� &� &� V�.6�'�.A�.A���*�*��QT�~�H�#�H�Q�K�0�0� � �:� %� %�$�#�A�;�#�A�;� �� � ��G�G� �V� #� #�$��� �� � ��G�G�%��#�A�;� �� � ��G� �4�9� 9� 9��~�-�-�"�1�+���d�?�?�?��5�<�<�W�E�E�E��M�%�%�g�t�4�4�4����/�/�$�Q�K� ��� G�G�G��;�B�B�9�M�M�M��'�+�+�I�t�<�<�<��"�1�+���d�?�?�?��5�<�<�W�E�E�E��M�%�%�g�t�4�4�4��=� .��� .�t�?R� .��%�+�+�-�-�-� �4�5� 5� 5��z�)�)��-�+�+�G�I�,>��E�E�����+�+��-�1�1�'�)�2D�d�K�K����-�+�+�G�I�,>��E�E��� ���� � � ��t� ��V� #� #�)� �D�,J� ��t��r*� sleep_time�daemon�exception_handler�PubSubWorkerThreadc��|j���D]\}}|�td|�d�����|j���D]\}}|�td|�d�����|j���D]\}}|�td|�d�����t ||||���}|���|S)Nz Channel: 'z' has no handler registeredz Pattern: 'zShard Channel: ')r�r�)rcr3rrhrfr��start) r5r�r�r�r�r�r�r��threads r8� run_in_threadzPubSub.run_in_threadvs�� !%� � 3� 3� 5� 5� U� U� �G�W���!�"S�w�"S�"S�"S�T�T�T�� $� � 3� 3� 5� 5� U� U� �G�W���!�"S�w�"S�"S�"S�T�T�T��"&�"5�";�";�"=�"=� � � �I�w���!�M�y�M�M�M����� $� �*�V�?P� � � �� � � ����� r*)NFNN)r0r�r)Tr)Fr�r2)F)r�FN)+rJrKrLrMr�r�rTrrr rrNr9r�r�r�rWr�ra�propertyr{rr�r�r�r�r�r}rr�rwrIrvrHrxrJrArr��get_sharded_messager�r�r�rSr*r8r�r��s/��������@�� O��2�� �*/�'+�@D� ��$(� � �)�$� � !��x���t� �'<�!<�=� ����8������������ &� &� &� &�����.�.�.�.�2�.�D�.�.�.��X�.�L�L�L�,����$ � � � �  �  �  �����6  �D�  �  �  �  � 4� 4� 4� 4�?�t�?�?�?�?����4 ;� ;� ;����4 :� :� :�-1������4/3� ;� ;� ;� ;� ;����IL���)-��@E�����:&��+�+�E�#�t�)�,�+��+�+�+�+�H�H�H�H�X ��04� ������$�H�-� � � �����r*r�c �h��eZdZ d dededeeeddgdfdff�fd� Zd d �Z d d �Z �xZ S) r�FNr�r�r�r�c���t�����||_||_||_||_t j��|_dSr2) r;r9r�r�r�r�rPrQ�_running)r5r�r�r�r�r>s �r8r9zPubSubWorkerThread.__init__�sK��� ���������� ��� �$���!2���!��)�)�� � � r*r0c��|j���rdS|j���|j}|j}|j���rh |�d|���n6#t $r)}|j��|�|||��Yd}~nd}~wwxYw|j����h|���dS)NT)rKr�) r�rzrdr�r�r�� BaseExceptionr�r�)r5r�r��es r8�runzPubSubWorkerThread.run�s��� �=� � � !� !� � �F� � ����������_� ��m�"�"�$�$� 8� 8��"�"�T�:�"�V�V�V�V�� � 8� 8� 8��)�1���&�&�q�&�$�7�7�7�7�7�7�7�7����� 8�����m�"�"�$�$� 8� � � �����s�A5�5 B(�?B#�#B(c�8�|j���dSr2)r�rjr�s r8�stopzPubSubWorkerThread.stop�s�� � �������r*)FNr) rJrKrLrrr rr]r9r�r�rOrPs@r8r�r��s�������� � �*�*��*�� *� !� �i��+?�@�$�F� G�� M� � *�*�*�*�*�*� � � � ��������r*r�c���eZdZdZhd�Zd�Zd d�Zd�Zd�Zde fd�Z de fd �Z d!d �Z d!d �Zd!d �Zd�Zd!d�Zd�Zd d�Zdefd�Zd�Zd�Zd�Zd�Zd�Zdededd fd�Zd"d�Zd�Zd�Z de fd�Z!d S)#r�a_ Pipelines provide a way to transmit multiple commands to the Redis server in one transmission. This is convenient for batch processing, such as saving all the values in a list to Redis. All commands executed within a pipeline are wrapped with MULTI and EXEC calls. This guarantees all commands executed in the pipeline will be executed atomically. Any command raising an exception does *not* halt the execution of subsequent commands in the pipeline. Instead, the exception is caught and its instance is placed into the response list returned by execute(). Code iterating over the response list should be able to deal with an instance of an exception as a potential value. In general, these will be ResponseError exceptions, such as those raised when issuing a command on a key of a different datatype. >�EXEC�DISCARD�UNWATCHc��||_d|_||_||_||_d|_|���dS)NF)rZr�r�r�r��watchingrW)r5rZr�r�r�s r8r9zPipeline.__init__�s@��.������"4���&���$����� � � � � � � � � r*r0c��|Sr2rSr�s r8r�zPipeline.__enter__�r�r*c�.�|���dSr2rZr�s r8r�zPipeline.__exit__�r�r*c�R� |���dS#t$rYdSwxYwr2r\r�s r8r�zPipeline.__del__�s:�� � �J�J�L�L�L�L�L��� � � � �D�D� ���r^c�*�t|j��Sr2)�len� command_stackr�s r8�__len__zPipeline.__len__�s���4�%�&�&�&r*c��dS)z1Pipeline instances should always evaluate to TrueTrSr�s r8�__bool__zPipeline.__bool__�s���tr*Nc��g|_t��|_|jre|jr^ |j�d��|j���n)#t$r|j���YnwxYwd|_d|_ |jr(|j � |j��d|_dSdS)Nr�F) r�rd�scriptsr�r�r�rrr��explicit_transactionrZr�r�s r8rWzPipeline.reset�s�������u�u�� � �=� -�T�_� -� -���,�,�Y�7�7�7���-�-�/�/�/�/��"� -� -� -���*�*�,�,�,�,�,� -������ �$)��!� �?� #� � � (� (��� 9� 9� 9�"�D�O�O�O� #� #s�3A�#B�Bc�.�|���dS)zClose the pipelineNrZr�s r8r�zPipeline.close�s�� � � � � � � � r*c�l�|jrtd���|jrtd���d|_dS)z� Start a transactional block of the pipeline after WATCH commands are issued. End the transactional block with `execute`. z"Cannot issue nested calls to MULTIz:Commands without an initial WATCH have already been issuedTN)r�rr�r�s r8�multizPipeline.multisO�� � $� C��A�B�B� B� � � ��L��� �%)��!�!�!r*c�j�|js |ddkr|js |j|i|��S|j|i|��S)Nr�WATCH)r�r��immediate_execute_command�pipeline_execute_command)r5r�r_s r8rzPipeline.execute_commandsS�� �M� C�T�!�W��/�/��9R�/�1�4�1�4�B�6�B�B� B�,�t�,�d�=�f�=�=�=r*c��|���|jr#|���td���|j�$t |t |j����dur|����dS)z� Close the connection, reset watching state and raise an exception if we were watching, if retry_on_error is not set or the error is not one of the specified error types. �=A ConnectionError occurred on while watching one or more keysNF)r�r�rWr!rsr�r�r�s r8�_disconnect_reset_raisez Pipeline._disconnect_reset_raises��� ������ �=� � �J�J�L�L�L��O��� � � � '��%��t�':�!;�!;�<�<��E�E� �J�J�L�L�L� �F�Er*c���������d��j��s'�j���j�����_�j������fd���fd���S)z� Execute a command immediately, but don't auto-retry on a ConnectionError if we're already WATCHing a variable. Used when issuing WATCH or subsequent commands retrieving their values but before MULTI is called. rc�(���j��g��Ri���Sr2rrs�����r8rz4Pipeline.immediate_execute_command.<locals>.<lambda>=s6���5�D�5��l��%)����-4���r*c�0�����|��Sr2)r�rs ��r8rz4Pipeline.immediate_execute_command.<locals>.<lambda>@s���$�6�6�t�U�C�C�r*)r�rZr�r�rtr )r5r�r�r�r�s```@@r8r�z"Pipeline.immediate_execute_command.s���������A�w� ����� #��'�6�6�|�T�_�U�U�D�"�D�O��z�)�)� � � � � � � � � D� C� C� C� C�  � � r*c�>�|j�||f��|S)ar Stage a command to be executed when execute() is next called Returns the current Pipeline object back so commands can be chained together, such as: pipe = pipe.set('foo', 'bar').incr('baz').decr('bang') At some other point, you can then run: pipe.execute(), which will execute all commands queued in the pipe. )r�r�rs r8r�z!Pipeline.pipeline_execute_commandCs$�� ��!�!�4��/�2�2�2�� r*c�.�tdifg|difg��}|�d�|D����}|�|��g} |�|d��n.#t$r!}|�d|f��Yd}~nd}~wwxYwt |��D]�\}} t| dvr)|�|| dtf���= |�|d���U#t$rA}|�||dz| d��|�||f��Yd}~��d}~wwxYw |�|d��} n#t$r|r|dd��wxYwd|_ | �td���|D]\}}| � ||���t| ��t|��kr(|j���t d ���|r|�|| ��g} t#| |��D]o\} } t%| t&��s@| \}}|�d d��|d}||jvr|j|| fi|��} | �| ���p| S) N)�MULTI)r�c�*�g|]\}}t|v�|��SrS)r+)rqr�r�s r8� <listcomp>z1Pipeline._execute_transaction.<locals>.<listcomp>Us&�� M� M� M�m�d�G�~�W�/L�/L�T�/L�/L�/Lr*r�rr"FzWatched variable changed.z6Wrong number of response items from pipeline executionr )r� pack_commands�send_packed_commandr�rr�� enumerater+�annotate_exceptionrr�r!�insertr�r�r��raise_first_error�zipr�r]r[r�)r5r��commands�raise_on_error�cmds�all_cmdsr�r��ir�rr/�r�cmdr�r�r�s r8�_execute_transactionzPipeline._execute_transactionRs0���z�2�&�'��Y��O�3D�E�E���+�+� M� M�t� M� M� M� � �� �&�&�x�0�0�0���  "� � � � �C� 0� 0� 0� 0��� "� "� "� �M�M�1�a�&� !� !� !� !� !� !� !� !����� "����$�H�-�-� *� *�J�A�w�����+�+�� � �q�'�!�*�^�"<�=�>�>�>�>�*��'�'� �C�8�8�8�8��$�*�*�*��+�+�A�q�1�u�g�a�j�A�A�A��M�M�1�a�&�)�)�)�)�)�)�)�)�����*����  ��*�*�:�s�;�;�H�H��� � � �� #��Q�i��l�"� � ���� �� � � ��8�9�9� 9�� "� "�D�A�q� �O�O�A�q� !� !� !� !� �x�=�=�C��M�M� )� )� �O� &� &� (� (� (��H��� � � 7� � "� "�8�X� 6� 6� 6����(�H�-�-� � �F�A�s��a��+�+� L� #� ��g�� � �F�D�)�)�)�#�A�w� ��4�#:�:�:�=��/� �=�a�K�K�7�K�K�A� �K�K��N�N�N�N�� s<�A&�& B�0B � B�!C8�8 E�7D>�>E�E�E:c�\�|�d�|D����}|�|��g}|D]Z\}} |�|j||dfi|�����/#t$r}|�|��Yd}~�Sd}~wwxYw|r|�||��|S)Nc��g|]\}}|��SrSrS)rqr�r�s r8r�z.Pipeline._execute_pipeline.<locals>.<listcomp>�s��,J�,J�,J�g�d�A�T�,J�,J�,Jr*r)rrr�r�rr) r5r�rrr rr�r�r�s r8�_execute_pipelinezPipeline._execute_pipeline�s����+�+�,J�,J��,J�,J�,J�K�K���&�&�x�0�0�0���%� #� #�M�D�'� #���� 3�� 3�J��Q�� S� S�7� S� S�T�T�T�T�� � #� #� #�����"�"�"�"�"�"�"�"����� #���� � 7� � "� "�8�X� 6� 6� 6��s�(A(�( B�2B � Bc��t|��D]B\}}t|t��r(|�||dz||d��|��CdS)Nr"r)rr�rr)r5rrr r s r8rzPipeline.raise_first_error�sg���h�'�'� � �D�A�q��!�]�+�+� ��'�'��1�q�5�(�1�+�a�.�A�A�A��� � � r*c��d�tt|����}d|�d|�d|jd��}|f|jdd�z|_dS)Nr!z Command # z (z) of pipeline caused error: rr")r4�mapr(r�)r5� exception�numberr�r �msgs r8rzPipeline.annotate_exception�sr���h�h�s�8�W�-�-�.�.�� 1�� 1� 1�3� 1� 1�&�^�A�.� 1� 1� ���)�.����"4�4� ���r*c �j�tj|||fi|��}||jvrd|_n |dkrd|_|S)NFr�T)rUr��UNWATCH_COMMANDSr�)r5r�r�r��results r8r�zPipeline.parse_response�sL���%�d�J� �P�P��P�P�� �4�0� 0� 0�!�D�M�M� �W� $� $� �D�M�� r*c���t|j��}|j}d�|D��}|dg|�R�}t|��s.t ||��D]\}}|s|d|j��|_�dSdS)Nc��g|] }|j�� SrS)�sha)rq�ss r8r�z)Pipeline.load_scripts.<locals>.<listcomp>�s��'�'�'�!���'�'�'r*z SCRIPT EXISTSz SCRIPT LOAD)�listr�r��allr�scriptr)r5r�� immediate�shas�existsr�exists r8� load_scriptszPipeline.load_scripts�s����t�|�$�$���2� �'�'�w�'�'�'����?�2�T�2�2�2���6�{�{� ?����0�0� ?� ?���5��?�%�I�m�Q�X�>�>�A�E�� ?� ?� ?� ?r*r�r�c���|���|jrtd���|j�$t |t |j����dur|���|�dS)z� Close the connection, raise an exception if we were watching, and raise an exception if retry_on_error is not set or the error is not one of the specified error types. r�NF)r�r�r!rsr�r�rWr�s r8�_disconnect_raise_resetz Pipeline._disconnect_raise_reset�s}�� ������ �=� ��O��� � � � '��%��t�':�!;�!;�<�<��E�E� �J�J�L�L�L��K� F�Er*Tc��������j��s �jsgS�jr�����js�jr�j�n�j��j��s'�j � d�j �����_ �j � ����fd���fd�������S#����wxYw)z0Execute all the commands in the current pipeliner�c���������Sr2rS)r�r�r�stacks����r8rz"Pipeline.execute.<locals>.<lambda>�s������e�^�<�<�r*c�0�����|��Sr2)r(rs ��r8rz"Pipeline.execute.<locals>.<lambda>�s���d�:�:�4��G�G�r*)r�r�r�r&r�r�rrr�rZr�r�rtr rW)r5rr�r�r+s``@@@r8r�zPipeline.execute�s���������"��� �T�]� ��I� �<� � � � � � � � � � -�t�8� -��/�G�G��,�G����� #��'�6�6�w���P�P�D�#�D�O� ��:�-�-�<�<�<�<�<�<�<�G�G�G�G�G��� �J�J�L�L�L�L��D�J�J�L�L�L�L���s �$B:�:Cc�0�|�d��dS)zg Flushes all previously queued commands See: https://redis.io/commands/DISCARD r�Nr�r�s r8�discardzPipeline.discards�� ���Y�'�'�'�'�'r*c�J�|jrtd���|jdg|�R�S)z$Watches the values at keys ``names``z"Cannot issue a WATCH after a MULTIr�)r�rr)r5�namess r8r�zPipeline.watchs8�� � $� C��A�B�B� B�#�t�#�G�4�e�4�4�4�4r*c�>�|jr|�d��pdS)z'Unwatches all previously specified keysr�T)r�rr�s r8�unwatchzPipeline.unwatchs"���}�@��!5�!5�i�!@�!@�H�D�Hr*rr)T)"rJrKrLrMrr9r�r�r�rr�rr�rWr�r�rr�r�r�rrrrrr�r&rr]r(r�r.r�r2rSr*r8r�r��s��������$6�5�5��������������� '��'�'�'�'��$�����#�#�#�#�.���� )� )� )� )�>�>�>� ����2 � � �* � � � �C�D�C�C�C�C�J��� ��� 5�5�5���� ?� ?� ?�� ���� � ����8����6(�(�(�5�5�5� I��I�I�I�I�I�Ir*r�)Dr�rBrPr�r�� itertoolsr�typingrrrrrr r �redis._parsers.encodersr �redis._parsers.helpersr r rr� redis.cacherr�redis.commandsrrrr�redis.connectionrrrr�redis.credentialsr�redis.exceptionsrrrrrr r!� redis.lockr#� redis.retryr$� redis.utilsr%r&r'r(r)� SYM_EMPTYr+r,r�r.rRrU� StrictRedisr�r��Threadr�r�rSr*r8�<module>rBs��� � � � � � � � ����� � � � �����������C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�C�+�+�+�+�+�+������������� 4�3�3�3�3�3�3�3������������� ������������ 1�0�0�0�0�0��������������������������������������������� � �!��� ������$����6 � � � � � � � �B*�B*�B*�B*�B*� ��/?�B*�B*�B*�J� �@&�@&�@&�@&�@&�@&�@&�@&�Fj�j�j�j�j�j�j�j�Z$�$�$�$�$��)�$�$�$�NZI�ZI�ZI�ZI�ZI�u�ZI�ZI�ZI�ZI�ZIr*
Memory