
    ph                     f   S SK r S SKrS SKrS SKrS SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJrJrJrJr  S SKJrJ r J!r!J"r"  S SK#J$r$  S SK%J&r&  S SK'J(r(  S SK)J*r*J+r+J,r,J-r-  S S	K.J/r/J0r0J1r1J2r2  S S
K3J4r4  S SK5J6r6J7r7J8r8J9r9J:r:  S SK;J<r<J=r=J>r>J?r?J@r@JArA  S SKBJCrCJDrDJErE  S SKFJGrGJHrHJIrIJJrJJKrKJLrLJMrMJNrN  \(       a  \G(       a  S SKOJPrPJQrQJRrR  OSrPSrRSrQ\
\\S\S4   /\	S   4   rT\" S\ES9rU\" S\E\D5      rV\" SSS9rW\" S\\C\X4   S9rY\(       a  S SKZJ[r[   " S S\5      r\ " S S\5      r]\\\\]4   r^ " S S\,\0\/\15      r_\_r` " S S\5      ra " S S5      rb " S  S!5      rc " S" S#\5      rd " S$ S%\5      re\\d\e4   rf\\\\S\g4   S&4   \\S\4   4   rh\\h   ri " S' S(\_5      rjg))    N)TYPE_CHECKINGAnyAsyncIterator	AwaitableCallableDictIterableListMappingMutableMappingOptionalProtocolSetTupleType	TypedDictTypeVarUnioncast)_RedisCallbacks_RedisCallbacksRESP2_RedisCallbacksRESP3bool_ok)
ConnectionConnectionPoolSSLConnectionUnixDomainSocketConnectionLock)Retry)ExponentialWithJitterBackoff)EMPTY_RESPONSENEVER_DECODEAbstractRedisCaseInsensitiveDict)AsyncCoreCommandsAsyncRedisModuleCommandsAsyncSentinelCommandslist_or_args)CredentialProvider)(AfterPooledConnectionsInstantiationEvent'AfterPubSubConnectionInstantiationEvent'AfterSingleConnectionInstantiationEvent
ClientTypeEventDispatcher)ConnectionErrorExecAbortErrorPubSubError
RedisErrorResponseError
WatchError)ChannelT
EncodableTKeyT)SSL_AVAILABLE_set_info_loggerdeprecated_argsdeprecated_functionget_lib_versionsafe_strstr_if_bytestruncate_text)
TLSVersionVerifyFlags
VerifyMode_KeyT)bound_ArgT_RedisTRedis_NormalizeKeysT)Scriptc                   "    \ rS rSrS\4S jrSrg)ResponseCallbackProtocolc   responsec                     g N selfrN   kwargss      N/home/james-whalen/.local/lib/python3.13/site-packages/redis/asyncio/client.py__call__!ResponseCallbackProtocol.__call__d   s        rQ   N__name__
__module____qualname____firstlineno__r   rV   __static_attributes__rQ   rX   rU   rL   rL   c   s
    44rX   rL   c                   "    \ rS rSrS\4S jrSrg)AsyncResponseCallbackProtocolg   rN   c                    #    g 7frP   rQ   rR   s      rU   rV   &AsyncResponseCallbackProtocol.__call__h   s     s   rQ   NrY   rQ   rX   rU   r`   r`   g   s
    :s:rX   r`   c            O          \ rS rSr% Sr\\\\4   \	4   \
S'   \  S}S\S\S\\   4S	 jj5       r\S
\S    S\SS 4S j5       r\" S/SSS9SSSSSSSSSSSSSS\" \" SSS9SS9SSSSSSSSSSSSSSSSS\" 5       SSSSSSS .'S!\S"\S#\\\4   S$\\   S%\\   S&\\   S'\\   S(\\\\\\4   4      S\\   S)\\   S*\S+\S,\S\S-\S.\\   S/\S0\\   S1\\   S2\\\4   S3\\\      S4\\\      S5\\   S6\\   S7\S8\\   S9\\   S:\\   S\S;\S<\\   S=\\   S>\\   S?\\   S\\   S@\\   SA\\   SB\\   4LSC jj5       r SD r!SE r"SF\#S\#4SG jr$SH\SI\	4SJ jr%SK r&SL r'S\\   4SM jr(S-\SS4SN jr)SO r* S~SP\SQ\\   SSR4SS jjr+SSSST.SU\,SR/\\-\.\-   4   4   SV\/SQ\\   SW\SX\\   4
SY jjr0       SSZ\/S[\\   S\\S]\S^\\   S_\\\1      S`\Sa\S\14Sb jjr2SSc jr3SSd jr4SSe jr5SF\#S\#4Sf jr6S\4Sg jr7S\4Sh jr8Si r9Sjr:\;Rx                  \=R|                  4Sk\-Sl\-SS4Sm jjr?SSn\\   SS4So jjr@\A" SpSqSrSs9SSn\\   SS4St jj5       rBSu rCSv\D4Sw jrESx rFSy\DSz\\\4   4S{ jrGS|rHg)rH   n   an  
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.
response_callbacksFNurlsingle_connection_clientauto_close_connection_poolc                     [         R                  " U40 UD6nU " UUS9nUb   [        R                  " [	        S5      5        OSnX6l        U$ )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.

connection_poolri   "auto_close_connection_pool" is deprecated since version 5.0.1. Please create a ConnectionPool explicitly and provide to the Redis() constructor instead.T)r   from_urlwarningswarnDeprecationWarningrj   )clsrh   ri   rj   rT   rm   clients          rU   ro   Redis.from_url   s_    d )11#@@+%=
 &1MM"B *.&,F)rX   rs   rm   returnc                      U " US9nSUl         U$ )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.
)rm   T)rj   )rs   rm   rt   s      rU   	from_poolRedis.from_pool   s      +
 -1)rX   retry_on_timeoutz$TimeoutError is included by default.z6.0.0)args_to_warnreasonversion	localhosti  r   zutf-8strict   
   )basecap   )backoffretriesrequiredTzredis-py   )'hostportdbpasswordsocket_timeoutsocket_connect_timeoutsocket_keepalivesocket_keepalive_optionsrm   unix_socket_pathencodingencoding_errorsdecode_responsesrz   retryretry_on_errorsslssl_keyfilessl_certfilessl_cert_reqsssl_include_verify_flagsssl_exclude_verify_flagsssl_ca_certsssl_ca_datassl_check_hostnamessl_min_versionssl_ciphersmax_connectionsri   health_check_intervalclient_namelib_namelib_versionusernamerj   redis_connect_funccredential_providerprotocolevent_dispatcherr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   c       '            U'c  [        5       U l        OU'U l        U#b   [        R                  " [	        S5      5        OSn#U	(       d  U(       d  / n0 SU_SU"_SU_SU%_SU_S	U_S
U_SU_SU_S[
        R                  " U5      _SU_SU_SU_SU _SU!_SU$_SU&_n(U
b  U(R                  U
[        S.5        O?U(R                  UUUUUS.5        U(       a!  U(R                  [        UUUUUUUUUUS.5        U#U l
        [        S0 U(D6n	U R                  R                  [        U	/[        R                  U%5      5        O<SU l
        U R                  R                  [        U	/[        R                  U%5      5        Xl        UU l        SU l        ['        [(        5      U l        U R                   R,                  R/                  S5      S;   a   U R*                  R                  [0        5        OU R*                  R                  [2        5        [4        R6                  " 5       U l        SU l        [4        R6                  " 5       U l        g)aE  
Initialize a new Redis client.

To specify a retry policy for specific errors, you have two options:

1. Set the `retry_on_error` to a list of the error/s to retry on, and
you can also set `retry` to a valid `Retry` object(in case the default
one is not appropriate) - with this approach the retries will be triggered
on the default errors specified in the Retry object enriched with the
errors specified in `retry_on_error`.

2. Define a `Retry` object with configured 'supported_errors' and set
it to the `retry` parameter - with this approach you completely redefine
the errors on which retries will happen.

`retry_on_timeout` is deprecated - please include the TimeoutError
either in the Retry object or in the `retry_on_error` list.

When 'connection_pool' is provided - the retry configuration of the
provided pool will be used.
Nrn   Tr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )pathconnection_class)r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   F)3r   r   rQ   )r/   _event_dispatcherrp   rq   rr   copydeepcopyupdater   r   rj   r   dispatchr+   r.   ASYNCrm   ri   
connectionr%   r   rg   connection_kwargsgetr   r   asyncior   _single_conn_lock_usage_counter_usage_lock))rS   r   r   r   r   r   r   r   r   rm   r   r   r   r   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ri   r   r   r   r   r   rj   r   r   r   r   rT   s)                                            rU   __init__Redis.__init__   s   P #%4%6D"%5D" &1MM"B *.&!!#bH H &':	
 !. H "? #$4 !. u- "? ()> { H {  %&8!" H#F(  + 0,F  $ $2H,<4L MM0=+6,8-:8P8P,8+62D/>+6  /ID+,6v6O""++8$%z'7'79L /4D+""++8$%z'7'79L  /(@%04"5o"F1155jAXM##**+?@##**+?@
 ")
  "<<>rX   c                     SU R                   R                   SU R                   R                   SU R                  < S3$ )N<.(z)>)	__class__r[   rZ   rm   rS   s    rU   __repr__Redis.__repr__  s?    ))*!DNN,C,C+D$$'r+	
rX   c                 >    U R                  5       R                  5       $ rP   )
initialize	__await__r   s    rU   r   Redis.__await__  s     **,,rX   rS   c                   #    U R                   (       a  U R                   IS h  vN   U R                  c'  U R                  R	                  5       I S h  vN U l        S S S 5      IS h  vN   U R
                  R                  [        U R                  [        R                  U R                  5      5        U $  N Ne NR! , IS h  vN  (       d  f       Ng= f7frP   )
ri   r   r   rm   get_connectionr   r   r-   r.   r   r   s    rU   r   Redis.initialize  s     ((---??*,0,@,@,O,O,Q&QDO .- ""++7OOZ%5%5t7M7M
  .&Q .---sW   "CB7C+B=B9	B=C(B;)AC9B=;C=CCCCcommandcallbackc                      X R                   U'   g)zSet a custom Response CallbackN)rg   )rS   r   r   s      rU   set_response_callbackRedis.set_response_callback  s    +3(rX   c                 6    U R                   R                  5       $ )z!Get the connection pool's encoder)rm   get_encoderr   s    rU   r   Redis.get_encoder  s    ##//11rX   c                 .    U R                   R                  $ )z'Get the connection's key-word arguments)rm   r   r   s    rU   get_connection_kwargsRedis.get_connection_kwargs  s    ##555rX   c                 @    U R                  5       R                  S5      $ Nr   )r   r   r   s    rU   	get_retryRedis.get_retry  s    ))+//88rX   c                 |    U R                  5       R                  SU05        U R                  R                  U5        g r   )r   r   rm   	set_retry)rS   r   s     rU   r   Redis.set_retry  s2    ""$++We,<=&&u-rX   c                     [        XU5        g)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)rS   funcnamefuncs      rU   load_external_moduleRedis.load_external_module  s    * 	%rX   transaction
shard_hintPipelinec                 D    [        U R                  U R                  X5      $ )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   rm   rg   )rS   r   r   s      rU   pipelineRedis.pipeline  s$       $"9"9;
 	
rX   )r   value_from_callablewatch_delayr   watchesr   r   c                  #    U R                  SU5       ISh  vN n  U(       a  UR                  " U6 I Sh  vN   U" U5      n[        R                  " U5      (       a
  UI Sh  vN nUR	                  5       I Sh  vN nU(       a  UOU sSSS5      ISh  vN   $  N Nh N= N' N! [
         a,    Ub%  US:  a  [        R                  " U5      I Sh  vN     M  f = f! , ISh  vN  (       d  f       g= f7f)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.
TNr   )r   watchinspectisawaitableexecuter5   r   sleep)	rS   r   r   r   r   r   pipe
func_value
exec_values	            rU   r   Redis.transaction  s      ==z22d"jj'222!%dJ**:66+5%5
'+||~!5J)<:*L 322 3 &6!5 3 " ".;?%mmK888 322s   C=B C=C#B*B",B*&B$'B*>B&?B*C=B(C="B*$B*&B*(C=*,C CC C#C  C##C:)C,*C:6C=nametimeoutr   blockingblocking_timeout
lock_classthread_localraise_on_release_errorc	                 .    Uc  [         nU" U UUUUUUUS9$ )a  
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.

``raise_on_release_error`` indicates whether to raise an exception when
the lock is no longer owned when exiting the context manager. By default,
this is True, meaning an exception will be raised. If False, the warning
will be logged and the exception will be suppressed.

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.)r   r   r   r   r   r   r   )	rS   r   r   r   r   r   r   r   r   s	            rU   lock
Redis.lock  s5    H J-%#9	
 		
rX   c                 F    [        U R                  4SU R                  0UD6$ )z
Return a Publish/Subscribe object. With this object, you can
subscribe to channels and listen for messages that get published to
them.
r   )PubSubrm   r   )rS   rT   s     rU   pubsubRedis.pubsubM  s0       
373I3I
MS
 	
rX   c                 ,    [        U R                  5      $ rP   )Monitorrm   r   s    rU   monitorRedis.monitorW  s    t++,,rX   c                 6    U R                  U R                  SS9$ )NTrl   )r   rm   r   s    rU   rt   Redis.clientZ  s#    ~~ 004  
 	
rX   c                    #    U R                  5       I Sh  vN    U R                  5       I Sh  vN $  N N! [         a    U R                  5       I Sh  vN    e f = f7f)z
Async context manager entry. Increments a usage counter so that the
connection pool is only closed (via aclose()) when no context is using
the client.
N)_increment_usager   	Exception_decrement_usager   s    rU   
__aenter__Redis.__aenter___  s[      ##%%%	*** 	& + 	'')))	s:   A 4A 8 68 A 8 AAAA c                    #    U R                    ISh  vN   U =R                  S-  sl        U R                  sSSS5      ISh  vN   $  N6 N! , ISh  vN  (       d  f       g= f7f)zu
Helper coroutine to increment the usage counter while holding the lock.
Returns the new value of the usage counter.
Nr   r   r   r   s    rU   r  Redis._increment_usagen  A     
 ###1$&& $#####C   A(A
A(!AA(AA(A(A%AA%!A(c                    #    U R                    ISh  vN   U =R                  S-  sl        U R                  sSSS5      ISh  vN   $  N6 N! , ISh  vN  (       d  f       g= f7f)zu
Helper coroutine to decrement the usage counter while holding the lock.
Returns the new value of the usage counter.
Nr   r  r   s    rU   r  Redis._decrement_usagew  r  r  c                    #    [         R                  " U R                  5       5      I Sh  vN nUS:X  a-  [         R                  " U R                  5       5      I Sh  vN   gg N8 N7f)z
Async context manager exit. Decrements a usage counter. If this is the
last exit (counter becomes zero), the client closes its connection pool.
Nr   )r   shieldr  aclose)rS   exc_type	exc_value	tracebackcurrent_usages        rU   	__aexit__Redis.__aexit__  sQ     
 &nnT-B-B-DEEA..///  F 0s!   (A'A#1A'A%A'%A'zUnclosed Redis client_warn_grlc                    [        U S5      (       a^  U R                  bP  U" SU < 3[        U S9   X R                  S.nU" 5       R	                  U5        U R                  R                  5         g g g ! [
         a     N)f = f)Nr   zUnclosed client session )source)rt   message)hasattrr   ResourceWarning_DEL_MESSAGEcall_exception_handlerRuntimeError_close)rS   r#  r$  contexts       rU   __del__Redis.__del__  s    
 4&&DOO,G,TH5tT%)6G6GH--g6 OO""$ -H&
   s   $A1 1
A>=A>close_connection_poolc                   #    U R                   nU(       a*  SU l         U R                  R                  U5      I Sh  vN   U(       d  Uc5  U R                  (       a#  U R                  R	                  5       I Sh  vN   ggg ND N	7f)a5  
Closes Redis client connection

Args:
    close_connection_pool:
        decides whether to close the connection pool used by this Redis client,
        overriding Redis.auto_close_connection_pool.
        By default, let Redis.auto_close_connection_pool decide
        whether to close the connection pool.
N)r   rm   releaserj   
disconnect)rS   r1  conns      rU   r  Redis.aclose  sp      "DO&&..t444 !)d.M.M&&11333 /N) 5 4s!   9BB <B8B9BB5.0.1Use aclose() insteadcloser}   r|   r   c                 B   #    U R                  U5      I Sh  vN   g N7f)z1
Alias for aclose(), for backwards compatibility
Nr  )rS   r1  s     rU   r9  Redis.close  s     
 kk/000   c                 v   #    UR                   " U6 I Sh  vN   U R                  " X40 UD6I Sh  vN $  N N7f)z'
Send a command and parse the response
N)send_commandparse_response)rS   r5  command_nameargsoptionss        rU   _send_command_parse_response"Redis._send_command_parse_response  s<      &&&((GwGGG 	'Gs   959799r5  c                 @   #    UR                  5       I Sh  vN   g N7f)a  
Close the connection before retrying.

The supported exceptions are already checked in the
retry object so we don't need to do it here.

After we disconnect the connection, it will try to reconnect and
do a health check as part of the send_command logic(on connection level).
N)r4  rS   r5  s     rU   _close_connectionRedis._close_connection  s      oo   c                   ^ ^^^^#    T R                  5       I Sh  vN   T R                  nTS   mT R                  =(       d    UR                  5       I Sh  vN mT R                  (       a"  T R
                  R                  5       I Sh  vN    TR                  R                  UUUUU 4S jUU 4S j5      I Sh  vN T R                  (       a  T R
                  R                  5         T R                  (       d  UR                  T5      I Sh  vN   $ $  N N N N` N! T R                  (       a  T R
                  R                  5         T R                  (       d  UR                  T5      I Sh  vN    f f = f7f)z.Execute a command and return a parsed responseNr   c                  2   > TR                   " TT/T Q70 TD6$ rP   rE  rC  rB  r5  rD  rS   s   rU   <lambda>'Redis.execute_command.<locals>.<lambda>  s%    99,)-18rX   c                 &   > TR                  T5      $ rP   )rI  _r5  rS   s    rU   rP  rQ    s    $006rX   )
r   rm   r   r   ri   r   acquirer   call_with_retryr3  )rS   rC  rD  poolrB  r5  s   ``` @@rU   execute_commandRedis.execute_command  s     oo##Aw=(;(;(="=((((00222	)33  7	  ,,&&..0??ll4((( ## 	  #> 3 ) ,,&&..0??ll4((( #s}   E=D;E=D2E=
DE=,D! <D=D!  AE=DE=E=E=D! E=!AE:2E53E::E=r   rB  c                   #     [         U;   a-  UR                  SS9I Sh  vN nUR                  [         5        OUR                  5       I Sh  vN n [        U;   a  UR                  [        5        UR                  SS5        X R
                  ;   aM  [        [        U5      nU R
                  U   " U40 UD6n[        R                  " U5      (       a
  UI Sh  vN $ U$ U$  N N! [         a    [        U;   a  U[           s $ e f = f N07f)z'Parses a response from the Redis serverT)disable_decodingNkeys)
r#   read_responsepopr4   r"   rg   r   strr   r   )rS   r   rB  rD  rN   retvals         rU   rA  Redis.parse_response  s     		w&!+!9!94!9!PPL)!+!9!9!;; W$KK' 	FD!222\2L,,\:8OwOF#*#6#6v#>#><JFJ) Q < 	(~..	  sa   DC' C#C' DC' C%C' BDDD#C' %C' 'DDDD)	r   r   r   r   rj   r   rm   rg   ri   )FN)TN)Ng?TNNTT)rv   r  )rv   r  )rv   rH   rP   )IrZ   r[   r\   r]   __doc__r   r   r_  bytesResponseCallbackT__annotations__classmethodboolr   ro   r   r   rx   r;   r    r!   r=   intfloatr   listrC   r
   rB   rA   r*   r/   r   r   r   rG   r   r   r   r   r   r   r   r   r   r   r   r8   r   r   r  r  r	  rt   r  r  r  r!  r*  rp   rq   r   get_running_loopr/  r  r<   r9  rE  r   rI  rX  rA  r^   rQ   rX   rU   rH   rH   n   s   
 'uS%Z'8:K'KLL */59	BB #'B %-TN	B BH ']' 
  ()5  "&*.26+/NR48*.'!&!&0aR@!
 *.%)&*0:@D@D&*%)#'04%))-).%&%)",%4%6"&59<@"#6:Wv* v* 	v*
 #s(Ov* 3-v* !v* !)v* #4.v* #+73c5j8I3I+J"Kv* ".1v* #3-v* v* v* v*  !v*" #v*( !)v** +v*, c]-v*. sm/v*0 S*_-1v*2 #+4+<"=3v*4 #+4+<"=5v*6 sm7v*8 c]9v*: !;v*< "*-=v*> c]?v*@ "#Av*B #'Cv*D  #Ev*F c]Gv*H 3-Iv*J c]Kv*L 3-Mv*N %-TNOv*R &&89Sv*T 3-Uv*V #?3Wv*
v*p
-w 7 4S 4<M 42698E? 9.u . .&0 EI

4<SM
	
$ %)$)'+
|U3	#+>%??@  SM	
 " e_@ $(,0+/!'+O
O
 %O
 	O

 O
 #5/O
 T$Z(O
 O
 !%O
 
O
b
-

w 7 ' '' '0 +L ]],,%% % 
	%4(4. 4D 4( 1GgV1$ 14 1 W1H
 J 
 ),$49#u*4ErX   c                   R    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   Srg	)
MonitorCommandInfoi  timer   client_addressclient_portclient_typer   rQ   N)	rZ   r[   r\   r]   ri  re  rh  r_  r^   rQ   rX   rU   rm  rm    s#    
KGLrX   rm  c                       \ rS rSrSr\R                  " S5      r\R                  " S5      rS\	4S jr
S rS rS	 rS
\4S jrS
\\   4S jrSrg)r  i
  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"(.*?)(?<!\\)"rm   c                     Xl         S U l        g rP   )rm   r   )rS   rm   s     rU   r   Monitor.__init__  s    .04rX   c                 z   #    U R                   c(  U R                  R                  5       I S h  vN U l         g g  N7frP   )r   rm   r   r   s    rU   connectMonitor.connect  s0     ??"$($8$8$G$G$IIDO #Is   +;9;c                   #    U R                  5       I S h  vN   U R                  R                  S5      I S h  vN   U R                  R                  5       I S h  vN n[	        U5      (       d  [        SU 35      eU $  Ni NH N(7f)NMONITORzMONITOR failed: )rv  r   r@  r]  r   r3   rS   rN   s     rU   r  Monitor.__aenter__  so     llnoo**95556688x  /z:;; 	58s1   BB "BB!BB%BBBc                    #    U R                   R                  5       I S h  vN   U R                  R                  U R                   5      I S h  vN   g  N2 N7frP   )r   r4  rm   r3  )rS   rC  s     rU   r!  Monitor.__aexit__%  sA     oo((***""**4??;;; 	+;s!   AA,AAAArv   c                   #    U R                  5       I Sh  vN   U R                  R                  5       I Sh  vN n[        U[        5      (       a$  U R                  R
                  R                  USS9nUR                  SS5      u  p#U R                  R                  U5      nUR                  5       u  pVnSR                  U R                  R                  U5      5      nUR                  SS5      nUS:X  a  SnS	n	Sn
O6UR                  S
5      (       a
  S
nUSS n	S
n
OUR!                  SS5      u  pSn
[#        U5      [%        U5      UU	U
US.$  GN< GN7f)z)Parse the response from a monitor commandNTforce r   z\""lua unix   :tcp)rn  r   ro  rp  rq  r   )rv  r   r]  
isinstancerc  encoderdecodesplit
monitor_rematchgroupsjoin
command_refindallreplace
startswithrsplitri  rh  )rS   rN   command_timecommand_datamdb_idclient_infor   ro  rp  rq  s              rU   next_commandMonitor.next_command)  sA    lln6688h&&..55hd5KH%-^^C%;"OO!!,/&'hhj#G((4??227;< //%-%"NKK##F++#N%ab/K K +6*<*<S!*D'NK,'e*,&&
 	
3 	8s    EE!EEDEEc                J   #     U R                  5       I Sh  vN 7v   M   N	7f)z)Listen for commands coming to the server.N)r  r   s    rU   listenMonitor.listenM  s"     ))+++ +s   #!
#)r   rm   N)rZ   r[   r\   r]   rb  recompiler  r  r   r   rv  r  r!  rm  r  r   r  r^   rQ   rX   rU   r  r  
  sc     34J-.J5 5J<"
$6 "
H,m,>? ,rX   r  c                      \ rS rSrSrSrSrSr     S8S\S\	\
   S	\S
\	\   S\	S   4
S jjrS rS rS rS r\" SSSS9S9S j5       r\" SSSS9S9S j5       rS\4S jr\S 5       rS\4S jrS rS  rS! rS:S"\S#\4S$ jjrS% r S&\!S\!4S' jr"S\#S(\$4S) jr%S\#S\&4S* jr'S\#S(\4S+ jr(S\&4S, jr)S\*4S- jr+ S;S	\S#\	\   4S. jjr,S<S\&\   4S/ jjr-S=S0 jr.SS1SS2.S3\	S4   S5\SS4S6 jjr/S7r0g)>r  iS  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.
)r'  pmessage)unsubscribepunsubscribezredis-py-health-checkNrm   r   ignore_subscribe_messagespush_handler_funcr   r/   c                    Uc  [        5       U l        OX`l        Xl        X l        X0l        S U l        X@l        XPl        U R                  c  U R                  R                  5       U l        U R                  R                  (       a   SU R                  /U R                  /U l        OQSU R                  R                  U R                  5      /U R                  R                  U R                  5      /U l        U R                  c
  [        5         0 U l        [        5       U l        0 U l        [        5       U l        [&        R(                  " 5       U l        g )Npong   pong)r/   r   rm   r   r  r   r  r  r   r   HEALTH_CHECK_MESSAGEhealth_check_responseencoder:   channelssetpending_unsubscribe_channelspatternspending_unsubscribe_patternsr   r   _lock)rS   rm   r   r  r  r  r   s          rU   r   PubSub.__init__`  s    #%4%6D"%5".$)B& !2<<//;;=DL<<((223))*D& $,,--d.G.GHI##D$=$=>*D& !!),/E),/E)\\^
rX   c                    #    U $ 7frP   rQ   r   s    rU   r  PubSub.__aenter__  
        c                 @   #    U R                  5       I S h  vN   g  N7frP   r<  rS   r  r  r  s       rU   r!  PubSub.__aexit__  s     kkmrK  c                 r    U R                   (       a&  U R                   R                  U R                  5        g g rP   )r   deregister_connect_callback
on_connectr   s    rU   r/  PubSub.__del__  s$    ??OO77H rX   c                 .  #    [        U S5      (       d  g U R                   IS h  vN   U R                  (       a{  U R                  R                  5       I S h  vN   U R                  R	                  U R
                  5        U R                  R                  U R                  5      I S h  vN   S U l        0 U l        [        5       U l
        0 U l        [        5       U l        S S S 5      IS h  vN   g  N N NL N! , IS h  vN  (       d  f       g = f7f)Nr   )r(  r  r   r4  r  r  rm   r3  r  r  r  r  r  r   s    rU   r  PubSub.aclose  s      t\**:::oo00222;;DOOL**224??CCC"&DM03D-DM03D- ::2C	 :::si   #DC3D/C;C5AC;*C7+7C;"D-C9.D5C;7C;9D;DDDDr7  r8  r9  r:  rv   c                 @   #    U R                  5       I Sh  vN   g N7fz/Alias for aclose(), for backwards compatibilityNr<  r   s    rU   r9  PubSub.close        kkmrK  resetc                 @   #    U R                  5       I Sh  vN   g N7fr  r<  r   s    rU   r  PubSub.reset  r  rK  r   c                 .  #    U R                   R                  5         U R                  R                  5         U R                  (       a[  0 nU R                  R	                  5        H!  u  p4XBU R
                  R                  USS9'   M#     U R                  " S0 UD6I Sh  vN   U R                  (       a\  0 nU R                  R	                  5        H!  u  p4XEU R
                  R                  USS9'   M#     U R                  " S0 UD6I Sh  vN   gg Nr N7f)zBRe-subscribe to any channels and patterns previously subscribed toTr  NrQ   )
r  clearr  r  itemsr  r  	subscriber  
psubscribe)rS   r   r  kvr  s         rU   r  PubSub.on_connect  s     
 	))//1))//1==H++-?@,,Qd,;< ...,8,,,==H++-?@,,Qd,;< .//-H---	  -
 .s%   BDDA+D
DDDc                 R    [        U R                  =(       d    U R                  5      $ )z@Indicates if there are subscriptions to any channels or patterns)rg  r  r  r   s    rU   
subscribedPubSub.subscribed  s     DMM2T]]33rX   rC  c                    #    U R                  5       I Sh  vN   U R                  nSU R                  (       + 0nU R                  " X"R                  /UQ70 UD6I Sh  vN   g NL N7f)z#Execute a publish/subscribe commandNcheck_health)rv  r   r  _executer@  )rS   rC  r   rT   s       rU   rX  PubSub.execute_command  s]      lln__
 doo"56mmJ(?(?Q$Q&QQQ 	 	Rs"   A'A#AA'A%A'%A'c                 *  #    U R                   cM  U R                  R                  5       I Sh  vN U l         U R                   R                  U R                  5        O"U R                   R                  5       I Sh  vN   U R                  b/  U R                   R                  R                  U R                  5        U R                  R                  [        U R                   U R                  [        R                  U R                  5      5        g N N7f)z%
Ensure that the PubSub is connected
N)r   rm   r   register_connect_callbackr  rv  r  _parserset_pubsub_push_handlerr   r   r,   r.   r   r  r   s    rU   rv  PubSub.connect  s      ??"$($8$8$G$G$IIDO OO55dooF//))+++!!-OO##;;D<R<RS''3!5!5z7G7G	
 J
 ,s#   +DDAD:D;BDDc                 t   #    UR                  5       I Sh  vN   UR                  5       I Sh  vN   g N N7f)z
Try to reconnect
N)r4  rv  rH  s     rU   
_reconnectPubSub._reconnect  s.      oolln 	 s   848688c                 v   ^ ^^^^#    TR                   R                  UUU4S jUU 4S j5      I Sh  vN $  N7f)a%  
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                     > T" T 0 TD6$ rP   rQ   )rC  r   rT   s   rU   rP  !PubSub._execute.<locals>.<lambda>  s    GT,V,rX   c                 &   > TR                  T5      $ rP   )r  rS  s    rU   rP  r    s    dood+rX   N)r   rV  )rS   r5  r   rC  rT   s   `````rU   r  PubSub._execute  s/      ZZ//,+
 
 	
 
s   +979blockr   c                 r  #    U R                   nUc  [        S5      eU R                  5       I Sh  vN   UR                  (       d  UR	                  5       I Sh  vN   U(       a  SOUnU R                  UUR                  USSS9I Sh  vN nUR                  (       a  XPR                  ;   a  gU$  N NY N+7f)z3Parse the response from a publish/subscribe commandNNpubsub connection not set: did you forget to call subscribe() or psubscribe()?FT)r   disconnect_on_errorpush_request)	r   r,  r  is_connectedrv  r  r]  r   r  )rS   r  r   r5  read_timeoutrN   s         rU   rA  PubSub.parse_response  s     <F 
 !!!  ,,.  $t'  % ' 
 
 %%(6P6P*P# 	" !
s3   .B7B1(B7B3/B7	B5
(B73B75B7c                   #    U R                   nUc  [        S5      eUR                  (       aV  [        R                  " 5       R                  5       UR                  :  a$  UR                  SU R                  SS9I S h  vN   g g g  N7f)Nr  PINGF)r  )	r   r,  r   r   rk  rn  next_health_checkr@  r  rH  s     rU   r  PubSub.check_health  s     <F  &&((*//1D4J4JJ##11 $    K 's   A;B=B>Bdatac           	          U R                   R                  nU R                   R                  nUR                  5        VVs0 s H  u  pEU" U" U5      5      U_M     snn$ s  snnf )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.
)r  r  r  r  )rS   r  r  r  r  r  s         rU   _normalize_keysPubSub._normalize_keys%  sP     $$$$15>vay!1$>>>s    ArT   c                 v  #    U(       a  [        US   4USS 5      OUn[        R                  U5      nUR                  U5        U R                  " S/UR                  5       Q76 I Sh  vN nU R                  U5      nU R                  R                  U5        U R                  R                  U5        U$  NM7f)a  
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()``.
r   r   N
PSUBSCRIBE)
r)   dictfromkeysr   rX  r\  r  r  r  difference_update)rS   rC  rT   parsed_argsnew_patternsret_vals         rU   r  PubSub.psubscribe/  s      =AlDG:tABx8d6:mmK6PF#,,\PL<M<M<OPP ++L9\*));;LI Q   A'B9)B7*AB9c                    U(       aF  [        US   4USS 5      nU R                  [        R                  U5      5      R	                  5       nO/ nU R
                  nU R                  R                  U5        U R                  " S/UQ76 $ )zR
Unsubscribe from the supplied patterns. If empty, unsubscribe from
all patterns.
r   r   NPUNSUBSCRIBE)	r)   r  r  r  r\  r  r  r   rX  )rS   rC  r  r  s       rU   r  PubSub.punsubscribeD  sy     &Qz48<K++DMM+,FGLLNHK}}H))00:##NA[AArX   c                 v  #    U(       a  [        US   4USS 5      OSn[        R                  U5      nUR                  U5        U R                  " S/UR                  5       Q76 I Sh  vN nU R                  U5      nU R                  R                  U5        U R                  R                  U5        U$  NM7f)a"  
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()``.
r   r   NrQ   	SUBSCRIBE)
r)   r  r  r   rX  r\  r  r  r  r  )rS   rC  rT   r  new_channelsr  s         rU   r  PubSub.subscribeS  s      =AlDG:tABx8b}}[1F#,,[O<;L;L;NOO ++L9\*));;LI Pr  c                     U(       a7  [        US   USS 5      nU R                  [        R                  U5      5      nO/ nU R                  nU R
                  R                  U5        U R                  " S/UQ76 $ )zQ
Unsubscribe from the supplied channels. If empty, unsubscribe from
all channels
r   r   NUNSUBSCRIBE)r)   r  r  r  r  r  r   rX  )rS   rC  r  r  s       rU   r  PubSub.unsubscribeh  sn    
 &tAwQR9K++DMM+,FGHK}}H))00:##M@K@@rX   c                   #    U R                   (       aJ  U R                  U R                  SS9I Sh  vN 5      I Sh  vN nUb  U7v   U R                   (       a  MI  gg N- N#7f)zBListen for messages on channels this client has been subscribed toT)r  N)r  handle_messagerA  rz  s     rU   r  PubSub.listenv  sM     oo!00t7J7JQU7J7V1VWWH# ooo1VWs%   /A#AA#A!A#A#!A#c                    #    U R                  USL US9I Sh  vN nU(       a  U R                  X15      I Sh  vN $ g N% N7f)z
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.
N)r  r   )rA  r
  )rS   r  r   rN   s       rU   get_messagePubSub.get_message}  sF      ,,GtOg,VV,,XQQQ WQs   A>AA A Ac                 4    Ub  SU/OS/nU R                   " U6 $ )z
Ping the Redis server to test connectivity.

Sends a PING command to the Redis server and returns True if the server
responds with "PONG".
r  rX  )rS   r'  rC  s      rU   pingPubSub.ping  s(     %,$7 fX##T**rX   c                   #    Uc  g[        U[        5      (       a  US:w  a  SU/OSS/n[        US   5      nUS:X  a  UUS   US   US	   S
.nOUS:X  a  USSUS   S
.nOUSUS   US   S
.nX0R                  ;   a  US:X  aL  US   nXPR                  ;   a7  U R                  R                  U5        U R                  R                  US5        OKUS   nX`R                  ;   a7  U R                  R                  U5        U R                  R                  US5        X0R                  ;   a  US:X  a   U R                  R                  US   S5      nOU R                  R                  US   S5      nU(       a5  [        R                  " U5      (       a  U" U5      I Sh  vN   gU" U5        g U$ US:w  a  U(       d  U R                  (       a  gU$  N27f)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.
Ns   PONGr  rX   r   r  r   r   r   )typepatternchannelr  r  r  r  r  )r  rc  r?   UNSUBSCRIBE_MESSAGE_TYPESr  remover  r^  r  r  PUBLISH_MESSAGE_TYPESr   r   iscoroutinefunctionr  )rS   rN   r  message_typer'  r  r  handlers           rU   r
  PubSub.handle_message  s     h&&.6'.A*QT~H#HQK0:%$#A;#A; 	G V#$ 	G %#A; 	G 999~-"1+???55<<WEMM%%gt4"1+???55<<WEMM%%gt4555z)--++GI,>E--++GI,>E..w77!'***  G$   V# )D,J,J +s   FGG3Gg      ?)exception_handlerpoll_timeoutr  r  PSWorkerThreadExcHandlerTr  c                  #    U R                   R                  5        H  u  pEUb  M
  [        SU S35      e   U R                  R                  5        H  u  peUb  M
  [        SU S35      e   U R	                  5       I Sh  vN     Uc  U R                  SUS9I Sh  vN   OUR                  SUS9I Sh  vN    [        R                  " S5      I Sh  vN   MV   N[ N@ N)! [        R                   a    e [         a<  nUc  e U" Xp5      n[        R                  " U5      (       a  UI Sh  vN     SnAN{SnAff = f Ni7f)a`  Process pub/sub messages using registered callbacks.

This is the equivalent of :py:meth:`redis.PubSub.run_in_thread` in
redis-py, but it is a coroutine. To launch it as a separate task, use
``asyncio.create_task``:

    >>> task = asyncio.create_task(pubsub.run())

To shut it down, use asyncio cancellation:

    >>> task.cancel()
    >>> await task
Nz
Channel: 'z' has no handler registeredz
Pattern: 'T)r  r   r   )r  r  r2   r  rv  r  r   CancelledErrorBaseExceptionr   r   r   )	rS   r  r  r  r  r  r  eress	            rU   run
PubSub.run  sQ    ( !% 3 3 5G!Jwi7R"STT !6 !% 3 3 5G!Jwi7R"STT !6 lln>**26 +    !,,26 -    --""")  	 ))   $,'0&&s++II #s   !E1E$E CEC" CC" "E#C" 6C 7C" ;ED?EC"  C" "D< ,D7,D/-D72E7D<<E)r   r  r  r   rm   r  r  r  r  r  r  r  r   )NFNNNrv   N)Tr   )Fg        rP   )F)1rZ   r[   r\   r]   rb  r  r  r  r   r   r_  rg  r   r   r  r!  r/  r  r<   r9  r  r   r  propertyr  r7   rX  rv  r  r  ri  rA  r  rI   r  r6   PubSubHandlerr  r   r  r  r  r   r  r  r  r
  r&  r^   rQ   rX   rU   r  r  S  s    4 ?2
 %)*/048<'$''$ SM'$ $(	'$ $H-'$ ##45'$RI6" 1GgV W 1GgV W.: .$ 4 4
R: 
R
(
$  8 ?O ? ?h - *B( By BX  *AI Am  SV)-@H+IdO +@J DH!0# $$?@0# 	0# 
0# 0#rX   r  c                   &    \ rS rSrS\S\4S jrSrg)PubsubWorkerExceptionHandleri  r$  r  c                     g rP   rQ   rS   r$  r  s      rU   rV   %PubsubWorkerExceptionHandler.__call__  s    #rX   rQ   NrZ   r[   r\   r]   r#  r  rV   r^   rQ   rX   rU   r,  r,    s    =-==rX   r,  c                   &    \ rS rSrS\S\4S jrSrg)!AsyncPubsubWorkerExceptionHandleri  r$  r  c                    #    g 7frP   rQ   r.  s      rU   rV   *AsyncPubsubWorkerExceptionHandler.__call__  s     rd   rQ   Nr0  rQ   rX   rU   r2  r2    s    CCvCrX   r2  .c            	         ^  \ rS rSrSr1 SkrS\S\\\	\
4   \4   S\S\\	   4S jrS	\S
\4S jrS rS rSrS rS rS rS rS1S jrS rS
\S \S    4   4S jrS\S\4S jrS rS r S\S\!4S jr"S\S\!S\4S  jr#S\!S!\$\%   4S" jr&S#\S$\'S%\$\(   S
S4S& jr)S\S'\\	\
4   4U 4S( jjr*S) r+S\S\4S* jr,S2S\S
\-\%   4S+ jjr.S, r/S-\04S. jr1S/ r2S0r3U =r4$ )3r   i  aj  
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(when running in transactional mode,
which is the default behavior) 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UNWATCHrm   rg   r   r   c                     Xl         S U l        X l        X0l        X@l        SU l        / U l        [        5       U l        SU l	        g )NF)
rm   r   rg   is_transactionr   watchingcommand_stackr  scriptsexplicit_transaction)rS   rm   rg   r   r   s        rU   r   Pipeline.__init__2  sB      /"4)$,.$'E$)!rX   rS   rv   c                    #    U $ 7frP   rQ   r   s    rU   r  Pipeline.__aenter__C  r  r  c                 @   #    U R                  5       I S h  vN   g  N7frP   r  r  s       rU   r!  Pipeline.__aexit__F  s     jjlrK  c                 >    U R                  5       R                  5       $ rP   )_async_selfr   r   s    rU   r   Pipeline.__await__I  s    !++--rX   zUnclosed Pipeline clientc                 ,    [        U R                  5      $ rP   )lenr<  r   s    rU   __len__Pipeline.__len__N  s    4%%&&rX   c                     g)z1Pipeline instances should always evaluate to TrueTrQ   r   s    rU   __bool__Pipeline.__bool__Q  s    rX   c                    #    U $ 7frP   rQ   r   s    rU   rF  Pipeline._async_selfU  r  r  c                 D  #    / U l         [        5       U l        U R                  (       aW  U R                  (       aF   U R                  R                  S5      I S h  vN   U R                  R                  5       I S h  vN   SU l        SU l	        U R                  (       a5  U R                  R                  U R                  5      I S h  vN   S U l        g g  N{ N[! [         a7    U R                  (       a#  U R                  R                  5       I S h  vN     Nf = f NU7f)Nr8  F)r<  r  r=  r;  r   r@  r]  r0   r4  r>  rm   r3  r   s    rU   r  Pipeline.resetX  s     u ==T__7 oo229===oo33555 $)! ??&&..t???"DO  >5" 7??//446667 @se   9D C C!C <C=C AD D	D C C 8DDDD DD Nc                 @   #    U R                  5       I Sh  vN   g N7f)z5Alias for reset(), a standard method name for cleanupNrC  r   s    rU   r  Pipeline.aclosep  s     jjlrK  c                     U R                   (       a  [        S5      eU R                  (       a  [        S5      eSU l         g)zz
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>  r3   r<  r   s    rU   multiPipeline.multit  s<    
 $$ABBL  %)!rX   c                     U R                   (       d	  US   S:X  a#  U R                  (       d  U R                  " U0 UD6$ U R                  " U0 UD6$ )Nr   WATCH)r;  r>  immediate_execute_commandpipeline_execute_command)rS   rC  rT   s      rU   rX  Pipeline.execute_command  sJ     MMT!W/9R9R114B6BB,,d=f==rX   r5  errorc                    #    UR                  5       I Sh  vN   U R                  (       a:  U R                  5       I Sh  vN   [        S[	        U5      R
                   S35      eg NP N)7f)aE  
Close the connection reset watching state and
raise an exception if we were watching.

The supported exceptions are already checked in the
retry object so we don't need to do it here.

After we disconnect the connection, it will try to reconnect and
do a health check as part of the send_command logic(on connection level).
NA ) occurred while watching one or more keys)r4  r;  r  r5   r  rZ   rS   r5  r]  s      rU   #_disconnect_reset_raise_on_watching,Pipeline._disconnect_reset_raise_on_watching  sc      oo ==**,T%[))**ST  	 	 
 s    A+A'(A+A) (A+)A+c                    ^ ^^^^#    TS   mT R                   mT(       d)  T R                  R                  5       I Sh  vN mTT l         TR                  R	                  UUUUU 4S jUU 4S j5      I Sh  vN $  N< N7f)z
Execute a command immediately, but don't auto-retry on the supported
errors for retry if we're already WATCHing a variable.
Used when issuing WATCH or subsequent commands retrieving their values but before
MULTI is called.
r   Nc                  2   > TR                   " TT/T Q70 TD6$ rP   rN  rO  s   rU   rP  4Pipeline.immediate_execute_command.<locals>.<lambda>  s%    D55l%)-4rX   c                 (   > TR                  TU 5      $ rP   )rb  r]  r5  rS   s    rU   rP  rf    s    $BB4OrX   )r   rm   r   r   rV  )rS   rC  rD  rB  r5  s   ```@@rU   rZ  "Pipeline.immediate_execute_command  sq      Aw--<<>>D"DOZZ//  P	
 
 	
 ?
s!   6A>A:7A>5A<6A><A>c                 >    U R                   R                  X45        U $ )a:  
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<  append)rS   rC  rD  s      rU   r[  !Pipeline.pipeline_execute_command  s     	!!4/2rX   r   commandsc                   #    S0 4nS0 4nU/UQUP7nUR                  S U 5       5      nUR                  U5      I S h  vN   / n U R                  US5      I S h  vN   [        U5       HK  u  p[        US   ;   a  UR	                  XS   [           45        M0   U R                  US5      I S h  vN   MM      U R                  US5      I S h  vN nSU l	        Uc  [        S5      S eU H  u  pUR                  X5        M     [        U5      [        U5      :w  a?  U R                  (       a"  U R                  R                  5       I S h  vN   [        S	5      S eU(       a  U R                  X,5        / n[!        X5       H  u  nn[#        U[$        5      (       dg  Uu  nnUS   nUR'                  S
S 5        UU R(                  ;   a;  U R(                  U   " U40 UD6n[*        R,                  " U5      (       a
  UI S h  vN nUR	                  U5        M     U$  GN GN! [         a  n	UR	                  SU	45         S n	A	GNS n	A	ff = f GN! [         a6  n	U R                  XS-   US   5        UR	                  X45         S n	A	GM   S n	A	ff = f GN! [         a  n	U(       a	  US   S   U	ee S n	A	ff = f GNl N7f)N)MULTI)r6  c              3   B   #    U  H  u  p[         U;  d  M  Uv   M     g 7frP   )r"   ).0rC  rD  s      rU   	<genexpr>0Pipeline._execute_transaction.<locals>.<genexpr>  s      ,
&*]TnG.KDDds   	rT  r   r   FzWatched variable changed.z6Wrong number of response items from pipeline executionr\  )pack_commandssend_packed_commandrA  r4   rk  	enumerater"   annotate_exceptionr1   r;  r5   insertrI  r   r4  raise_first_errorzipr  r  r^  rg   r   r   )rS   r   rm  raise_on_errorprepostcmdsall_cmdserrorserrir   rN   r$  r  rcmdrC  rD  rB  s                       rU   _execute_transactionPipeline._execute_transaction  s     $R(#R%h%%++ ,
&*,
 
 ,,X666	$%%j#666
 $H-JA+q!*^"<=>,--j#>>> .	!00SAAH 89tC DAOOA!  x=CM)oo00222H
 ""86 (-FAsa++ #g#Aw FD)4#:#:://=aK7KA**1--"#GKKN . G 	7 7 	$MM1c(##	$ ?$ ,++CQ
CMM1(++, B 	Qil+	" 3, $s   =J?H J?H# H H# !;J?I2I3I7J?<J JJ A8J?J:B2J?J=J? H# #
I-I J?IJ?I
J*JJ?JJ?J 
J7!J22J77J?=J?r{  c                   #    UR                  U VVs/ s H  u  pEUPM	     snn5      nUR                  U5      I S h  vN   / nU H3  u  pH UR                  U R                  " XS   40 UD6I S h  vN 5        M5     U(       a  U R                  X'5        U$ s  snnf  N_ N.! [         a  n	UR                  U	5         S n	A	M|  S n	A	ff = f7f)Nr   )rt  ru  rk  rA  r4   ry  )
rS   r   rm  r{  rC  rT  r  rN   rD  r$  s
             rU   _execute_pipelinePipeline._execute_pipeline  s      ++,JgdT,JK,,X666%MD#--jq'MWMM & ""86 -K6 N  #""#sU   C
B
C
BC
$B!0B
1B!9%C
B!!
C+C<C
CC
rN   c                     [        U5       H6  u  p4[        U[        5      (       d  M  U R                  XCS-   X   S   5        Ue   g )Nr   r   )rv  r  r4   rw  )rS   rm  rN   r  r  s        rU   ry  Pipeline.raise_first_error'  s?    h'DA!]++''q5(+a.A (rX   	exceptionnumberr   c                     SR                  [        [        U5      5      nSU S[        U5       S3nU4UR                  SS  -   Ul        g )Nr  z
Command # z (z,) of pipeline caused error: {exception.args}r   )r  mapr>   r@   rC  )rS   r  r  r   r  msgs         rU   rw  Pipeline.annotate_exception-  sV     hhs8W-.=#5"6 79 9 	 ).."44	rX   rB  c                    >#    [         TU ]  " X40 UD6I S h  vN nX R                  ;   a	  SU l        U$ US:X  a  SU l        U$  N+7f)NFrY  T)superrA  UNWATCH_COMMANDSr;  )rS   r   rB  rD  resultr   s        rU   rA  Pipeline.parse_response7  sU      w-jR'RR000!DM  W$ DM Ss   AA,Ac                 T  #    [        U R                  5      nU R                  nU Vs/ s H  o3R                  PM     nnU" S/UQ76 I S h  vN n[	        U5      (       d>  [        X5       H.  u  p6U(       a  M  U" SUR                  5      I S h  vN Ul        M0     g g s  snf  NX N7f)NzSCRIPT EXISTSzSCRIPT LOAD)rj  r=  rZ  shaallrz  script)rS   r=  	immediatesshasexistsexists          rU   load_scriptsPipeline.load_scriptsA  s     t||$22	&'w!w' !84886{{0u"+M188"DDAE 1 	 ( 9 Es3   &B(BB(B$)B(9B(B&B(&B(c                    #    UR                  5       I Sh  vN   U R                  (       a"  [        S[        U5      R                   S35      eg N87f)a-  
Close the connection, raise an exception if we were watching.

The supported exceptions are already checked in the
retry object so we don't need to do it here.

After we disconnect the connection, it will try to reconnect and
do a health check as part of the send_command logic(on connection level).
Nr_  r`  )r4  r;  r5   r  rZ   ra  s      rU   _disconnect_raise_on_watching&Pipeline._disconnect_raise_on_watchingN  sO      oo ==T%[))**ST  	 	 s   AA9Ac                   ^ ^^^^#    T R                   mT(       d  T R                  (       d  / $ T R                  (       a  T R                  5       I Sh  vN   T R                  (       d  T R
                  (       a  T R                  mOT R                  mT R                  mT(       d)  T R                  R                  5       I Sh  vN mTT l        [        [        T5      m TR                  R                  UUUU4S jUU 4S j5      I Sh  vN T R                  5       I Sh  vN   $  N Nf N  N! T R                  5       I Sh  vN    f = f7f)z0Execute all the commands in the current pipelineNc                     > T" T TT5      $ rP   rQ   )r5  r   r{  stacks   rU   rP  "Pipeline.execute.<locals>.<lambda>w  s    e^<rX   c                 (   > TR                  TU 5      $ rP   )r  rh  s    rU   rP  r  x  s    d@@uMrX   )r<  r;  r=  r  r:  r>  r  r  r   rm   r   r   r   r   rV  r  )rS   r{  r5  r   r  s   ``@@@rU   r   Pipeline.executea  s     ""T]]I<<##%%%$";";//G,,G--<<>>D #DOJ%	33<M 
 **,) & ?
 $**,sm   AED'A/ED)E+D/ 
D+D/ E!D-"E)E+D/ -E/E
EE

Ec                 B   #    U R                  S5      I Sh  vN   g N7f)zNFlushes all previously queued commands
See: https://redis.io/commands/DISCARD
r7  Nr  r   s    rU   discardPipeline.discard}  s      ""9---r>  namesc                 |   #    U R                   (       a  [        S5      eU R                  " S/UQ76 I Sh  vN $  N7f)z$Watches the values at keys ``names``z"Cannot issue a WATCH after a MULTIrY  N)r>  r3   rX  )rS   r  s     rU   r   Pipeline.watch  s6     $$ABB))':E::::s   3<:<c                 x   #    U R                   =(       a    U R                  S5      I Sh  vN =(       d    S$  N7f)z'Unwatches all previously specified keysr8  NT)r;  rX  r   s    rU   unwatchPipeline.unwatch  s*     }}Ft';';I'F!FN$N!Fs   (:8:)	r<  r   rm   r>  r:  rg   r=  r   r;  r(  )T)5rZ   r[   r\   r]   rb  r  r   r   r   r_  rc  rd  rg  r   r   rG   r  r!  r   r*  rJ  rM  rF  r  r  rV  r   rX  r   r  rb  rZ  r[  CommandStackTr  r  r	   r   ry  rh  objectrw  rA  r  r  r
   r   r  r8   r   r  r^   __classcell__)r   s   @rU   r   r     s   & 6*'* +5e+<>O+OP* 	*
 SM*"w 7 . .L'#0)>	z9Z00	1> 2
*L$L0=L\$0=OS(- 8C= 5"5,/5:B6:J5	5$49#u*4EE
 9 &D DI 8.;$ ;O OrX   r   )kr   r   r   r  rp   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   redis._parsers.helpersr   r   r   r   redis.asyncio.connectionr   r   r   r   redis.asyncio.lockr   redis.asyncio.retryr    redis.backoffr!   redis.clientr"   r#   r$   r%   redis.commandsr&   r'   r(   r)   redis.credentialsr*   redis.eventr+   r,   r-   r.   r/   redis.exceptionsr0   r1   r2   r3   r4   r5   redis.typingr6   r7   r8   redis.utilsr9   r:   r;   r<   r=   r>   r?   r@   r   rA   rB   rC   r_  r*  rD   rF   rG   r  rI   redis.commands.corerJ   rL   r`   rd  rH   StrictRedisrm  r  r  r,  r2  r   rc  CommandTr  r   rQ   rX   rU   <module>r     s      	      ,   $ % 6   1   4 3	 	 	 ]77JJK$sCx.)9T?:;t$z*
)7
++78V;K3LM*5x 5;H ; 24QQR M
+->@UM
`  F, F,Ru# u#p>8 >D D " "CC 
 uS%Z(#-.S0AABXoOu oOrX   