
    (ph{o                    $   S SK Jr  S SKJr  S SKrS SKr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  S SKJrJrJr  S SKJr  S SKJrJrJrJrJ r J!r!J"r"J#r#J$r$  Sr%S	r&S
 r'S r(S r)S r* " S S\+5      r,S r-S r.S r/S r00 S\1_S\1_S\1_S\1_S\1_S\1_S\1_S\1_S\1_S\1_S\1_S\1_S \1_S!\1_S"\1_S#\1_S$\1_\1\1\1\1\1\1S%.Er2S& r3S' r4S( r5S) r6S* r7S+ r8SXS, jr9S- r:S. r;S/ r<S0 r=S1 r>S2 r?S3 r@S4 rAS5 rBS6 rCS7 rDS8 rES9 rFS: rGS; rHS< rIS= rJS> rKS? rLS@ rMSA rNSB rOSC rPSD rQSE rRSF rSSG rTSH rUSI rV " SJ SK\W5      rX\XrY " SL SM\W5      rZ " SN SO\W5      r[ " SP SQ\R                  5      r] " SR SS\X5      r^ " ST SU\W5      r_ " SV SW\W5      r`g)Y    )unicode_literals)chainN)	
basestringimap	iteritemsiterkeys
itervaluesiziplong	nativestrsafe_unicode)ConnectionPoolUnixDomainSocketConnectionSSLConnectionLock)	ConnectionError	DataErrorExecAbortErrorNoScriptErrorPubSubError
RedisErrorResponseErrorTimeoutError
WatchError    EMPTY_RESPONSEc                      [        U 5        [        U [        [        45      (       a  U /n O[	        U 5      n  U(       a  U R                  U5        U $ ! [
         a    U /n  N)f = fN)iter
isinstancer   byteslist	TypeErrorextend)keysargss     ?/var/www/html/venv/lib/python3.13/site-packages/redis/client.pylist_or_argsr)      s`    	T
 dZ/006D:D DK	  vs   )A A A"!A"c                     U (       d  g [        U 5      n [        R                  R                  U 5      $ ! [         a     gf = f)z5Converts a unix timestamp to a Python datetime objectN)int
ValueErrordatetimefromtimestampresponses    r(   timestamp_to_datetimer1   0   sC    x= **844  s   4 
A Ac                 J    [         R                  U R                  5       U5      $ r   )dictfromkeyssplit)
key_stringcallbacks     r(   string_keys_to_dictr8   ;   s    ==))+X66r   c                  >    0 nU  H  nUR                  U5        M     U$ r   )update)dictsmergedds      r(   
dict_merger>   ?   s"    Fa Mr   c                   r   ^  \ rS rSrSrS rU 4S jrU 4S jrU 4S jrSU 4S jjr	U 4S jr
U 4S	 jrS
rU =r$ )CaseInsensitiveDictF   z?Case insensitive dict implementation. Assumes string keys only.c                 P    [        U5       H  u  p#X0UR                  5       '   M     g r   )r   upper)selfdatakvs       r(   __init__CaseInsensitiveDict.__init__I   s    dODAO $r   c                 F   > [         [        U ]  UR                  5       5      $ r   )superr@   __contains__rC   rD   rF   	__class__s     r(   rL    CaseInsensitiveDict.__contains__M   s    ($<QWWYGGr   c                 H   > [         [        U ]  UR                  5       5        g r   )rK   r@   __delitem__rC   rM   s     r(   rQ   CaseInsensitiveDict.__delitem__P   s    !44QWWY?r   c                 F   > [         [        U ]  UR                  5       5      $ r   )rK   r@   __getitem__rC   rM   s     r(   rT   CaseInsensitiveDict.__getitem__S   s    ($;AGGIFFr   c                 H   > [         [        U ]  UR                  5       U5      $ r   )rK   r@   getrC   )rD   rF   defaultrN   s      r(   rW   CaseInsensitiveDict.getV   s    ($3AGGIwGGr   c                 J   > [         [        U ]  UR                  5       U5        g r   )rK   r@   __setitem__rC   )rD   rF   rG   rN   s      r(   r[   CaseInsensitiveDict.__setitem__Y   s    !44QWWYBr   c                 B   > [        U5      n[        [         U ]  U5        g r   )r@   rK   r:   )rD   rE   rN   s     r(   r:   CaseInsensitiveDict.update\   s    "4(!4/5r    r   )__name__
__module____qualname____firstlineno____doc__rH   rL   rQ   rT   rW   r[   r:   __static_attributes____classcell__rN   s   @r(   r@   r@   F   s3    E H@GHC6 6r   r@   c                     [        U 5      n SU -   n [        S U R                  5        5       5      n SnU H  nX ;   d  M
  [        X   5      X'   M     U $ )zDParse the results of Redis's DEBUG OBJECT command into a Python dictztype:c              3   B   #    U  H  oR                  S 5      v   M     g7f:Nr5   ).0kvs     r(   	<genexpr>%parse_debug_object.<locals>.<genexpr>g   s     =,<bHHSMM,<s   )refcountserializedlengthlrulru_seconds_idle)r   r3   r5   r+   )r0   
int_fieldsfields      r(   parse_debug_objectrw   a   s\     "H!H=HNN,<==H MJ!(/2HO  Or   c                 (    US;   a  [        U 5      $ U $ )z&Parse the results of an OBJECT command)idletimerq   )int_or_none)r0   infotypes     r(   parse_objectr|   s   s    ++8$$Or   c                 ~  ^ 0 n[        U 5      n U4S jmU R                  5        H  nU(       d  M  UR                  S5      (       a  M$  UR                  S5      S:w  a:  UR	                  SS5      u  p4US:X  a  UR                  SS5      u  p4T" U5      X'   Ms  UR                  S/ 5      R                  U5        M     U$ )z;Parse the result of Redis's INFO command into a Python dictc                    > SU ;  d  SU ;  a   SU ;   a  [        U 5      $ [        U 5      $ 0 nU R                  S5       H!  nUR	                  SS5      u  p4T" U5      X'   M#     U$ ! [         a    U s $ f = f)N,=.   )floatr+   r,   r5   rsplit)valuesub_dictitemrF   rG   	get_values        r(   r   parse_info.<locals>.get_value   s    es%/%< <'u:% HC({{3*'l ) O  s   A% 
A% %A43A4#rk   r   cmdstat_host__raw__)r   
splitlines
startswithfindr5   r   
setdefaultappend)r0   infolinekeyr   r   s        @r(   
parse_infor   z   s    D"H  ##%4,,yy~# "ZZQ/
.(!%S!!4JC%e,	 	2.55d; & Kr   c                     [        U SSS9n[        U5       H*  u  p4UR                  S5      (       d  M  [        USSS9X#'   M,     U$ )z!Parse the results of MEMORY STATST)decode_keysdecode_string_valueszdb.)pairs_to_dictr   r   )r0   kwargsstatsr   r   s        r(   parse_memory_statsr      sR    (&*/35E  &
>>%  &u37<@BEJ '
 Lr   zcan-failover-its-masterzconfig-epochzdown-after-millisecondszfailover-timeoutzinfo-refreshzlast-hello-messagezlast-ok-ping-replyzlast-ping-replyzlast-ping-sentzmaster-link-down-timezmaster-portznum-other-sentinelsz
num-slaveszo-down-timezpending-commandszparallel-syncsport)quorumzrole-reported-timezs-down-timezslave-priorityzslave-repl-offsetzvoted-leader-epochc                     [        U [        5      n[        US   R                  S5      5      nS H  u  p4XB;   X'   M     U$ )Nflagsr   ))	is_mastermaster)is_slaveslave)is_sdowns_down)is_odowno_down)is_sentinelsentinel)is_disconnecteddisconnected)is_master_downmaster_down)pairs_to_dict_typedSENTINEL_STATE_TYPESsetr5   )r   resultr   nameflags        r(   parse_sentinel_stater      sH     ';<Fw%%c*+E:

 }: Mr   c                 4    [        [        [        U 5      5      $ r   r   r   r   r/   s    r(   parse_sentinel_masterr      s    Y 9::r   c                 \    0 nU  H#  n[        [        [        U5      5      nX1US   '   M%     U$ )Nr   r   )r0   r   r   states       r(   parse_sentinel_mastersr      s5    F$T)T%:; %uV}  Mr   c           	      `    U  Vs/ s H  n[        [        [        U5      5      PM     sn$ s  snf r   r   )r0   r   s     r(   #parse_sentinel_slaves_and_sentinelsr      s'    DLMHD i!67HMMMs   #+c                 L    U =(       a    U S   [        U S   5      4=(       d    S $ Nr   r   r+   r/   s    r(   parse_sentinel_get_masterr      s$    7!c(1+&67?4?r   c                 F    [        U [        5      (       a  [        U 5      $ U $ r   )r!   r"   r   )r   s    r(   nativestr_if_bytesr      s    )%779UBUBr   c                 
   U c  0 $ U(       d  U(       aR  U SSS2   nU(       a  [        [        U5      nU SSS2   nU(       a  [        [        U5      n[        [	        X45      5      $ [        U 5      n[        [	        XU5      5      $ )z-Create a dict given a list of key/value pairsN   r   )r   r   r   r3   r
   r    )r0   r   r   r&   valuesits         r(   r   r      sx    	* !}	4(D!$Q$,f5FD&''(^DL!!r   c                     [        U 5      n0 n[        X"5       H  u  pEXA;   a   X   " U5      nXSU'   M     U$ ! [         a     Nf = fr   )r    r
   	Exception)r0   	type_infor   r   r   r   s         r(   r   r      s]    	hBF2l
!u-
 s # M   s   
8
AAc           	          U (       a  UR                  S5      (       d  U $ UR                  S[        5      n[        U 5      n[        [	        U[        X#5      5      5      $ )zf
If ``withscores`` is specified in the options, return the response as
a list of (value, score) pairs

withscoresscore_cast_func)rW   r   r    r#   r
   r   )r0   optionsr   r   s       r(   zset_score_pairsr     sK    
 7;;|44kk"3U;O	hBRo2344r   c                     U (       a  UR                  S5      (       d  U $ US   n[        [        [        U5       Vs/ s H
  o0USU2   PM     sn6 5      $ s  snf )z
If ``groups`` is specified, return the response as a list of
n-element tuples with n being the value found in options['groups']
groupsN)rW   r#   r
   range)r0   r   nis       r(   sort_return_tuplesr     sR    
 7;;x00AuQx8x!1~x89::8s   Ac                      U c  g [        U 5      $ r   r   r/   s    r(   rz   rz   %  s    x=r   c                      U c  g [        U 5      $ r   r   r/   s    r(   nativestr_or_noner   +  s    Xr   c                     U c  g / nU  H;  nUb$  UR                  US   [        US   5      45        M*  UR                  S5        M=     U$ )Nr   r   NN)r   r   )r0   rE   rs      r(   parse_stream_listr   1  sP    D=KK1}QqT234KK%	 
 Kr   c                     [        U SS9$ )NTr   r   r/   s    r(   !pairs_to_dict_with_nativestr_keysr   =  s    t44r   c                 4    [        [        [        U 5      5      $ r   )r#   r   r   r/   s    r(   parse_list_of_dictsr   A  s    6ABBr   c                 J    UR                  SS5      (       a  U $ [        U 5      $ )Nparse_justidF)rW   r   r0   r   s     r(   parse_xclaimr   E  s#    {{>5))X&&r   c                     [        U SS9nUS   nUb  US   [        US   5      4US'   US   nUb  US   [        US   5      4US'   U$ )NTr   zfirst-entryr   r   z
last-entryr   )r0   rE   firstlasts       r(   parse_xinfo_streamr   K  sk    t4DE$QxuQx)@A]D"1g}T!W'=>\Kr   c                 \    U c  / $ U  Vs/ s H  oS   [        US   5      /PM     sn$ s  snf r   )r   )r0   r   s     r(   parse_xreadr   V  s6    	5=>XqT$QqT*+X>>>s   )c                     UR                  SS5      (       a  [        U 5      $ U S   =(       d    /  VVs/ s H  u  p#U[        U5      S.PM     nnnU S   U S   U S   US.$ s  snnf )	Nparse_detailF   )r   pendingr   r   r   )r   minmax	consumers)rW   parse_xpending_ranger   )r0   r   r   pr   s        r(   parse_xpendingr   \  ss    {{>5))#H--=Ea[=NB=NO=NTQ!Q0=NIOA;{{	  Ps   A!c           	      Z    SnU  Vs/ s H  n[        [        X5      5      PM     sn$ s  snf )N)
message_idconsumertime_since_deliveredtimes_delivered)r3   r
   )r0   rF   r   s      r(   r   r   h  s(    MA&./hDah///s   (c                      U c  g [        U 5      $ r   r   r/   s    r(   float_or_noner   m  s    ?r   c                     [        U 5      S:H  $ NOKr   r/   s    r(   bool_okr  s  s    X$&&r   c                 b    U c  g UR                  S5      (       a  [        U 5      $ [        U 5      $ )Nas_score)rW   r   r+   r   s     r(   
parse_zaddr  w  s.    {{:Xx=r   c           	          / n[        U 5      R                  5        H3  nUR                  [        S UR	                  S5       5       5      5        M5     U$ )Nc              3   D   #    U  H  oR                  S S5      v   M     g7f)r   r   Nrl   )rm   pairs     r(   ro   $parse_client_list.<locals>.<genexpr>  s     H<4JJsA..<s     )r   r   r   r3   r5   )r0   r   clientscs       r(   parse_client_listr    sE    Gx ++-tH1773<HHI . Nr   c                     U  Vs/ s H  o"b  [        U5      OS PM     n nU =(       a    [        U 5      =(       d    0 $ s  snf r   )r   r   )r0   r   r   s      r(   parse_config_getr    s<    AIJA	!47HJ/h/525 Ks   =c                 $    U u  p#[        U5      U4$ r   )r   r0   r   cursorr   s       r(   
parse_scanr    s    IF<?r   c                 Z    U u  p#[        U5      U=(       a    [        U5      =(       d    0 4$ r   )r   r   r  s       r(   parse_hscanr    s'    IF</}Q/5255r   c           
          UR                  S[        5      nU u  p4[        U5      n[        U5      [	        [        U[        X%5      5      5      4$ )Nr   )rW   r   r    r   r#   r
   r   )r0   r   r   r  r   r   s         r(   parse_zscanr    sC    kk"3U;OIF	aB<d2tO'@ABBBr   c           
          UR                  SS5      (       a  SOSnU  Vs/ s H7  nUS   [        US   5      [        US   5      UR                  US   5      S	.PM9     sn$ s  snf )
Ndecode_responsesFr      r   r   r   r   )id
start_timedurationcommand)rW   r+   join)r0   r   spacer   s       r(   parse_slowlog_getr#    st    ;;1599CtE 
 $	 1g$q'lQL::d1g&	
   s   >A!c                 X    [        U 5      n [        S U R                  5        5       5      $ )Nc              3   T   #    U  H  o(       d  M  UR                  S 5      v   M      g7frj   rl   rm   r   s     r(   ro   %parse_cluster_info.<locals>.<genexpr>  s      J,ADT

3,As   
(()r   r3   r   r   s     r(   parse_cluster_infor(    s&    "HJH,?,?,AJJJr   c           	          U R                  S5      nU R                  S5      S S u  p#pEpgnn	USS   V
s/ s H  oR                  S5      PM     nn
UUUUUUUU	S:X  a  SOSS.nX<4$ s  sn
f )Nr     -	connectedTF)node_idr   	master_idlast_ping_sentlast_pong_rcvdepochslotsr,  rl   )r   
line_itemsr-  addrr   r.  pingpongr1  r,  slr2  	node_dicts                r(   _parse_node_liner9    s    CJJJsOBQ'G5T%/^4^rXXc]^E4&+5T5	I ? 5s   A%c                     [        U 5      n U n[        U [        5      (       a  U R                  5       n[	        S U 5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   )r9  r&  s     r(   ro   &parse_cluster_nodes.<locals>.<genexpr>  s     =94 &&9s   )r   r!   r   r   r3   )r0   r   	raw_liness      r(   parse_cluster_nodesr>    s=    "HI(J'''')	=9===r   c                    US   (       d
  US   (       a  U $ [        U 5      [        :w  a  U /nOU nUS   (       d  US   (       d  US   (       d  U$ [        S [        S.nS /nUS	 Vs/ s H  oQU   (       d  M  X5   PM     sn-  nU Vs/ s H"  n[        [	        S
 [        XF5      5      5      PM$     sn$ s  snf s  snf )Nstore
store_distwithdist	withcoordwithhashc                 :    [        U S   5      [        U S   5      4$ r   r   lls    r(   <lambda>)parse_georadius_generic.<locals>.<lambda>  s    r!uuRU| <r   )rB  rC  rD  c                     U $ r   r_   xs    r(   rH  rI    s    1r   )rB  rD  rC  c                     U S   " U S   5      $ r   r_   )fvs    r(   rH  rI    s    BqE"Q%Lr   )typer#   r   r+   mapzip)r0   r   response_listcastfor   s          r(   parse_georadius_genericrV    s    w7<0 H~!
 :w{';J' <D 
A@	O@aAJ'$'@	OOA?L?L!S(#a)45}  
Ps   (B69B6
)B;c           	      D    [        [        U SS S2   U SS S2   5      5      $ )Nr   r   r   )r#   rQ  r   s     r(   parse_pubsub_numsubrX    s(    HQTTNHQTTN344r   c                 j    [        U [        [        45      (       a  [        U 5      $ [        U 5      S:H  $ r  r!   r   r+   r   r   s     r(   parse_client_killr[    s-    (T3K((8}X$&&r   c                 v   U c  g [        U SS9n[        [        [        US   5      5      US'   [        [        [        US   5      5      US'   [        US   5      US'   / / pCUS   R	                  S5       H-  nSU;   a  UR                  U5        M  UR                  U5        M/     X2S'   XBS'   S	US   ;   US
'   U$ )NTr   r   	passwordscommandsr  @
categoriesonenabled)r   r#   rP  r   r5   r   )r0   r   rE   r^  r`  r   s         r(   parse_acl_getuserrc    s    t4D YW67DMSD,=>?D j!12D rj
#))#.'>g&OOG$	 /  #d7m+DOKr   c            !          \ rS rSrSr\" \" S\5      \" S\5      \" S\	5      \" SS 5      \" S\
5      \" S	\5      \" S
\5      \" SS 5      \" SS 5      \" S\5      \" SS 5      \" S\5      \" S\5      \" S\5      \" SS 5      0 SS _S\_S\_S\_SS _S\_S\_S \_S!S" _S#\_S$S% _S&\_S'\_S(\_S)\_S*S+ _S,\_0 S-\_S.S/ _S0S1 _S2\_S3\_S4\_S5\_S6S7 _S8\_S9\_S:\_S;\_S<\_S=\_S>\_S?\_S@\_E0 SA\_SB\_SC\_SDSE _SFSG _SH\_SI\_SJSK _SL\_SM\_SN\_SO\_SP\_SQ\_SR\_SSST _SU\_E0 SVSW _SX\ _SYSZ _S[\_S\\_S]\_S^\!_S_\"_S`\#_Sa\_Sb\_Sc\$_Sd\_Se\$_SfSg _Sh\%_Si\_E\\ Sj \&\\\\\'\'\(\)\*\+Sk.E5      r,\-GSbSm j5       r.             GScSp jr/Sq r0Sr r1GSdSs jr2St r3  GSeSu jr4Sv r5Sw r6Sx r7Sy r8Sz r9S{ r:S| r;S} r<S~ r=GSbS jr>S r?S r@S rAS rBS rCS rD    GSfS jrES rFS rGS rHS rIS rJGSgS jrKGSbS jrLS rMS rNS rOGShS jrPS rQS rRS rSGSiS jrTS rUS rVS rWS rXS rYS rZGShS jr[GShS jr\S r]GSbS jr^S r_ GSjS jr`S raS rbGSbS jrcS rdS reS rfS rgS rhS riS rjS rkS rlS rmS rnS roGSkS jrpGSlS jrqGSbS jrrS rsS rtS ruS rvS rwGSlS jrxGSbS jryS rzGSlS jr{GSmS jr|GSmS jr}S r~S rS rS r\rS rS rS rS rS rS rS rGSmS jrGSmS jrGSnS jrGSiS jrS rS rS rS rS rS rS rS rS rS rS rS rGShS jr GSoS jrS rS rS rS rS rS rGSpS jrS rS rS rS rS rS rGSqS jrGSqS jrGSqS jrS rS rS rS rS rS rS rS rS rS rS rS rS rS r  GSrS jrGSsS jrGStS jrGSuS jrGSlS jrGSuS jrGSlGS  jrSnSlSl\	4GS jrSlSl\	4GS jrGS rGS rGS rGS rGS rGS rGS	 rGS
 rGS rGSbGS jrGSbGS jrGS rGS rGS rGS rGSvGS jr  GSwGS jrGS rGSxGS jrGS rGS rGS rGS rGS rGS rGS rGS r GSbGS jrGSyGS jrGSlGS  jr  GSzGS! jrGS{GS" jrGS|GS# jrGS}GS$ jrGS% rGS& rGS' rGSbGS( jrGS) rGSbGS* jrGSbGS+ jrGSqGS, jrGSqGS- jrSoSo\	4GS. jrGSlGS/ jrGSlGS0 jrSlSlSo\	4GS1 jrGS2 rGS3 rGS4 rGS5 rGS6 rSo\	4GS7 jrSlSlSo\	4GS8 jrGS9 rGS: rGSbGS; jrGSbGS< jrGS= rGS> rGS? rGS@ Gr GSA GrGSB GrGSC GrGSmGSD jGrGSnGSE jGrGSF GrGSG GrGStGSH jGrGSI Gr	GSJ Gr
GSK GrGSL GrGSM GrGSN GrGSiGSO jGrGSP GrGSQ GrGSR GrGSS GrGST GrGSU GrGSV GrGSW GrGSX GrGSY GrGSZ GrGSbGS[ jGrGS\ GrGS] Gr   GS~GS^ jGr   GS~GS_ jGrGS` Gr GSaGr!gl(  Redisi  a  
Implementation of the Redis protocol.

This abstract class provides a Python interface to all Redis commands
and an implementation of the Redis protocol.

Connection and Pipeline derive from this, implementing how
the commands are sent and received to the Redis server
zbAUTH EXPIRE EXPIREAT HEXISTS HMSET MOVE MSETNX PERSIST PSETEX RENAMENX SISMEMBER SMOVE SETEX SETNXa  BITCOUNT BITPOS DECRBY DEL EXISTS GEOADD GETBIT HDEL HLEN HSTRLEN INCRBY LINSERT LLEN LPUSHX PFADD PFCOUNT RPUSHX SADD SCARD SDIFFSTORE SETBIT SETRANGE SINTERSTORE SREM STRLEN SUNIONSTORE UNLINK XACK XDEL XLEN XTRIM ZCARD ZLEXCOUNT ZREM ZREMRANGEBYLEX ZREMRANGEBYRANK ZREMRANGEBYSCOREzINCRBYFLOAT HINCRBYFLOATzLPUSH RPUSHc                 j    [        U [        [        45      =(       a    U =(       d    [        U 5      S:H  $ r  rZ  r   s    r(   rH  Redis.<lambda>&  s%    jT3K06QN)A,$:NNr   SORTzZSCORE ZINCRBY GEODISTzuFLUSHALL FLUSHDB LSET LTRIM MSET PFMERGE READONLY READWRITE RENAME SAVE SELECT SHUTDOWN SLAVEOF SWAPDB WATCH UNWATCH zBLPOP BRPOPc                 <    U =(       a    [        U 5      =(       d    S $ r   )tuplerg  s    r(   rH  rh  /  s    Q^585Kt5Kr   zSDIFF SINTER SMEMBERS SUNIONc                 L    U =(       a    [        U 5      =(       d
    [        5       $ r   r   rg  s    r(   rH  rh  2  s    alCF+ce+r   z?ZPOPMAX ZPOPMIN ZRANGE ZRANGEBYSCORE ZREVRANGE ZREVRANGEBYSCOREzBZPOPMIN BZPOPMAXc                 T    U =(       a    U S   U S   [        U S   5      4=(       d    S $ )Nr   r   r   r   rg  s    r(   rH  rh  9  s(    a&EQqT1Q4qt,E&M&Mr   zZRANK ZREVRANKzXREVRANGE XRANGEzXREAD XREADGROUPzBGREWRITEAOF BGSAVEc                     g)NTr_   rg  s    r(   rH  rh  =  s    Tr   ACL CATc                 4    [        [        [        U 5      5      $ r   r#   rP  r   rg  s    r(   rH  rh  ?  s    c)Q&7!8r   ACL DELUSERACL GENPASSACL GETUSERACL LISTc                 4    [        [        [        U 5      5      $ r   rr  rg  s    r(   rH  rh  C  s    $s9a'8"9r   ACL LOADACL SAVEACL SETUSER	ACL USERSc                 4    [        [        [        U 5      5      $ r   rr  rg  s    r(   rH  rh  G  s    4Iq(9#:r   
ACL WHOAMICLIENT GETNAMEc                 *    U =(       a    [        U 5      $ r   r   rg  s    r(   rH  rh  I  s    (:il(:r   	CLIENT IDCLIENT KILLCLIENT LISTCLIENT SETNAMECLIENT UNBLOCKc                 B    U =(       a    [        U 5      S:H  =(       d    S$ )Nr   Fr   rg  s    r(   rH  rh  N  s    (9c!fk(BU(Br   CLIENT PAUSEzCLUSTER ADDSLOTSzCLUSTER COUNT-FAILURE-REPORTSc                     [        U 5      $ r   r   rK  s    r(   rH  rh  Q  s    s1vr   zCLUSTER COUNTKEYSINSLOTc                     [        U 5      $ r   r   rK  s    r(   rH  rh  R  s    Qr   zCLUSTER DELSLOTSzCLUSTER FAILOVERzCLUSTER FORGETzCLUSTER INFOzCLUSTER KEYSLOTc                     [        U 5      $ r   r   rK  s    r(   rH  rh  W  s    Qr   zCLUSTER MEETzCLUSTER NODESzCLUSTER REPLICATEzCLUSTER RESETzCLUSTER SAVECONFIGzCLUSTER SET-CONFIG-EPOCHzCLUSTER SETSLOTzCLUSTER SLAVES
CONFIG GETCONFIG RESETSTAT
CONFIG SETDEBUG OBJECTGEOHASHc                 4    [        [        [        U 5      5      $ r   )r#   rP  r   rg  s    r(   rH  rh  d  s    c*;Q&?!@r   GEOPOSc                 .    [        [        S U 5      5      $ )Nc                 D    U b  [        U S   5      [        U S   5      4$ S $ r   r   rF  s    r(   rH   Redis.<lambda>.<locals>.<lambda>e  s3    ,.N 6;2a5\).r!u57 5E@D5Er   )r#   rP  rg  s    r(   rH  rh  e  s    S *EFG&I !Jr   	GEORADIUSGEORADIUSBYMEMBERHGETALLc                 <    U =(       a    [        U 5      =(       d    0 $ r   r   rg  s    r(   rH  rh  j  s    !7}Q'7!=2!=r   HSCANINFOLASTSAVEMEMORY PURGEMEMORY STATSMEMORY USAGEOBJECTPINGc                     [        U 5      S:H  $ )NPONGr   rg  s    r(   rH  rh  r  s    ilf4r   PUBSUB NUMSUB	RANDOMKEYc                 *    U =(       a    U =(       d    S $ r   r_   rg  s    r(   rH  rh  t  s    17?d?r   SCANSCRIPT EXISTSc                 4    [        [        [        U 5      5      $ r   )r#   r   boolrg  s    r(   rH  rh  v  s    tDqM':r   SCRIPT FLUSHSCRIPT KILLSCRIPT LOAD SENTINEL GET-MASTER-ADDR-BY-NAMESENTINEL MASTERSENTINEL MASTERSSENTINEL MONITORSENTINEL REMOVESENTINEL SENTINELSSENTINEL SETSENTINEL SLAVESSETc                 0    U =(       a    [        U 5      S:H  $ r  r   rg  s    r(   rH  rh    s    Q79Q<4#77r   SLOWLOG GETSLOWLOG LENc                 :    [        U S   5      [        U S   5      4$ r   r   rK  s    r(   rH  rh    s    s1Q4y#ad)4r   )SLOWLOG RESETSSCANTIMEXCLAIMXGROUP CREATEXGROUP DELCONSUMERXGROUP DESTROYXGROUP SETIDXINFO CONSUMERSXINFO GROUPSXINFO STREAMXPENDINGZADDZSCANNc                 @    [         R                  " U4SU0UD6nU " US9$ )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]:[password]]@/path/to/socket.sock?db=0

Three URL schemes are supported:

- ```redis://``
  <http://www.iana.org/assignments/uri-schemes/prov/redis>`_ creates a
  normal TCP socket connection
- ```rediss://``
  <http://www.iana.org/assignments/uri-schemes/prov/rediss>`_ creates a
  SSL wrapped TCP socket connection
- ``unix://`` creates a Unix Domain Socket connection

There are several ways to specify a database number. The parse function
will return the first specified option:
    1. A ``db`` querystring option, e.g. redis://localhost?db=0
    2. If using the redis:// scheme, the path argument of the url, e.g.
       redis://localhost/0
    3. The ``db`` argument to this function.

If none of these options are specified, db=0 is used.

Any additional querystring arguments and keyword arguments will be
passed along to the ConnectionPool class's initializer. In the case
of conflicting arguments, querystring arguments always win.
db)connection_pool)r   from_url)clsurlr  r   r  s        r(   r  Redis.from_url  s*    D )11#G"GG?33r   r   Fc                 0   U	(       d  Ub!  [         R                  " [        S5      5        UnUb!  [         R                  " [        S5      5        UnUUUUUUUUUUUS.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S.5        [        S0 UD6n	Xl        S U l        U(       a   U R                  R                  S5      U l        [        U R                  R                  5      U l        g )	Nz/"charset" is deprecated. Use "encoding" insteadz5"errors" is deprecated. Use "encoding_errors" instead)r  usernamepasswordsocket_timeoutencodingencoding_errorsr  retry_on_timeoutmax_connectionshealth_check_intervalclient_name)pathconnection_class)hostr   socket_connect_timeoutsocket_keepalivesocket_keepalive_options)r  ssl_keyfilessl_certfilessl_cert_reqsssl_ca_certsssl_check_hostname_r_   )warningswarnDeprecationWarningr:   r   r   r   r  
connectionget_connectionr@   rN   RESPONSE_CALLBACKSresponse_callbacks)rD   r  r   r  r  r  r  r  r  r  unix_socket_pathr  r  charseterrorsr  r  sslr  r  r  r  r  r  single_connection_clientr  r  r  r   s                                r(   rH   Redis.__init__  s3    "0EG H"!0KM N"( $$"0$#2$4$4#2)>*F  +,(B    .D(80H  MM,9'2(4)6(4.@#  -6v6O.#"22AA#FDO"5NN--#/r   c                 b    [        U 5      R                  < S[        U R                  5      < S3$ )N<>)rO  r`   reprr  rD   s    r(   __repr__Redis.__repr__  s"    :..T5I5I0JKKr   c                      X R                   U'   g)zSet a custom Response CallbackN)r  )rD   r   r7   s      r(   set_response_callbackRedis.set_response_callback  s    +3(r   c                 F    [        U R                  U R                  UU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.
)Pipeliner  r  )rD   transaction
shard_hints      r(   pipelineRedis.pipeline  s)       ##	 	r   c                    UR                  SS5      nUR                  SS5      nUR                  SS5      nU R                  SU5       n  U(       a  UR                  " U6   U" U5      nUR                  5       n	U(       a  UOU	 sSSS5        $ ! [         a#    Ub  US:  a  [
        R                  " U5         Mq  f = f! , (       d  f       g= 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.
r  Nvalue_from_callableFwatch_delayTr   )popr  watchexecuter   timesleep)
rD   funcwatchesr   r  r  r  pipe
func_value
exec_values
             r(   r  Redis.transaction  s     ZZd3
$jj)>Fjj5]]4,	

G,!%dJ!%J)<:*L -, " ".;?

;/ -,s*   	B?8B)B<8B?;B<<B??
Cc           	      &    Uc  [         nU" XX#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_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.

``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.        )timeoutr  blocking_timeoutthread_localr   )rD   r   r  r  r  
lock_classr  s          r(   lock
Redis.lock,  s'    Z J$g+;'35 	5r   c                 .    [        U R                  4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.
)PubSubr  )rD   r   s     r(   pubsubRedis.pubsub_  s     d**5f55r   c                 ,    [        U R                  5      $ r   )Monitorr  r  s    r(   monitorRedis.monitorg  s    t++,,r   c                 6    U R                  U R                  SS9$ )NT)r  r  )rN   r  r  s    r(   clientRedis.clientj  s#    ~~d.B.B7;  = 	=r   c                     U $ r   r_   r  s    r(   	__enter__Redis.__enter__n      r   c                 $    U R                  5         g r   closerD   exc_type	exc_value	tracebacks       r(   __exit__Redis.__exit__q      

r   c                 $    U R                  5         g r   r&  r  s    r(   __del__Redis.__del__t  r.  r   c                 p    U R                   nU(       a#  S U l         U R                  R                  U5        g g r   )r  r  releaserD   conns     r(   r'  Redis.closew  s.    "DO  ((. r   c                 ~   U R                   nUS   nU R                  =(       d    UR                  " U40 UD6n UR                  " U6   U R                  " XT40 UD6U R                  (       d  UR                  U5        $ $ ! [        [        4 a  nUR                  5         UR                  (       a  [        U[        5      (       d  e UR                  " U6   U R                  " XT40 UD6s SnAU R                  (       d  UR                  U5        $ $ SnAff = f! U R                  (       d  UR                  U5        f f = f)z.Execute a command and return a parsed responser   N)r  r  r  send_commandparse_responser3  r   r   
disconnectr  r!   )rD   r'   r   poolcommand_namer5  es          r(   execute_commandRedis.execute_command~  s   ##AwN$"5"5l"Ng"N	#t$&&tEWE ??T" #  . 	FOO))jL.I.It$&&tEWEE??T" #	F ??T" #s0   !A> >DAD&D'D DD %D<c                      UR                  5       nX R                  ;   a  U R                  U   " U40 UD6$ U$ ! [         a    [        U;   a  U[           s $ e f = f)z'Parses a response from the Redis server)read_responser   r   r  )rD   r  r<  r   r0   s        r(   r9  Redis.parse_response  sj    	!//1H
 222**<8MWMM  	(~..	s   9 AAc                 @    U(       a  U/O/ nU R                   " S/UQ76 $ )z
Returns a list of categories or commands within a category.

If ``category`` is not supplied, returns a list of all categories.
If ``category`` is supplied, returns a list of all commands within
that category.
rp  r>  )rD   categorypiecess      r(   acl_catRedis.acl_cat  s%      ((R##I777r   c                 &    U R                  SU5      $ )z-Delete the ACL for the specified ``username``rs  rD  rD   r  s     r(   acl_deluserRedis.acl_deluser  s    ##M8<<r   c                 $    U R                  S5      $ )z Generate a random password valuert  rD  r  s    r(   acl_genpassRedis.acl_genpass      ##M22r   c                 &    U R                  SU5      $ )zb
Get the ACL details for the specified ``username``.

If ``username`` does not exist, return None
ru  rD  rJ  s     r(   acl_getuserRedis.acl_getuser  s     ##M8<<r   c                 $    U R                  S5      $ )z'Return a list of all ACLs on the serverrv  rD  r  s    r(   acl_listRedis.acl_list      ##J//r   c                 $    U R                  S5      $ )z
Load ACL rules from the configured ``aclfile``.

Note that the server must be configured with the ``aclfile``
directive to be able to load ACL rules from an aclfile.
rx  rD  r  s    r(   acl_loadRedis.acl_load       ##J//r   c                 $    U R                  S5      $ )z
Save ACL rules to the configured ``aclfile``.

Note that the server must be configured with the ``aclfile``
directive to be able to save ACL rules to an aclfile.
ry  rD  r  s    r(   acl_saveRedis.acl_save  r[  r   c           	      t   U R                   R                  5       nU/nU	(       a  UR                  S5        U
(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        OUR                  S5        U(       d  U(       a  U(       a  [        S5      eU(       a  [	        U/ 5      n[        U5       H  u  pUR                  U5      nUR                  S5      (       a  UR                  SUS	S
 -  5        ME  UR                  S5      (       a  UR                  SUS	S
 -  5        Mt  [        SU-  5      e   U(       a  [	        U/ 5      n[        U5       H  u  nnUR                  U5      nUR                  S5      (       a  UR                  SUS	S
 -  5        MF  UR                  S5      (       a  UR                  SUS	S
 -  5        Mu  [        SU-  5      e   U(       a  UR                  S5        U(       a  U H  nUR                  U5      nUR                  S5      (       a  UR                  U5        M=  UR                  S5      (       a  UR                  SUS	S
 -  5        Ml  UR                  S5      (       a  UR                  U5        M  UR                  S5      (       a  UR                  SUS	S
 -  5        M  [        SUR                  USS9-  5      e   U(       as  U Hm  nUR                  U5      nUR                  S5      (       d2  UR                  S5      (       d  [        SUR                  USS9-  5      eUR                  U5        Mo     U(       a.  U H(  nUR                  U5      nUR                  SU-  5        M*     U R                  " S/UQ76 $ )a
  
Create or update an ACL user.

Create or update the ACL for ``username``. If the user already exists,
the existing ACL is completely overwritten and replaced with the
specified values.

``enabled`` is a boolean indicating whether the user should be allowed
to authenticate or not. Defaults to ``False``.

``nopass`` is a boolean indicating whether the can authenticate without
a password. This cannot be True if ``passwords`` are also specified.

``passwords`` if specified is a list of plain text passwords
to add to or remove from the user. Each password must be prefixed with
a '+' to add or a '-' to remove. For convenience, the value of
``add_passwords`` can be a simple prefixed string when adding or
removing a single password.

``hashed_passwords`` if specified is a list of SHA-256 hashed passwords
to add to or remove from the user. Each hashed password must be
prefixed with a '+' to add or a '-' to remove. For convenience,
the value of ``hashed_passwords`` can be a simple prefixed string when
adding or removing a single password.

``categories`` if specified is a list of strings representing category
permissions. Each string must be prefixed with either a '+' to add the
category permission or a '-' to remove the category permission.

``commands`` if specified is a list of strings representing command
permissions. Each string must be prefixed with either a '+' to add the
command permission or a '-' to remove the command permission.

``keys`` if specified is a list of key patterns to grant the user
access to. Keys patterns allow '*' to support wildcard matching. For
example, '*' grants access to all keys while 'cache:*' grants access
to all keys that are prefixed with 'cache:'. ``keys`` should not be
prefixed with a '~'.

``reset`` is a boolean indicating whether the user should be fully
reset prior to applying the new ACL. Setting this to True will
remove all existing passwords, flags and privileges from the user and
then apply the specified rules. If this is False, the user's existing
passwords, flags and privileges will be kept and any new specified
rules will be applied on top.

``reset_keys`` is a boolean indicating whether the user's key
permissions should be reset prior to applying any new key permissions
specified in ``keys``. If this is False, the user's existing
key permissions will be kept and any new specified key permissions
will be applied on top.

``reset_passwords`` is a boolean indicating whether to remove all
existing passwords and the 'nopass' flag from the user prior to
applying any new passwords specified in 'passwords' or
'hashed_passwords'. If this is False, the user's existing passwords
and 'nopass' status will be kept and any new specified passwords
or hashed_passwords will be applied on top.
s   resets	   resetkeyss	   resetpasss   ons   offz@Cannot set 'nopass' and supply 'passwords' or 'hashed_passwords'   +s   >%sr   N   -s   <%szBPassword %d must be prefixeed with a "+" to add or a "-" to removes   #%ss   !%szIHashed %d password must be prefixeed with a "+" to add or a "-" to removes   nopasss   +@s   +@%ss   -@s   -@%sz.Category "%s" must be prefixed with "+" or "-"Tforcez-Command "%s" must be prefixed with "+" or "-"s   ~%srz  )
r  get_encoderr   r   r)   	enumerateencoder   decoder>  )rD   r  rb  nopassr]  hashed_passwordsr`  r^  r&   reset
reset_keysreset_passwordsencoderrF  r   r  hashed_passwordrE  cmdr   s                       r(   acl_setuserRedis.acl_setuser  se   ~ &&224MM(#MM,'MM,'MM% MM&!)v D E E  %Y3I(3">>(3&&t,,MM&8AB<"78((..MM&8AB<"78# %DFG%H I I  4   ,,<bA&/0@&A"?").."A"--d33MM&?12+>">?$//55MM&?12+>">?# %KMN%O P P 'B MM)$&">>(3&&u--MM(+((..MM'HQRL"89((//MM(+((..MM'HQRL"89# %1&-nnXTn&J%K L L ' nnS)~~d++CNN44H4H# %1&-nnSn&E%F G G c"   nnS)fsl+  ##M;F;;r   c                 $    U R                  S5      $ )z5Returns a list of all registered users on the server.r{  rD  r  s    r(   	acl_usersRedis.acl_usersc      ##K00r   c                 $    U R                  S5      $ )z+Get the username for the current connectionr}  rD  r  s    r(   
acl_whoamiRedis.acl_whoamig  s    ##L11r   c                 $    U R                  S5      $ )zBTell the Redis server to rewrite the AOF file from data in memory.BGREWRITEAOFrD  r  s    r(   bgrewriteaofRedis.bgrewriteaofk      ##N33r   c                 $    U R                  S5      $ )zv
Tell the Redis server to save its data to disk.  Unlike save(),
this method is asynchronous and returns immediately.
BGSAVErD  r  s    r(   bgsaveRedis.bgsaveo  s    
 ##H--r   c                 &    U R                  SU5      $ )z/Disconnects the client at ``address`` (ip:port)r  rD  )rD   addresss     r(   client_killRedis.client_killv  s    ##M7;;r   c                    / nUbA  Sn[        U5      R                  5       U;  a  [        SU< 35      eUR                  SU45        UbJ  [	        U[
        5      (       d  [        S5      eU(       a  UR                  S5        OUR                  S5        Ub  UR                  SU45        Ub  UR                  SU45        U(       d  [        S	5      eU R                  " S
/UQ76 $ )a  
Disconnects client(s) using a variety of filter options
:param id: Kills a client by its unique ID field
:param type: Kills a client by type where type is one of 'normal',
'master', 'slave' or 'pubsub'
:param addr: Kills a client by its 'address:port'
:param skipme: If True, then the client calling the command
will not get killed even if it is identified by one of the filter
options. If skipme is not provided, the server defaults to skipme=True
)normalr   r   r  z CLIENT KILL type must be one of    TYPEz!CLIENT KILL skipme must be a bool)   SKIPMEs   YES)r     NOs   IDs   ADDRzVCLIENT KILL <filter> <value> ... ... <filter> <value> must specify at least one filterr  )strlowerr   r%   r!   r  r>  )rD   _id_typer4  skipmer'   client_typess          r(   client_kill_filterRedis.client_kill_filterz  s     BL5z!5 ,!/ 0 0KK%()fd++ CDD/0./?KK%KK$( G H H##M9D99r   c                      UbA  Sn[        U5      R                  5       U;  a  [        SU< 35      eU R                  SSU5      $ U R                  S5      $ )z
Returns a list of currently connected clients.
If type of client specified, only that type will be returned.
:param _type: optional. one of the client types (normal, master,
 replica, pubsub)
)r  r   replicar  z!CLIENT LIST _type must be one of r  r  )r  r  r   r>  )rD   r  r  s      r(   client_listRedis.client_list  sb     	8DL5z!5 ,!/ 0 0''wFF##M22r   c                 $    U R                  S5      $ )z#Returns the current connection namer~  rD  r  s    r(   client_getnameRedis.client_getname      ##$455r   c                 $    U R                  S5      $ )z!Returns the current connection idr  rD  r  s    r(   	client_idRedis.client_id  ru  r   c                 &    U R                  SU5      $ )z Sets the current connection namer  rD  rD   r   s     r(   client_setnameRedis.client_setname  s    ##$4d;;r   c                 j    S[        U5      /nU(       a  UR                  S5        U R                  " U6 $ )z
Unblocks a connection by its client id.
If ``error`` is True, unblocks the client with a special error message.
If ``error`` is False (default), the client is unblocked using the
regular timeout mechanism.
r  s   ERROR)r+   r   r>  )rD   r  errorr'   s       r(   client_unblockRedis.client_unblock  s2     !#i.1KK!##T**r   c                     [        U[        [        45      (       d  [        S5      eU R	                  S[        U5      5      $ )zn
Suspend all the Redis clients for the specified amount of time
:param timeout: milliseconds to pause clients
z'CLIENT PAUSE timeout must be an integerr  )r!   r+   r   r   r>  r  )rD   r  s     r(   client_pauseRedis.client_pause  s8    
 'C;//EFF##NCLAAr   c                 $    U R                  S5      $ )zDDisables read queries for a connection to a Redis Cluster slave node	READWRITErD  r  s    r(   	readwriteRedis.readwrite  ru  r   c                 $    U R                  S5      $ )zEEnables read queries for a connection to a Redis Cluster replica nodeREADONLYrD  r  s    r(   readonlyRedis.readonly  rW  r   c                 &    U R                  SU5      $ )z=Return a dictionary of configuration based on the ``pattern``r  rD  rD   patterns     r(   
config_getRedis.config_get  s    ##L'::r   c                 &    U R                  SX5      $ )z'Set config item ``name`` with ``value``r  rD  rD   r   r   s      r(   
config_setRedis.config_set  s    ##L$>>r   c                 $    U R                  S5      $ )zReset runtime statisticsr  rD  r  s    r(   config_resetstatRedis.config_resetstat      ##$677r   c                 $    U R                  S5      $ )zERewrite config file with the minimal change to reflect running configzCONFIG REWRITErD  r  s    r(   config_rewriteRedis.config_rewrite  r  r   c                 $    U R                  S5      $ )z2Returns the number of keys in the current databaseDBSIZErD  r  s    r(   dbsizeRedis.dbsize  s    ##H--r   c                 &    U R                  SU5      $ )z;Returns version specific meta information about a given keyr  rD  )rD   r   s     r(   debug_objectRedis.debug_object  s    ##NC88r   c                 &    U R                  SU5      $ )z$Echo the string back from the serverECHOrD  )rD   r   s     r(   echo
Redis.echo  s    ##FE22r   c                 \    / nU(       a  UR                  S5        U R                  " S/UQ76 $ )z
Delete all keys in all databases on the current host.

``asynchronous`` indicates whether the operation is
executed asynchronously by the server.
   ASYNCFLUSHALLr   r>  rD   asynchronousr'   s      r(   flushallRedis.flushall  s.     KK!##J666r   c                 \    / nU(       a  UR                  S5        U R                  " S/UQ76 $ )z
Delete all keys in the current database.

``asynchronous`` indicates whether the operation is
executed asynchronously by the server.
r  FLUSHDBr  r  s      r(   flushdbRedis.flushdb  s.     KK!##I555r   c                 &    U R                  SX5      $ )zSwap two databasesSWAPDBrD  )rD   r   seconds      r(   swapdbRedis.swapdb	  s    ##He<<r   c                 N    Uc  U R                  S5      $ U R                  SU5      $ )z
Returns a dictionary containing information about the Redis server

The ``section`` option can be used to select a specific section
of information

The section option is not supported by older versions of Redis Server,
and will generate ResponseError
r  rD  )rD   sections     r(   r   
Redis.info  s-     ?''//''88r   c                 $    U R                  S5      $ )za
Return a Python datetime object representing the last time the
Redis database was saved to disk
r  rD  r  s    r(   lastsaveRedis.lastsave  s    
 ##J//r   c	                 f   [        U/ 5      nU(       d  [        S5      e/ n	U(       a  U	R                  S5        U(       a  U	R                  S5        U(       a"  U	R                  S5        U	R                  U5        U	R                  S5        U	R                  U5        U R                  " SXSUU/U	Q76 $ )aB  
Migrate 1 or more keys from the current Redis server to a different
server specified by the ``host``, ``port`` and ``destination_db``.

The ``timeout``, specified in milliseconds, indicates the maximum
time the connection between the two servers can be idle before the
command is interrupted.

If ``copy`` is True, the specified ``keys`` are NOT deleted from
the source server.

If ``replace`` is True, this operation will overwrite the keys
on the destination server if they exist.

If ``auth`` is specified, authenticate to the destination server with
the password provided.
z!MIGRATE requires at least one keys   COPYs   REPLACEs   AUTHs   KEYSMIGRATE )r)   r   r   r%   r>  )
rD   r  r   r&   destination_dbr  copyreplaceauthrF  s
             r(   migrateRedis.migrate#  s    & D"%?@@MM'"MM*%MM'"MM$gd##It2~$+6.46 	6r   c                 $    U R                  SXUS9$ )z8Return the encoding, idletime, or refcount about the keyr  )r{   rD  )rD   r{   r   s      r(   objectRedis.objectF  s    ##Hhh#OOr   c                 $    U R                  S5      $ )z#Return a dictionary of memory statsr  rD  r  s    r(   memory_statsRedis.memory_statsJ  r}  r   c                 ~    / n[        U[        5      (       a  UR                  SU/5        U R                  " SU/UQ76 $ )z
Return the total memory usage for key, its value and associated
administrative overheads.

For nested data structures, ``samples`` is the number of elements to
sample. If left unspecified, the server's default is 5. Use 0 to sample
all elements.
s   SAMPLESr  )r!   r+   r%   r>  )rD   r   samplesr'   s       r(   memory_usageRedis.memory_usageN  s?     gs##KKW-.##NC?$??r   c                 $    U R                  S5      $ )z:Attempts to purge dirty pages for reclamation by allocatorr  rD  r  s    r(   memory_purgeRedis.memory_purge\  r}  r   c                 $    U R                  S5      $ )zPing the Redis serverr  rD  r  s    r(   r5  
Redis.ping`  s    ##F++r   c                 $    U R                  S5      $ )zU
Tell the Redis server to save its data to disk,
blocking until the save is complete
SAVErD  r  s    r(   save
Redis.saved      
 ##F++r   c                 B    [         R                  " [        S5      5        g)z"Redis Sentinel's SENTINEL command.z%Use the individual sentinel_* methodsNr  r  r  rD   r'   s     r(   r   Redis.sentinelk  s    FG	Ir   c                 &    U R                  SU5      $ )z:Returns a (host, port) pair for the given ``service_name``r  rD  rD   service_names     r(    sentinel_get_master_addr_by_name&Redis.sentinel_get_master_addr_by_namep  s    ##$F$02 	2r   c                 &    U R                  SU5      $ )z<Returns a dictionary containing the specified masters state.r  rD  r  s     r(   sentinel_masterRedis.sentinel_masteru      ##$5|DDr   c                 $    U R                  S5      $ )z>Returns a list of dictionaries containing each master's state.r  rD  r  s    r(   sentinel_mastersRedis.sentinel_mastersy  r  r   c                 (    U R                  SXX45      $ )z,Add a new master to Sentinel to be monitoredr  rD  )rD   r   ipr   r   s        r(   sentinel_monitorRedis.sentinel_monitor}  s    ##$6$OOr   c                 &    U R                  SU5      $ )z*Remove a master from Sentinel's monitoringr  rD  r  s     r(   sentinel_removeRedis.sentinel_remove  s    ##$5t<<r   c                 &    U R                  SU5      $ )z0Returns a list of sentinels for ``service_name``r  rD  r  s     r(   sentinel_sentinelsRedis.sentinel_sentinels  s    ##$8,GGr   c                 (    U R                  SXU5      $ )z5Set Sentinel monitoring parameters for a given masterr  rD  )rD   r   optionr   s       r(   sentinel_setRedis.sentinel_set  s    ##ND%HHr   c                 &    U R                  SU5      $ )z-Returns a list of slaves for ``service_name``r  rD  r  s     r(   sentinel_slavesRedis.sentinel_slaves  r  r   c                     U(       a  U(       a  [        S5      eS/nU(       a  UR                  S5        U(       a  UR                  S5         U R                  " U6   [	        S5      e! [         a     gf = f)aF  Shutdown the Redis server.  If Redis has persistence configured,
data will be flushed before shutdown.  If the "save" option is set,
a data flush will be attempted even if there is no persistence
configured.  If the "nosave" option is set, no data flush will be
attempted.  The "save" and "nosave" options cannot both be set.
z+SHUTDOWN save and nosave cannot both be setSHUTDOWNr  NOSAVENzSHUTDOWN seems to have failed.)r   r   r>  r   r   )rD   r  nosaver'   s       r(   shutdownRedis.shutdown  so     FIJJ|KKKK!	  $' 9::  		s   A( (
A54A5c                 X    Uc  Uc  U R                  SSS5      $ U R                  SX5      $ )z
Set the server to be a replicated slave of the instance identified
by the ``host`` and ``port``. If called without arguments, the
instance is promoted to a master instead.
SLAVEOFr  s   ONErD  )rD   r  r   s      r(   slaveofRedis.slaveof  s5     <DL''	5&AA##It::r   c                     S/nUb  UR                  U5        U R                  R                  R                  SS5      nU R                  " USU06$ )z_
Get the entries from the slowlog. If ``num`` is specified, get the
most recent ``num`` items.
r  r  F)r   r  connection_kwargsrW   r>  )rD   numr'   r  s       r(   slowlog_getRedis.slowlog_get  sU    
 ?KK//AAEE'##TM<LMMr   c                 $    U R                  S5      $ )z&Get the number of items in the slowlogr  rD  r  s    r(   slowlog_lenRedis.slowlog_len  rP  r   c                 $    U R                  S5      $ )zRemove all items in the slowlogr  rD  r  s    r(   slowlog_resetRedis.slowlog_reset  s    ##O44r   c                 $    U R                  S5      $ )zj
Returns the server time as a 2-item tuple of ints:
(seconds since epoch, microseconds into this second).
r  rD  r  s    r(   r  
Redis.time  r  r   c                 &    U R                  SX5      $ )z
Redis synchronous replication
That returns the number of replicas that processed the query when
we finally have at least ``num_replicas``, or when the ``timeout`` was
reached.
WAITrD  )rD   num_replicasr  s      r(   wait
Redis.wait  s     ##FLBBr   c                 &    U R                  SX5      $ )z
Appends the string ``value`` to the value at ``key``. If ``key``
doesn't already exist, create it with a value of ``value``.
Returns the new length of the value at ``key``.
APPENDrD  )rD   r   r   s      r(   r   Redis.append  s     ##Hc99r   c                     U/nUb&  Ub#  UR                  U5        UR                  U5        OUb  Ub  Ub  Uc  [        S5      eU R                  " S/UQ76 $ )z
Returns the count of set bits in the value of ``key``.  Optional
``start`` and ``end`` paramaters indicate which bytes to consider
z$Both start and end must be specifiedBITCOUNT)r   r   r>  )rD   r   startendparamss        r(   bitcountRedis.bitcount  sb    
 MM% MM#CKU]BCC##J888r   c                     [        XUS9$ )zk
Return a BitFieldOperation instance to conveniently construct one or
more bitfield operations on ``key``.
)default_overflow)BitFieldOperation)rD   r   rH  s      r(   bitfieldRedis.bitfield  s    
 !=MNNr   c                 *    U R                   " SX/UQ76 $ )zd
Perform a bitwise operation using ``operation`` between ``keys`` and
store the result in ``dest``.
BITOPrD  )rD   	operationdestr&   s       r(   bitopRedis.bitop  s    
 ##GYDtDDr   c                     US;  a  [        S5      eX/nUSL=(       a    UR                  U5        Ub  Ub  UR                  U5        OUc  Ub  [        S5      eU R                  " S/UQ76 $ )z
Return the position of the first bit set to 1 or 0 in a string.
``start`` and ``end`` difines search range. The range is interpreted
as a range of bytes and not a range of bits, so start=0 and end=2
means to look at the first three bytes.
)r   r   zbit must be 0 or 1Nz0start argument is not set, when end is specifiedBITPOSr   r   r>  )rD   r   bitrB  rC  rD  s         r(   bitposRedis.bitpos  s}     f011T2fmmE2MM#]s 4 5 5##H6v66r   c                 $    U R                  X5      $ )s
Decrements the value of ``key`` by ``amount``.  If no key exists,
the value will be initialized as 0 - ``amount``
)decrbyrD   r   amounts      r(   decr
Redis.decr  s     {{4((r   c                 &    U R                  SX5      $ )rY  DECRBYrD  r[  s      r(   rZ  Redis.decrby  s    
 ##Hd;;r   c                 (    U R                   " S/UQ76 $ )z.Delete one or more keys specified by ``names``DELrD  rD   namess     r(   deleteRedis.delete  s    ##E2E22r   c                 &    U R                  U5        g r   )rf  r  s     r(   rQ   Redis.__delitem__!  s    Dr   c                 &    U R                  SU5      $ )z{
Return a serialized version of the value stored at the specified key.
If key does not exist a nil bulk reply is returned.
DUMPrD  r  s     r(   dump
Redis.dump$  s    
 ##FD11r   c                 (    U R                   " S/UQ76 $ )z*Returns the number of ``names`` that existEXISTSrD  rd  s     r(   existsRedis.exists+      ##H5u55r   c                     [        U[        R                  5      (       a  [        UR                  " 5       5      nU R                  SX5      $ )z
Set an expire flag on key ``name`` for ``time`` seconds. ``time``
can be represented by an integer or a Python timedelta object.
EXPIREr!   r-   	timedeltar+   total_secondsr>  rD   r   r  s      r(   expireRedis.expire0  s=    
 dH..//t))+,D##Hd99r   c                     [        U[        R                  5      (       a-  [        [        R                  " UR                  5       5      5      nU R                  SX5      $ )z
Set an expire flag on key ``name``. ``when`` can be represented
as an integer indicating unix time or a Python datetime object.
EXPIREAT)r!   r-   r+   mod_timemktime	timetupler>  )rD   r   whens      r(   expireatRedis.expireat9  sD    
 dH--..xt~~'789D##J;;r   c                 &    U R                  SU5      $ )zD
Return the value at key ``name``, or None if the key doesn't exist
GETrD  r  s     r(   rW   	Redis.getB  s     ##E400r   c                 D    U R                  U5      nUb  U$ [        U5      e)zO
Return the value at key ``name``, raises a KeyError if the key
doesn't exist.
)rW   KeyErrorr  s      r(   rT   Redis.__getitem__H  s&    
 Ltnr   c                 &    U R                  SX5      $ )z@Returns a boolean indicating the value of ``offset`` in ``name``GETBITrD  )rD   r   offsets      r(   getbitRedis.getbitR  s    ##Hd;;r   c                 (    U R                  SXU5      $ )z
Returns the substring of the string value stored at ``key``,
determined by the offsets ``start`` and ``end`` (both are inclusive)
GETRANGErD  )rD   r   rB  rC  s       r(   getrangeRedis.getrangeV  s    
 ##JC@@r   c                 &    U R                  SX5      $ )zc
Sets the value at key ``name`` to ``value``
and returns the old value at key ``name`` atomically.
GETSETrD  r  s      r(   getsetRedis.getset]  s    
 ##Hd::r   c                 $    U R                  X5      $ )o
Increments the value of ``key`` by ``amount``.  If no key exists,
the value will be initialized as ``amount``
)incrbyr[  s      r(   incr
Redis.incrd  s    
 {{4((r   c                 &    U R                  SX5      $ )r  INCRBYrD  r[  s      r(   r  Redis.incrbyk  s     ##Hd;;r   c                 &    U R                  SX5      $ )z|
Increments the value at key ``name`` by floating ``amount``.
If no key exists, the value will be initialized as ``amount``
INCRBYFLOATrD  r[  s      r(   incrbyfloatRedis.incrbyfloatt  s    
 ##M4@@r   c                 &    U R                  SU5      $ )z+Returns a list of keys matching ``pattern``KEYSrD  r  s     r(   r&   
Redis.keys{  s    ##FG44r   c                 h    [        X5      n0 nU(       d	  / U[        '   U R                  " S/UQ70 UD6$ )z:
Returns a list of values ordered identically to ``keys``
MGET)r)   r   r>  )rD   r&   r'   r   s       r(   mget
Redis.mget  s;     D'&(GN###F=T=W==r   c                 r    / n[        U5       H  nUR                  U5        M     U R                  " S/UQ76 $ )z
Sets key/values based on a mapping. Mapping is a dictionary of
key/value pairs. Both keys and values should be strings or types that
can be cast to a string via str().
MSETr   r%   r>  rD   mappingitemsr
  s       r(   mset
Redis.mset  s:     g&DLL '##F3U33r   c                 r    / n[        U5       H  nUR                  U5        M     U R                  " S/UQ76 $ )a  
Sets key/values based on a mapping if none of the keys are already set.
Mapping is a dictionary of key/value pairs. Both keys and values
should be strings or types that can be cast to a string via str().
Returns a boolean indicating if the operation was successful.
MSETNXr  r  s       r(   msetnxRedis.msetnx  s:     g&DLL '##H5u55r   c                 &    U R                  SX5      $ )z;Moves the key ``name`` to a different Redis database ``db``MOVErD  )rD   r   r  s      r(   move
Redis.move  s    ##FD55r   c                 &    U R                  SU5      $ )z!Removes an expiration on ``name``PERSISTrD  r  s     r(   persistRedis.persist      ##It44r   c                     [        U[        R                  5      (       a  [        UR                  " 5       S-  5      nU R                  SX5      $ )z
Set an expire flag on key ``name`` for ``time`` milliseconds.
``time`` can be represented by an integer or a Python timedelta
object.
  PEXPIREru  rx  s      r(   pexpireRedis.pexpire  sB     dH..//t))+d23D##It::r   c                     [        U[        R                  5      (       aK  [        UR                  S-  5      n[        [        R
                  " UR                  5       5      5      S-  U-   nU R                  SX5      $ )z
Set an expire flag on key ``name``. ``when`` can be represented
as an integer representing unix time in milliseconds (unix time * 1000)
or a Python datetime object.
r  	PEXPIREAT)r!   r-   r+   microsecondr}  r~  r  r>  )rD   r   r  mss       r(   	pexpireatRedis.pexpireat  sc     dH--..T%%,-Bxt~~'789D@2ED##K<<r   c                     [        U[        R                  5      (       a  [        UR	                  5       S-  5      nU R                  SXU5      $ )z
Set the value of key ``name`` to ``value`` that expires in ``time_ms``
milliseconds. ``time_ms`` can be represented by an integer or a Python
timedelta object
r  PSETEXru  )rD   r   time_msr   s       r(   psetexRedis.psetex  sD     gx1122'//1D89G##HdUCCr   c                 &    U R                  SU5      $ )zEReturns the number of milliseconds until the key ``name`` will expirePTTLrD  r  s     r(   pttl
Redis.pttl      ##FD11r   c                 $    U R                  S5      $ )z Returns the name of a random keyr  rD  r  s    r(   	randomkeyRedis.randomkey  ru  r   c                 &    U R                  SX5      $ )z
Rename key ``src`` to ``dst``
RENAMErD  rD   srcdsts      r(   renameRedis.rename  s     ##Hc77r   c                 &    U R                  SX5      $ )z>Rename key ``src`` to ``dst`` if ``dst`` doesn't already existRENAMENXrD  r  s      r(   renamenxRedis.renamenx  s    ##J99r   c                 `    XU/nU(       a  UR                  S5        U R                  " S/UQ76 $ )zS
Create a key using the provided serialized value, previously obtained
using DUMP.
REPLACERESTOREr  )rD   r   ttlr   r  rD  s         r(   restoreRedis.restore  s3    
 U#MM)$##I777r   c                 8   X/nUbZ  UR                  S5        [        U[        R                  5      (       a  [	        UR                  5       5      nUR                  U5        Ub]  UR                  S5        [        U[        R                  5      (       a  [	        UR                  5       S-  5      nUR                  U5        U(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        U R                  " S/UQ76 $ )a  
Set the value at key ``name`` to ``value``

``ex`` sets an expire flag on key ``name`` for ``ex`` seconds.

``px`` sets an expire flag on key ``name`` for ``px`` milliseconds.

``nx`` if set to True, set the value at key ``name`` to ``value`` only
    if it does not exist.

``xx`` if set to True, set the value at key ``name`` to ``value`` only
    if it already exists.

``keepttl`` if True, retain the time to live associated with the key.
    (Available since Redis 6.0)
EXPXr  NXXXKEEPTTLr  )r   r!   r-   rv  r+   rw  r>  )	rD   r   r   expxnxxxkeepttlrF  s	            r(   r   	Redis.set  s    $ >MM$"h0011))+,MM">MM$"h0011))+d23MM"MM$MM$MM)$##E3F33r   c                 &    U R                  X5        g r   rm  r  s      r(   r[   Redis.__setitem__  s    r   c                 P    U=(       a    S=(       d    SnU R                  SXU5      $ )zn
Flag the ``offset`` in ``name`` as ``value``. Returns a boolean
indicating the previous value of ``offset``.
r   r   SETBITrD  rD   r   r  r   s       r(   setbitRedis.setbit  s'    
 ! q##HdEBBr   c                     [        U[        R                  5      (       a  [        UR                  " 5       5      nU R                  SXU5      $ )z
Set the value of key ``name`` to ``value`` that expires in ``time``
seconds. ``time`` can be represented by an integer or a Python
timedelta object.
SETEXru  )rD   r   r  r   s       r(   setexRedis.setex  s?     dH..//t))+,D##GT??r   c                 &    U R                  SX5      $ )z?Set the value of key ``name`` to ``value`` if key doesn't existSETNXrD  r  s      r(   setnxRedis.setnx   s    ##GT99r   c                 (    U R                  SXU5      $ )a  
Overwrite bytes in the value of ``name`` starting at ``offset`` with
``value``. If ``offset`` plus the length of ``value`` exceeds the
length of the original value, the new value will be larger than before.
If ``offset`` exceeds the length of the original value, null bytes
will be used to pad between the end of the previous value and the start
of what's being injected.

Returns the length of the new string.
SETRANGErD  r  s       r(   setrangeRedis.setrange$  s     ##JeDDr   c                 &    U R                  SU5      $ )z:Return the number of bytes stored in the value of ``name``STRLENrD  r  s     r(   strlenRedis.strlen1  s    ##Hd33r   c                 (    U R                  SXU5      $ )z
Return a substring of the string at key ``name``. ``start`` and ``end``
are 0-based integers specifying the portion of the string to return.
SUBSTRrD  rD   r   rB  rC  s       r(   substrRedis.substr5  s    
 ##Hd3??r   c                 (    U R                   " S/UQ76 $ )z[
Alters the last access time of a key(s) ``*args``. A key is ignored
if it does not exist.
TOUCHrD  r  s     r(   touchRedis.touch<  s    
 ##G3d33r   c                 &    U R                  SU5      $ )z@Returns the number of seconds until the key ``name`` will expireTTLrD  r  s     r(   r  	Redis.ttlC  s    ##E400r   c                 &    U R                  SU5      $ )z Returns the type of key ``name``TYPErD  r  s     r(   rO  
Redis.typeG  r  r   c                 B    [         R                  " [        S5      5        g)zH
Watches the values at keys ``names``, or None if the key doesn't exist
z!Call WATCH from a Pipeline objectNr  rd  s     r(   r  Redis.watchK  s     	()LMNr   c                 B    [         R                  " [        S5      5        g)zG
Unwatches the value at key ``name``, or None of the key doesn't exist
z#Call UNWATCH from a Pipeline objectNr  r  s    r(   unwatchRedis.unwatchQ  s     	DE	Gr   c                 (    U R                   " S/UQ76 $ )z.Unlink one or more keys specified by ``names``UNLINKrD  rd  s     r(   unlinkRedis.unlinkX  rr  r   c                 l    Uc  Sn[        US5      nUR                  U5        U R                  " S/UQ76 $ )a  
LPOP a value off of the first non-empty list
named in the ``keys`` list.

If none of the lists in ``keys`` has a value to LPOP, then block
for ``timeout`` seconds, or until a value gets pushed on to one
of the lists.

If timeout is 0, then block indefinitely.
Nr   BLPOPr)   r   r>  rD   r&   r  s      r(   blpopRedis.blpop]  <     ?GD$'G##G3d33r   c                 l    Uc  Sn[        US5      nUR                  U5        U R                  " S/UQ76 $ )a  
RPOP a value off of the first non-empty list
named in the ``keys`` list.

If none of the lists in ``keys`` has a value to RPOP, then block
for ``timeout`` seconds, or until a value gets pushed on to one
of the lists.

If timeout is 0, then block indefinitely.
Nr   BRPOPr$  r%  s      r(   brpopRedis.brpopn  r(  r   c                 2    Uc  SnU R                  SXU5      $ )z
Pop a value off the tail of ``src``, push it on the head of ``dst``
and then return it.

This command blocks until a value is in ``src`` or until ``timeout``
seconds elapse, whichever is first. A ``timeout`` value of 0 blocks
forever.
r   
BRPOPLPUSHrD  )rD   r  r  r  s       r(   
brpoplpushRedis.brpoplpush  s#     ?G##L#GDDr   c                 &    U R                  SX5      $ )z
Return the item from list ``name`` at position ``index``

Negative indexes are supported and will return an item at the
end of the list
LINDEXrD  )rD   r   indexs      r(   lindexRedis.lindex  s     ##Hd::r   c                 (    U R                  SXX45      $ )z
Insert ``value`` in list ``name`` either immediately before or after
[``where``] ``refvalue``

Returns the new length of the list on success or -1 if ``refvalue``
is not in the list.
LINSERTrD  )rD   r   whererefvaluer   s        r(   linsertRedis.linsert  s     ##ItHLLr   c                 &    U R                  SU5      $ )z&Return the length of the list ``name``LLENrD  r  s     r(   llen
Redis.llen  r  r   c                 &    U R                  SU5      $ )z5Remove and return the first item of the list ``name``LPOPrD  r  s     r(   lpop
Redis.lpop  r  r   c                 *    U R                   " SU/UQ76 $ )z2Push ``values`` onto the head of the list ``name``LPUSHrD  rD   r   r   s      r(   lpushRedis.lpush      ##GT;F;;r   c                 &    U R                  SX5      $ )zDPush ``value`` onto the head of the list ``name`` if ``name`` existsLPUSHXrD  r  s      r(   lpushxRedis.lpushx      ##Hd::r   c                 (    U R                  SXU5      $ )z
Return a slice of the list ``name`` between
position ``start`` and ``end``

``start`` and ``end`` can be negative numbers just like
Python slicing notation
LRANGErD  r  s       r(   lrangeRedis.lrange  s     ##Hd3??r   c                 (    U R                  SXU5      $ )ap  
Remove the first ``count`` occurrences of elements equal to ``value``
from the list stored at ``name``.

The count argument influences the operation in the following ways:
    count > 0: Remove elements equal to value moving from head to tail.
    count < 0: Remove elements equal to value moving from tail to head.
    count = 0: Remove all elements equal to value.
LREMrD  )rD   r   countr   s       r(   lrem
Redis.lrem  s     ##FD??r   c                 (    U R                  SXU5      $ )z.Set ``position`` of list ``name`` to ``value``LSETrD  )rD   r   r3  r   s       r(   lset
Redis.lset  s    ##FD??r   c                 (    U R                  SXU5      $ )z
Trim the list ``name``, removing all values not within the slice
between ``start`` and ``end``

``start`` and ``end`` can be negative numbers just like
Python slicing notation
LTRIMrD  r  s       r(   ltrimRedis.ltrim  s     ##GT#>>r   c                 &    U R                  SU5      $ )z4Remove and return the last item of the list ``name``RPOPrD  r  s     r(   rpop
Redis.rpop  r  r   c                 &    U R                  SX5      $ )zj
RPOP a value off of the ``src`` list and atomically LPUSH it
on to the ``dst`` list.  Returns the value.
	RPOPLPUSHrD  r  s      r(   	rpoplpushRedis.rpoplpush  s    
 ##K::r   c                 *    U R                   " SU/UQ76 $ )z2Push ``values`` onto the tail of the list ``name``RPUSHrD  rF  s      r(   rpushRedis.rpush  rI  r   c                 &    U R                  SX5      $ )zDPush ``value`` onto the tail of the list ``name`` if ``name`` existsRPUSHXrD  r  s      r(   rpushxRedis.rpushx  rN  r   c
                 R   Ub  Ub  Ub  Uc  [        S5      eU/n
Ub"  U
R                  S5        U
R                  U5        Ub6  Ub3  U
R                  S5        U
R                  U5        U
R                  U5        Ubi  [        U[        [        45      (       a#  U
R                  S5        U
R                  U5        O+U H%  nU
R                  S5        U
R                  U5        M'     U(       a  U
R                  S5        U(       a  U
R                  S5        Ub"  U
R                  S5        U
R                  U5        U	(       a<  U(       a*  [        U[        [        45      (       d  [        U5      S	:  a  [        S
5      eSU	(       a  [        U5      OS0nU R                  " S/U
Q70 UD6$ )a!  
Sort and return the list, set or sorted set at ``name``.

``start`` and ``num`` allow for paging through the sorted data

``by`` allows using an external key to weight and sort the items.
    Use an "*" to indicate where in the key the item value is located

``get`` allows for returning items from external keys rather than the
    sorted data itself.  Use an "*" to indicate where in the key
    the item value is located

``desc`` allows for reversing the sort

``alpha`` allows for sorting lexicographically rather than numerically

``store`` allows for storing the result of the sort into
    the key ``store``

``groups`` if set to True and if ``get`` contains at least two
    elements, sort will return a list of tuples, each containing the
    values fetched from the arguments to ``get``.

N,``start`` and ``num`` must both be specifieds   BY   LIMITs   GET   DESCs   ALPHA   STOREr   zVwhen using "groups" the "get" argument must be specified and contain at least two keysr   ri  )r   r   r!   r"   r   lenr>  )rD   r   rB  r-  byrW   descalphar@  r   rF  gr   s                r(   sort
Redis.sort  sh   4 #+U]JKK>MM% MM"MM(#MM% MM#?
 #z233f%c"AMM&)MM!$  MM'"MM(#MM(#MM% *S5**=>>#c(Q, !+ , , SXT:##F?V?w??r   c                     U/nUb  UR                  SU/5        Ub  UR                  SU/5        Ub  UR                  SU/5        U R                  " S/UQ76 $ )a  
Incrementally return lists of key names. Also return a cursor
indicating the scan position.

``match`` allows for filtering the keys by pattern

``count`` provides a hint to Redis about the number of keys to
    return per batch.

``_type`` filters the returned values by a particular Redis type.
    Stock Redis instances allow for the following types:
    HASH, LIST, SET, STREAM, STRING, ZSET
    Additionally, Redis modules can expose other types as well.
   MATCH   COUNTr  r  r%   r>  )rD   r  matchrU  r  rF  s         r(   scan
Redis.scan*  sf     MM8U+,MM8U+,MM7E*+##F4V44r   c              #   l   #    SnUS:w  a(  U R                  XAX#S9u  pEU H  nUv   M	     US:w  a  M'  gg7f)a  
Make an iterator using the SCAN command so that the client doesn't
need to remember the cursor position.

``match`` allows for filtering the keys by pattern

``count`` provides a hint to Redis about the number of keys to
    return per batch.

``_type`` filters the returned values by a particular Redis type.
    Stock Redis instances allow for the following types:
    HASH, LIST, SET, STREAM, STRING, ZSET
    Additionally, Redis modules can expose other types as well.
0r   )r  r  rU  r  N)r  )rD   r  rU  r  r  rE   r   s          r(   	scan_iterRedis.scan_iterB  sE      k99F+0 % ?LF
  k   .44c                     X/nUb  UR                  SU/5        Ub  UR                  SU/5        U R                  " S/UQ76 $ )z
Incrementally return lists of elements in a set. Also return a cursor
indicating the scan position.

``match`` allows for filtering the keys by pattern

``count`` allows for hint the minimum number of returns
r}  r~  r  r  rD   r   r  r  rU  rF  s         r(   sscanRedis.sscanX  O     MM8U+,MM8U+,##G5f55r   c              #   l   #    SnUS:w  a(  U R                  XX#S9u  pEU H  nUv   M	     US:w  a  M'  gg7f)z
Make an iterator using the SSCAN command so that the client doesn't
need to remember the cursor position.

``match`` allows for filtering the keys by pattern

``count`` allows for hint the minimum number of returns
r  r   r  r  rU  N)r  rD   r   r  rU  r  rE   r   s          r(   
sscan_iterRedis.sscan_iterh  sF      k::d,1 & @LF
  kr  c                     X/nUb  UR                  SU/5        Ub  UR                  SU/5        U R                  " S/UQ76 $ )z
Incrementally return key/value slices in a hash. Also return a cursor
indicating the scan position.

``match`` allows for filtering the keys by pattern

``count`` allows for hint the minimum number of returns
r}  r~  r  r  r  s         r(   hscanRedis.hscanx  r  r   c              #      #    SnUS:w  a6  U R                  XX#S9u  pEUR                  5        H  nUv   M	     US:w  a  M5  gg7f)z
Make an iterator using the HSCAN command so that the client doesn't
need to remember the cursor position.

``match`` allows for filtering the keys by pattern

``count`` allows for hint the minimum number of returns
r  r   r  N)r  r  r  s          r(   
hscan_iterRedis.hscan_iter  sL      k::d,1 & @LF


 % ks   <A Ac                     X/nUb  UR                  SU/5        Ub  UR                  SU/5        SU0nU R                  " S/UQ70 UD6$ )a  
Incrementally return lists of elements in a sorted set. Also return a
cursor indicating the scan position.

``match`` allows for filtering the keys by pattern

``count`` allows for hint the minimum number of returns

``score_cast_func`` a callable used to cast the score return value
r}  r~  r   r  r  )rD   r   r  r  rU  r   rF  r   s           r(   zscanRedis.zscan  s^     MM8U+,MM8U+,$o6##G@f@@@r   c              #   p   #    SnUS:w  a*  U R                  XUUUS9u  pVU H  nUv   M	     US:w  a  M)  gg7f)a  
Make an iterator using the ZSCAN command so that the client doesn't
need to remember the cursor position.

``match`` allows for filtering the keys by pattern

``count`` allows for hint the minimum number of returns

``score_cast_func`` a callable used to cast the score return value
r  r   )r  r  rU  r   N)r  )rD   r   r  rU  r   r  rE   r   s           r(   
zscan_iterRedis.zscan_iter  sM      k::d,16E & GLF 
 	 ks   066c                 *    U R                   " SU/UQ76 $ )z Add ``value(s)`` to set ``name``SADDrD  rF  s      r(   sadd
Redis.sadd      ##FD:6::r   c                 &    U R                  SU5      $ )z-Return the number of elements in set ``name``SCARDrD  r  s     r(   scardRedis.scard      ##GT22r   c                 >    [        X5      nU R                  " S/UQ76 $ )z3Return the difference of sets specified by ``keys``SDIFFr)   r>  rD   r&   r'   s      r(   sdiffRedis.sdiff  s"    D'##G3d33r   c                 @    [        X#5      nU R                  " SU/UQ76 $ )z
Store the difference of sets specified by ``keys`` into a new
set named ``dest``.  Returns the number of keys in the new set.

SDIFFSTOREr  rD   rO  r&   r'   s       r(   
sdiffstoreRedis.sdiffstore  s&    
 D'##L$>>>r   c                 >    [        X5      nU R                  " S/UQ76 $ )z5Return the intersection of sets specified by ``keys``SINTERr  r  s      r(   sinterRedis.sinter  "    D'##H4t44r   c                 @    [        X#5      nU R                  " SU/UQ76 $ )z
Store the intersection of sets specified by ``keys`` into a new
set named ``dest``.  Returns the number of keys in the new set.
SINTERSTOREr  r  s       r(   sinterstoreRedis.sinterstore  &    
 D'##M4?$??r   c                 &    U R                  SX5      $ )zDReturn a boolean indicating if ``value`` is a member of set ``name``	SISMEMBERrD  r  s      r(   	sismemberRedis.sismember  s    ##K==r   c                 &    U R                  SU5      $ )z&Return all members of the set ``name``SMEMBERSrD  r  s     r(   smembersRedis.smembers  s    ##J55r   c                 (    U R                  SXU5      $ )z9Move ``value`` from set ``src`` to set ``dst`` atomicallySMOVErD  )rD   r  r  r   s       r(   smoveRedis.smove  s    ##GSu==r   c                 X    USL=(       a    U/=(       d    / nU R                   " SU/UQ76 $ )z1Remove and return a random member of set ``name``NSPOPrD  )rD   r   rU  r'   s       r(   spop
Redis.spop  s0    T!.w4"##FD8488r   c                 X    USL=(       a    U/=(       d    / nU R                   " SU/UQ76 $ )z
If ``number`` is None, returns a random member of set ``name``.

If ``number`` is supplied, returns a list of ``number`` random
members of set ``name``. Note this is only available when running
Redis 2.6+.
NSRANDMEMBERrD  )rD   r   numberr'   s       r(   srandmemberRedis.srandmember  s2     d"06B##M4?$??r   c                 *    U R                   " SU/UQ76 $ )z#Remove ``values`` from set ``name``SREMrD  rF  s      r(   srem
Redis.srem  r  r   c                 >    [        X5      nU R                  " S/UQ76 $ )z.Return the union of sets specified by ``keys``SUNIONr  r  s      r(   sunionRedis.sunion	  r  r   c                 @    [        X#5      nU R                  " SU/UQ76 $ )zz
Store the union of sets specified by ``keys`` into a new
set named ``dest``.  Returns the number of keys in the new set.
SUNIONSTOREr  r  s       r(   sunionstoreRedis.sunionstore	  r  r   c                 *    U R                   " SX/UQ76 $ )z
Acknowledges the successful processing of one or more messages.
name: name of the stream.
groupname: name of the consumer group.
*ids: message ids to acknowlege.
XACKrD  )rD   r   	groupnameidss       r(   xack
Redis.xack	  s     ##FDBcBBr   c                    / nUbo  [        U[        [        45      (       a  US:  a  [        S5      eUR	                  S5        U(       a  UR	                  S5        UR	                  [        U5      5        UR	                  U5        [        U[        5      (       a  [        U5      S:X  a  [        S5      e[        U5       H  nUR                  U5        M     U R                  " SU/UQ76 $ )a  
Add to a stream.
name: name of the stream
fields: dict of field/value pairs to insert into the stream
id: Location to insert this record. By default it is appended.
maxlen: truncate old stream members beyond this size
approximate: actual stream length may be slightly more than maxlen

r   z&XADD maxlen must be a positive integer   MAXLEN   ~r   z$XADD fields must be a non-empty dictXADD)r!   r+   r   r   r   r  r3   ru  r   r%   r>  )rD   r   fieldsr  maxlenapproximaterF  r
  s           r(   xadd
Redis.xadd	  s     fsDk22fqj HIIMM)$d#MM#f+&b&$''3v;!+;BCCf%DMM$ &##FD:6::r   c                    [        U[        [        45      (       a  US:  a  [        S5      e[        U[        [
        45      (       a  U(       d  [        S5      e0 nXU[        U5      /nUR                  [	        U5      5        UbB  [        U[        [        45      (       d  [        S5      eUR                  S[        U5      45        UbB  [        U[        [        45      (       d  [        S5      eUR                  S[        U5      45        UbB  [        U[        [        45      (       d  [        S5      eUR                  S	[        U5      45        U	(       a1  [        U	[        5      (       d  [        S
5      eUR                  S5        U
(       a6  [        U
[        5      (       d  [        S5      eUR                  S5        SUS'   U R                  " S/UQ70 UD6$ )a
  
Changes the ownership of a pending message.
name: name of the stream.
groupname: name of the consumer group.
consumername: name of a consumer that claims the message.
min_idle_time: filter messages that were idle less than this amount of
milliseconds
message_ids: non-empty list or tuple of message IDs to claim
idle: optional. Set the idle time (last time it was delivered) of the
 message in ms
time: optional integer. This is the same as idle but instead of a
 relative amount of milliseconds, it sets the idle time to a specific
 Unix time (in milliseconds).
retrycount: optional integer. set the retry counter to the specified
 value. This counter is incremented every time a message is delivered
 again.
force: optional boolean, false by default. Creates the pending message
 entry in the PEL even if certain specified IDs are not already in the
 PEL assigned to a different client.
justid: optional boolean, false by default. Return just an array of IDs
 of messages successfully claimed, without returning the actual message
r   z3XCLAIM min_idle_time must be a non negative integerzLXCLAIM message_ids must be a non empty list or tuple of message IDs to claimzXCLAIM idle must be an integers   IDLEzXCLAIM time must be an integers   TIMEz$XCLAIM retrycount must be an integers
   RETRYCOUNTzXCLAIM force must be a booleans   FORCEzXCLAIM justid must be a booleans   JUSTIDTr   r  )r!   r+   r   r   r#   rk  r  r%   r  r   r>  )rD   r   r  consumernamemin_idle_timemessage_idsidler  
retrycountrc  justidr   rF  s                r(   xclaimRedis.xclaim3	  s   2 -#t559J & ' '+e}55[ < = = <]1CDd;'(dS$K00 @AAMM7CI./dS$K00 @AAMM7CI./!j3+66 FGGMM=#j/:;eT** @AAMM(#fd++ ABBMM)$%)F>"##H@v@@@r   c                 *    U R                   " SU/UQ76 $ )zd
Deletes one or more messages from a stream.
name: name of the stream.
*ids: message ids to delete.
XDELrD  )rD   r   r  s      r(   xdel
Redis.xdelo	  s     ##FD7377r   c                 Z    SXU/nU(       a  UR                  S5        U R                  " U6 $ )z
Create a new consumer group associated with a stream.
name: name of the stream.
groupname: name of the consumer group.
id: ID of the last item in the stream to consider already delivered.
r  s   MKSTREAMr  )rD   r   r  r  mkstreamrF  s         r(   xgroup_createRedis.xgroup_createw	  s0     "4B7MM+&##V,,r   c                 (    U R                  SXU5      $ )z
Remove a specific consumer from a consumer group.
Returns the number of pending messages that the consumer had before it
was deleted.
name: name of the stream.
groupname: name of the consumer group.
consumername: name of consumer to delete
r  rD  )rD   r   r  r  s       r(   xgroup_delconsumerRedis.xgroup_delconsumer	  s     ##$8$$02 	2r   c                 &    U R                  SX5      $ )z\
Destroy a consumer group.
name: name of the stream.
groupname: name of the consumer group.
r  rD  rD   r   r  s      r(   xgroup_destroyRedis.xgroup_destroy	  s     ##$4dFFr   c                 (    U R                  SXU5      $ )z
Set the consumer group last delivered ID to something else.
name: name of the stream.
groupname: name of the consumer group.
id: ID of the last item in the stream to consider already delivered.
r  rD  )rD   r   r  r  s       r(   xgroup_setidRedis.xgroup_setid	  s     ##NDRHHr   c                 &    U R                  SX5      $ )z
Returns general information about the consumers in the group.
name: name of the stream.
groupname: name of the consumer group.
r  rD  r  s      r(   xinfo_consumersRedis.xinfo_consumers	  s     ##$5tGGr   c                 &    U R                  SU5      $ )z`
Returns general information about the consumer groups of the stream.
name: name of the stream.
r  rD  r  s     r(   xinfo_groupsRedis.xinfo_groups	      
 ##ND99r   c                 &    U R                  SU5      $ )zI
Returns general information about the stream.
name: name of the stream.
r  rD  r  s     r(   xinfo_streamRedis.xinfo_stream	  r  r   c                 &    U R                  SU5      $ )z3
Returns the number of elements in a given stream.
XLENrD  r  s     r(   xlen
Redis.xlen	  s     ##FD11r   c                 &    U R                  SX5      $ )zy
Returns information about pending messages of a group.
name: name of the stream.
groupname: name of the consumer group.
r  rD  r  s      r(   xpendingRedis.xpending	  s     ##J@@r   c                 N   X/nUc  Uc  Ub\  Ub  Ub  Uc  [        S5      e[        U[        [        45      (       a  US:  a  [        S5      eUR	                  X4[        U5      45        Ub%  Ub  Ub  Uc  [        S5      eUR                  U5        U R                  " S/UQ7SS06$ )a  
Returns information about pending messages, in a range.
name: name of the stream.
groupname: name of the consumer group.
min: minimum stream ID.
max: maximum stream ID.
count: number of messages to return
consumername: name of a consumer to filter by (optional).
zOXPENDING must be provided with min, max and count parameters, or none of them. r   z&XPENDING count must be a integer >= -1zaif XPENDING is provided with consumername, it must be provided with min, max and count parametersr  r   T)r   r!   r+   r   r%   r  r   r>  )rD   r   r  r   r   rU  r  rF  s           r(   xpending_rangeRedis.xpending_range	  s     "?co1B{ckU] !J K Kec4[11URZ HIIMM3SZ01#{ckU] !4 5 5 MM,'##JKKdKKr   c                     X#/nUbW  [        U[        [        45      (       a  US:  a  [        S5      eUR	                  S5        UR	                  [        U5      5        U R                  " SU/UQ76 $ )a;  
Read stream values within an interval.
name: name of the stream.
start: first stream ID. defaults to '-',
       meaning the earliest available.
finish: last stream ID. defaults to '+',
        meaning the latest available.
count: if set, only return this many items, beginning with the
       earliest available.
r   z'XRANGE count must be a positive integerr~  XRANGEr!   r+   r   r   r   r  r>  )rD   r   r   r   rU  rF  s         r(   xrangeRedis.xrange	  sh     ec4[11UQY IJJMM(#MM#e*%##Hd<V<<r   c                 ~   / nUbW  [        U[        [        45      (       a  US:  a  [        S5      eUR	                  S5        UR	                  [        U5      5        UbW  [        U[        [        45      (       a  US:  a  [        S5      eUR	                  S5        UR	                  [        U5      5        [        U[        5      (       a  [        U5      S:X  a  [        S5      eUR	                  S5        [        [        U5      6 u  pVUR                  U5        UR                  U5        U R                  " S	/UQ76 $ )
a6  
Block and monitor multiple streams for new data.
streams: a dict of stream names to stream IDs, where
           IDs indicate the last ID already seen.
count: if set, only return this many items, beginning with the
       earliest available.
block: number of milliseconds to wait, if nothing already present.
r   z*XREAD block must be a non-negative integer   BLOCKr   z&XREAD count must be a positive integerr~  z&XREAD streams must be a non empty dict   STREAMSXREAD)r!   r+   r   r   r   r  r3   ru  r
   r   r%   r>  )rD   streamsrU  blockrF  r&   r   s          r(   xreadRedis.xread	  s    ec4[11UQY LMMMM(#MM#e*%ec4[11UQY HIIMM(#MM#e*%'4((CLA,=DEEj!Yw/0df##G5f55r   c                    SX/nUbW  [        U[        [        45      (       a  US:  a  [        S5      eUR	                  S5        UR	                  [        U5      5        UbW  [        U[        [        45      (       a  US:  a  [        S5      eUR	                  S5        UR	                  [        U5      5        U(       a  UR	                  S5        [        U[        5      (       a  [        U5      S:X  a  [        S	5      eUR	                  S
5        UR                  UR                  5       5        UR                  UR                  5       5        U R                  " S/UQ76 $ )a  
Read from a stream via a consumer group.
groupname: name of the consumer group.
consumername: name of the requesting consumer.
streams: a dict of stream names to stream IDs, where
       IDs indicate the last ID already seen.
count: if set, only return this many items, beginning with the
       earliest available.
block: number of milliseconds to wait, if nothing already present.
noack: do not add messages to the PEL
s   GROUPr   z+XREADGROUP count must be a positive integerr~  r   z/XREADGROUP block must be a non-negative integerr"  s   NOACKz+XREADGROUP streams must be a non empty dictr#  
XREADGROUP)r!   r+   r   r   r   r  r3   ru  r%   r&   r   r>  )rD   r  r  r%  rU  r&  noackrF  s           r(   
xreadgroupRedis.xreadgroup
  s    I4ec4[11UQY MNNMM(#MM#e*%ec4[11UQY !* + +MM(#MM#e*%MM(#'4((CLA,=IJJj!glln%gnn&'##L:6::r   c                     X#/nUbW  [        U[        [        45      (       a  US:  a  [        S5      eUR	                  S5        UR	                  [        U5      5        U R                  " SU/UQ76 $ )aJ  
Read stream values within an interval, in reverse order.
name: name of the stream
start: first stream ID. defaults to '+',
       meaning the latest available.
finish: last stream ID. defaults to '-',
        meaning the earliest available.
count: if set, only return this many items, beginning with the
       latest available.
r   z*XREVRANGE count must be a positive integerr~  	XREVRANGEr  )rD   r   r   r   rU  rF  s         r(   	xrevrangeRedis.xrevrange1
  sh     ec4[11UQY LMMMM(#MM#e*%##K???r   c                     S/nU(       a  UR                  S5        UR                  U5        U R                  " SU/UQ76 $ )z
Trims old messages from a stream.
name: name of the stream.
maxlen: truncate old stream messages beyond this size
approximate: actual stream length may be slightly more than maxlen
r  r  XTRIMr  )rD   r   r  r  rF  s        r(   xtrimRedis.xtrimE
  s>     MM$f##GT;F;;r   c                    U(       d  [        S5      eU(       a  U(       a  [        S5      eU(       a  [        U5      S:w  a  [        S5      e/ n0 nU(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        S	US
'   [        U5       H+  n	UR                  U	S   5        UR                  U	S   5        M-     U R                  " SU/UQ70 UD6$ )a  
Set any number of element-name, score pairs to the key ``name``. Pairs
are specified as a dict of element-names keys to score values.

``nx`` forces ZADD to only create new elements and not to update
scores for elements that already exist.

``xx`` forces ZADD to only update scores of elements that already
exist. New elements will not be added.

``ch`` modifies the return value to be the numbers of elements changed.
Changed elements include new elements that were added and elements
whose scores changed.

``incr`` modifies ZADD to behave like ZINCRBY. In this mode only a
single element/score pair can be specified and the score is the amount
the existing score will be incremented by. When using this mode the
return value of ZADD will be the new score of the element.

The return value of ZADD varies based on the mode specified. With no
options, ZADD returns the number of new elements added to the sorted
set.
z-ZADD requires at least one element/score pairz)ZADD allows either 'nx' or 'xx', not bothr   zFZADD option 'incr' only works when passing a single element/score pairs   NXs   XXs   CHs   INCRTr  r   r  )r   ru  r   r   r>  )
rD   r   r  r  r  chr  rF  r   r
  s
             r(   zadd
Redis.zaddS
  s    0 KLL"GHHCLA% 8 9 9MM% MM% MM% MM'""&GJg&DMM$q'"MM$q'" ' ##FDE6EWEEr   c                 &    U R                  SU5      $ )z8Return the number of elements in the sorted set ``name``ZCARDrD  r  s     r(   zcardRedis.zcard
  r  r   c                 (    U R                  SXU5      $ )zl
Returns the number of elements in the sorted set at key ``name`` with
a score between ``min`` and ``max``.
ZCOUNTrD  rD   r   r   r   s       r(   zcountRedis.zcount
  s    
 ##Hd==r   c                 (    U R                  SXU5      $ )zEIncrement the score of ``value`` in sorted set ``name`` by ``amount``ZINCRBYrD  )rD   r   r\  r   s       r(   zincrbyRedis.zincrby
  s    ##ItUCCr   c                 (    U R                  SXU5      $ )z
Intersect multiple sorted sets specified by ``keys`` into
a new sorted set, ``dest``. Scores in the destination will be
aggregated based on the ``aggregate``, or SUM if none is provided.
ZINTERSTORE_zaggregaterD   rO  r&   	aggregates       r(   zinterstoreRedis.zinterstore
       t9EEr   c                 (    U R                  SXU5      $ )zn
Return the number of items in the sorted set ``name`` between the
lexicographical range ``min`` and ``max``.
	ZLEXCOUNTrD  r@  s       r(   	zlexcountRedis.zlexcount
  s    
 ##KC@@r   c                 f    USL=(       a    U/=(       d    / nSS0nU R                   " SU/UQ70 UD6$ )za
Remove and return up to ``count`` members with the highest scores
from the sorted set ``name``.
Nr   TZPOPMAXrD  rD   r   rU  r'   r   s        r(   zpopmaxRedis.zpopmax
  E    
 T!.w4"$
 ##ItFdFgFFr   c                 f    USL=(       a    U/=(       d    / nSS0nU R                   " SU/UQ70 UD6$ )z`
Remove and return up to ``count`` members with the lowest scores
from the sorted set ``name``.
Nr   TZPOPMINrD  rV  s        r(   zpopminRedis.zpopmin
  rY  r   c                 l    Uc  Sn[        US5      nUR                  U5        U R                  " S/UQ76 $ )a  
ZPOPMAX a value off of the first non-empty sorted set
named in the ``keys`` list.

If none of the sorted sets in ``keys`` has a value to ZPOPMAX,
then block for ``timeout`` seconds, or until a member gets added
to one of the sorted sets.

If timeout is 0, then block indefinitely.
Nr   BZPOPMAXr$  r%  s      r(   bzpopmaxRedis.bzpopmax
  <     ?GD$'G##J666r   c                 l    Uc  Sn[        US5      nUR                  U5        U R                  " S/UQ76 $ )a  
ZPOPMIN a value off of the first non-empty sorted set
named in the ``keys`` list.

If none of the sorted sets in ``keys`` has a value to ZPOPMIN,
then block for ``timeout`` seconds, or until a member gets added
to one of the sorted sets.

If timeout is 0, then block indefinitely.
Nr   BZPOPMINr$  r%  s      r(   bzpopminRedis.bzpopmin
  rb  r   c                     U(       a  U R                  XX5U5      $ SXU/nU(       a  UR                  S5        UUS.nU R                  " U0 UD6$ )a  
Return a range of values from sorted set ``name`` between
``start`` and ``end`` sorted in ascending order.

``start`` and ``end`` can be negative, indicating the end of the range.

``desc`` a boolean indicating whether to sort the results descendingly

``withscores`` indicates to return the scores along with the values.
The return type is a list of (value, score) pairs

``score_cast_func`` a callable used to cast the score return value
ZRANGE
   WITHSCORESr   r   )	zrevranger   r>  )	rD   r   rB  rC  rw  r   r   rF  r   s	            r(   zrangeRedis.zrange
  s_     >>$s"13 3D-MM-($.
 ##V7w77r   c                     Ub  Ub  Ub  Uc  [        S5      eSXU/nUb  Ub  UR                  SXE/5        U R                  " U6 $ )z
Return the lexicographical range of values from sorted set ``name``
between ``min`` and ``max``.

If ``start`` and ``num`` are specified, then return a slice of the
range.
rq  ZRANGEBYLEXrr  r   r%   r>  )rD   r   r   r   rB  r-  rF  s          r(   zrangebylexRedis.zrangebylex
  s[     #+U]JKKC0MM8U01##V,,r   c                     Ub  Ub  Ub  Uc  [        S5      eSXU/nUb  Ub  UR                  SXE/5        U R                  " U6 $ )z
Return the reversed lexicographical range of values from sorted set
``name`` between ``max`` and ``min``.

If ``start`` and ``num`` are specified, then return a slice of the
range.
rq  ZREVRANGEBYLEXrr  rp  )rD   r   r   r   rB  r-  rF  s          r(   zrevrangebylexRedis.zrevrangebylex  s[     #+U]JKK"Ds3MM8U01##V,,r   c                     Ub  Ub  Ub  Uc  [        S5      eSXU/nUb  Ub  UR                  SXE/5        U(       a  UR                  S5        UUS.n	U R                  " U0 U	D6$ )af  
Return a range of values from the sorted set ``name`` with scores
between ``min`` and ``max``.

If ``start`` and ``num`` are specified, then return a slice
of the range.

``withscores`` indicates to return the scores along with the values.
The return type is a list of (value, score) pairs

`score_cast_func`` a callable used to cast the score return value
rq  ZRANGEBYSCORErr  ri  rj  r   r%   r   r>  )
rD   r   r   r   rB  r-  r   r   rF  r   s
             r(   zrangebyscoreRedis.zrangebyscore  s~     #+U]JKK!4c2MM8U01MM-($.
 ##V7w77r   c                 &    U R                  SX5      $ )zQ
Returns a 0-based value indicating the rank of ``value`` in sorted set
``name``
ZRANKrD  r  s      r(   zrankRedis.zrank/  s    
 ##GT99r   c                 *    U R                   " SU/UQ76 $ )z1Remove member ``values`` from sorted set ``name``ZREMrD  rF  s      r(   zrem
Redis.zrem6  r  r   c                 (    U R                  SXU5      $ )z
Remove all elements in the sorted set ``name`` between the
lexicographical range specified by ``min`` and ``max``.

Returns the number of elements removed.
ZREMRANGEBYLEXrD  r@  s       r(   zremrangebylexRedis.zremrangebylex:  s     ##$4dEEr   c                 (    U R                  SXU5      $ )z
Remove all elements in the sorted set ``name`` with ranks between
``min`` and ``max``. Values are 0-based, ordered from smallest score
to largest. Values can be negative indicating the highest scores.
Returns the number of elements removed
ZREMRANGEBYRANKrD  r@  s       r(   zremrangebyrankRedis.zremrangebyrankC  s     ##$5t#FFr   c                 (    U R                  SXU5      $ )z
Remove all elements in the sorted set ``name`` with scores
between ``min`` and ``max``. Returns the number of elements removed.
ZREMRANGEBYSCORErD  r@  s       r(   zremrangebyscoreRedis.zremrangebyscoreL  s    
 ##$63GGr   c                 j    SXU/nU(       a  UR                  S5        UUS.nU R                  " U0 UD6$ )aq  
Return a range of values from sorted set ``name`` between
``start`` and ``end`` sorted in descending order.

``start`` and ``end`` can be negative, indicating the end of the range.

``withscores`` indicates to return the scores along with the values
The return type is a list of (value, score) pairs

``score_cast_func`` a callable used to cast the score return value
	ZREVRANGEri  rj  r  )rD   r   rB  rC  r   r   rF  r   s           r(   rk  Redis.zrevrangeS  sD     tC0MM-($.
 ##V7w77r   c                     Ub  Ub  Ub  Uc  [        S5      eSXU/nUb  Ub  UR                  SXE/5        U(       a  UR                  S5        UUS.n	U R                  " U0 U	D6$ )a{  
Return a range of values from the sorted set ``name`` with scores
between ``min`` and ``max`` in descending order.

If ``start`` and ``num`` are specified, then return a slice
of the range.

``withscores`` indicates to return the scores along with the values.
The return type is a list of (value, score) pairs

``score_cast_func`` a callable used to cast the score return value
rq  ZREVRANGEBYSCORErr  ri  rj  ry  )
rD   r   r   r   rB  r-  r   r   rF  r   s
             r(   zrevrangebyscoreRedis.zrevrangebyscorei  s~     #+U]JKK$d5MM8U01MM-($.
 ##V7w77r   c                 &    U R                  SX5      $ )z\
Returns a 0-based value indicating the descending rank of
``value`` in sorted set ``name``
ZREVRANKrD  r  s      r(   zrevrankRedis.zrevrank  s    
 ##J<<r   c                 &    U R                  SX5      $ )z<Return the score of element ``value`` in sorted set ``name``ZSCORErD  r  s      r(   zscoreRedis.zscore  rN  r   c                 (    U R                  SXU5      $ )z
Union multiple sorted sets specified by ``keys`` into
a new sorted set, ``dest``. Scores in the destination will be
aggregated based on the ``aggregate``, or SUM if none is provided.
ZUNIONSTORErI  rK  s       r(   zunionstoreRedis.zunionstore  rO  r   c                 Z   X[        U5      /n[        U[        5      (       a  [        U5      [	        U5      pcOS nUR                  U5        U(       a"  UR                  S5        UR                  U5        U(       a"  UR                  S5        UR                  U5        U R                  " U6 $ )Ns   WEIGHTSs	   AGGREGATE)ru  r!   r3   r   r	   r%   r   r>  )rD   r   rO  r&   rL  rF  weightss          r(   rJ  Redis._zaggregate  s    T+dD!!$TNJt,<'GdMM*%MM'"MM,'MM)$##V,,r   c                 *    U R                   " SU/UQ76 $ )z9Adds the specified elements to the specified HyperLogLog.PFADDrD  rF  s      r(   pfaddRedis.pfadd  rI  r   c                 (    U R                   " S/UQ76 $ )zW
Return the approximated cardinality of
the set observed by the HyperLogLog at key(s).
PFCOUNTrD  )rD   sourcess     r(   pfcountRedis.pfcount  s    
 ##I888r   c                 *    U R                   " SU/UQ76 $ )z1Merge N different HyperLogLogs into a single one.PFMERGErD  )rD   rO  r  s      r(   pfmergeRedis.pfmerge  s    ##It>g>>r   c                 *    U R                   " SU/UQ76 $ )z"Delete ``keys`` from hash ``name``HDELrD  )rD   r   r&   s      r(   hdel
Redis.hdel  s    ##FD8488r   c                 &    U R                  SX5      $ )zCReturns a boolean indicating if ``key`` exists within hash ``name``HEXISTSrD  rD   r   r   s      r(   hexistsRedis.hexists  s    ##It99r   c                 &    U R                  SX5      $ )z4Return the value of ``key`` within the hash ``name``HGETrD  r  s      r(   hget
Redis.hget  s    ##FD66r   c                 &    U R                  SU5      $ )z3Return a Python dict of the hash's name/value pairsr  rD  r  s     r(   hgetallRedis.hgetall  r  r   c                 (    U R                  SXU5      $ )z=Increment the value of ``key`` in hash ``name`` by ``amount``HINCRBYrD  rD   r   r   r\  s       r(   hincrbyRedis.hincrby  s    ##It&AAr   c                 (    U R                  SXU5      $ )zH
Increment the value of ``key`` in hash ``name`` by floating ``amount``
HINCRBYFLOATrD  r  s       r(   hincrbyfloatRedis.hincrbyfloat  s     ##NDvFFr   c                 &    U R                  SU5      $ )z,Return the list of keys within hash ``name``HKEYSrD  r  s     r(   hkeysRedis.hkeys  r  r   c                 &    U R                  SU5      $ )z.Return the number of elements in hash ``name``HLENrD  r  s     r(   hlen
Redis.hlen  r  r   c                     Uc  U(       d  [        S5      e/ nUb  UR                  X#45        U(       a(  UR                  5        H  nUR                  U5        M     U R                  " SU/UQ76 $ )z
Set ``key`` to ``value`` within hash ``name``,
``mapping`` accepts a dict of key/value pairs that that will be
added to hash ``name``.
Returns the number of fields that were added.
z'hset' with no key value pairsHSET)r   r%   r  r>  )rD   r   r   r   r  r  r
  s          r(   hset
Redis.hset  sh     ;w<==?LL#&T" ( ##FD9599r   c                 (    U R                  SXU5      $ )z}
Set ``key`` to ``value`` within hash ``name`` if ``key`` does not
exist.  Returns 1 if HSETNX created a field, otherwise 0.
HSETNXrD  )rD   r   r   r   s       r(   hsetnxRedis.hsetnx  s    
 ##Hd??r   c                 ,   [         R                  " U R                  R                  < SU R                  R                  < S3[        SS9  U(       d  [        S5      e/ n[        U5       H  nUR                  U5        M     U R                  " SU/UQ76 $ )zg
Set key to value within hash ``name`` for each corresponding
key and value from the ``mapping`` dict.
z.hmset() is deprecated. Use z.hset() instead.r   )
stacklevelz"'hmset' with 'mapping' of length 0HMSET)	r  r  rN   r`   r  r   r   r%   r>  )rD   r   r  r  r
  s        r(   hmsetRedis.hmset  s~    
 	~~&&(?(?A		
 @AAg&DLL '##GT:E::r   c                 @    [        X#5      nU R                  " SU/UQ76 $ )z8Returns a list of values ordered identically to ``keys``HMGETr  )rD   r   r&   r'   s       r(   hmgetRedis.hmget  s$    D'##GT9D99r   c                 &    U R                  SU5      $ )z.Return the list of values within hash ``name``HVALSrD  r  s     r(   hvalsRedis.hvals
  r  r   c                 &    U R                  SX5      $ )zP
Return the number of bytes stored in the value of ``key``
within hash ``name``
HSTRLENrD  r  s      r(   hstrlenRedis.hstrlen  s    
 ##It99r   c                 &    U R                  SX5      $ )ze
Publish ``message`` on ``channel``.
Returns the number of subscribers the message was delivered to.
PUBLISHrD  )rD   channelmessages      r(   publishRedis.publish  s    
 ##Iw@@r   c                 &    U R                  SU5      $ )z=
Return a list of channels that have at least one subscriber
zPUBSUB CHANNELSrD  r  s     r(   pubsub_channelsRedis.pubsub_channels  s     ##$5w??r   c                 $    U R                  S5      $ )z1
Returns the number of subscriptions to patterns
zPUBSUB NUMPATrD  r  s    r(   pubsub_numpatRedis.pubsub_numpat"  s     ##O44r   c                 (    U R                   " S/UQ76 $ )z^
Return a list of (channel, number of subscribers) tuples
for each channel given in ``*args``
r  rD  r  s     r(   pubsub_numsubRedis.pubsub_numsub(  s    
 ##O;d;;r   c                 J    U R                   " SUR                  5       -  /UQ76 $ )Nz
CLUSTER %s)r>  rC   )rD   cluster_argr'   s      r(   clusterRedis.cluster/  s&    ##L;3D3D3F$FNNNr   c                 *    U R                   " SX/UQ76 $ )a   
Execute the Lua ``script``, specifying the ``numkeys`` the script
will touch and the key names and argument values in ``keys_and_args``.
Returns the result of the script.

In practice, use the object returned by ``register_script``. This
function exists purely for Redis API completion.
EVALrD  )rD   scriptnumkeyskeys_and_argss       r(   eval
Redis.eval2  s     ##FFLmLLr   c                 *    U R                   " SX/UQ76 $ )aU  
Use the ``sha`` to execute a Lua script already registered via EVAL
or SCRIPT LOAD. Specify the ``numkeys`` the script will touch and the
key names and argument values in ``keys_and_args``. Returns the result
of the script.

In practice, use the object returned by ``register_script``. This
function exists purely for Redis API completion.
EVALSHArD  )rD   shar  r  s       r(   evalshaRedis.evalsha=  s     ##IsLmLLr   c                 (    U R                   " S/UQ76 $ )z
Check if a script exists in the script cache by specifying the SHAs of
each script as ``args``. Returns a list of boolean values indicating if
if each already script exists in the cache.
r  rD  r  s     r(   script_existsRedis.script_existsI  s     ##O;d;;r   c                 $    U R                  S5      $ )z'Flush all scripts from the script cacher  rD  r  s    r(   script_flushRedis.script_flushQ  r}  r   c                 $    U R                  S5      $ )z'Kill the currently executing Lua scriptr  rD  r  s    r(   script_killRedis.script_killU  rP  r   c                 &    U R                  SU5      $ )z=Load a Lua ``script`` into the script cache. Returns the SHA.r  rD  rD   r  s     r(   script_loadRedis.script_loadY  s    ##M6::r   c                     [        X5      $ )z
Register a Lua ``script`` specifying the ``keys`` it will touch.
Returns a Script object that is callable and hides the complexity of
deal with scripts, keys, and shas. This is the preferred way to work
with Lua scripts.
)Scriptr  s     r(   register_scriptRedis.register_script]  s     d##r   c                 d    [        U5      S-  S:w  a  [        S5      eU R                  " SU/UQ76 $ )z
Add the specified geospatial items to the specified key identified
by the ``name`` argument. The Geospatial items are given as ordered
members of the ``values`` argument, each item or place is formed by
the triad longitude, latitude and name.
r   r   z4GEOADD requires places with lon, lat and name valuesGEOADD)ru  r   r>  rF  s      r(   geoaddRedis.geoaddg  s>     v;?a & ' '##Hd<V<<r   c                     XU/nU(       a  US;  a  [        S5      eU(       a  UR                  U5        U R                  " S/UQ76 $ )z
Return the distance between ``place1`` and ``place2`` members of the
``name`` key.
The units must be one of the following : m, km mi, ft. By default
meters are used.
mkmmiftzGEODIST invalid unitGEODISTrT  )rD   r   place1place2unitrF  s         r(   geodistRedis.geodists  sJ     'D 77233MM$##I777r   c                 *    U R                   " SU/UQ76 $ )zz
Return the geo hash string for each item of ``values`` members of
the specified key identified by the ``name`` argument.
r  rD  rF  s      r(   geohashRedis.geohash  s    
 ##It=f==r   c                 *    U R                   " SU/UQ76 $ )z
Return the positions of each item of ``values`` as members of
the specified key identified by the ``name`` argument. Each position
is represented by the pairs lon and lat.
r  rD  rF  s      r(   geoposRedis.geopos  s     ##Hd<V<<r   c                 .    U R                  SXX4XVXxXUUS9$ )a9  
Return the members of the specified key identified by the
``name`` argument which are within the borders of the area specified
with the ``latitude`` and ``longitude`` location and the maximum
distance from the center specified by the ``radius`` value.

The units must be one of the following : m, km mi, ft. By default

``withdist`` indicates to return the distances of each place.

``withcoord`` indicates to return the latitude and longitude of
each place.

``withhash`` indicates to return the geohash string of each place.

``count`` indicates to return the number of elements up to N.

``sort`` indicates to return the places in a sorted way, ASC for
nearest to fairest and DESC for fairest to nearest.

``store`` indicates to save the places names in a sorted set named
with a specific key, each element of the destination sorted set is
populated with the score got from the original geo sorted set.

``store_dist`` indicates to save the places names in a sorted set
named with a specific key, instead of ``store`` the sorted set
destination score is set with the distance.
r  r*  rB  rC  rD  rU  rz  r@  rA  _georadiusgeneric)rD   r   	longitudelatituderadiusr*  rB  rC  rD  rU  rz  r@  rA  s                r(   	georadiusRedis.georadius  s1    > %%k&*x+/09,1E1; & = 	=r   c                 ,    U R                  SXX4XVXxXUS9$ )a  
This command is exactly like ``georadius`` with the sole difference
that instead of taking, as the center of the area to query, a longitude
and latitude value, it takes the name of a member already existing
inside the geospatial index represented by the sorted set.
r  r4  r5  )rD   r   memberr9  r*  rB  rC  rD  rU  rz  r@  rA  s               r(   georadiusbymemberRedis.georadiusbymember  s0     %%&9&*F/7/7+/1; & = 	=r   c                    [        U5      nUS   (       a  US   S;  a  [        S5      eUS   (       a  UR                  US   5        OUR                  S5        S H!  u  pVX5   (       d  M  UR                  U5        M#     US   (       a  UR                  SUS   /5        US   (       aA  US   S	:X  a  UR                  S
5        O&US   S:X  a  UR                  S5        O[        S5      eUS   (       a  US   (       a  [        S5      eUS   (       a  UR                  SUS   /5        US   (       a  UR                  SUS   /5        U R                  " U/UQ70 UD6$ )Nr*  r"  zGEORADIUS invalid unitr#  ))rB  s   WITHDIST)rC  s	   WITHCOORD)rD  s   WITHHASHrU  r~  rz  ASCs   ASCDESCrs  zGEORADIUS invalid sortr@  rA  z3GEORADIUS store and store_dist cant be set togetherrt  s	   STOREDIST)r#   r   r   r%   r>  )rD   r   r'   r   rF  arg_name	byte_reprs          r(   r6  Redis._georadiusgeneric  sK   d&>fVn4KK455F^MM&.)MM#$+H i($+ '?MM8VG_56&>f~&f%6)g& 899'?vl3 ( ) ) '?MM8VG_56,MM<)=>?##G?f???r   )r  r  r  r   )	localhosti  r   NNNNNNNzutf-8strictNNFFFNNrequiredNFNFr   NN)TN)Ng?NNT)
FFNNNNNFFF)NNNNF)*)FFNFFr   )r   )g      ?)NNFFF)r   )r   )NNNNFFNF)r   NNN)NNN)r   NN)rJ  NT)NNNFF)$F)r+  +N)NNF)rM  r+  NT)FFFF)NFFFNNNN("  r`   ra   rb   rc   rd   r>   r8   r  r+   r   r   r   r  r   rz   r   r   r   rc  r[  r  r(  r>  r  rw   rV  r  r   r1   r   r|   rX  r  r   r   r   r   r#  r   r   r   r   r  r  r  classmethodr  rH   r  r  r  r  r  r  r  r  r"  r,  r0  r'  r>  r9  rG  rK  rN  rR  rU  rY  r]  rp  rs  rw  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  r5  r  r   r  r
  r  r  r  r  r  r  r%  r)  r.  r1  r4  r  r;  r   rE  rJ  rP  rV  r]  rZ  rf  rQ   rl  rp  rL   ry  r  rW   rT   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  rO  r  r  r   r&  r+  r/  r4  r:  r>  rB  rG  rL  rQ  rV  rZ  r^  rb  rf  rj  rn  rz  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  r  r  r  r  r'  r,  r0  r4  r8  r<  rA  rE  rM  rR  rW  r\  r`  re  rl  rq  ru  rz  r~  r  r  r  r  rk  r  r  r  r  rJ  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.  r1  r:  r>  r6  re   r_   r   r(   re  re    s
    $:	

 	>
 	
 	&	
 	N	

 	F$674mDH	

 	M+KL*+	
 	M	
 	/M	O,k:.0AB.<1>BU	
8U	
3U	
 9U	
 ,	U	

 9U	
 U	
 U	
 7U	
 :U	
 )U	
 :U	
 U	
 ,U	
 ,U	
 gU	
  B!U	
" G#U	
$ %U	
& ,-='U	
( &'7)U	
* +U	
, -U	
. g/U	
0 .1U	
2 /3U	
4 G5U	
6 07U	
8  9U	
: W;U	
< !'=U	
> '?U	
@ wAU	
B 1CU	
D *EU	
F GU	
H 'IU	
J .KU	
L @MU	
N  JOU	
T 0UU	
V  !8WU	
X =YU	
Z [[U	
\ J]U	
^ -_U	
` GaU	
b .cU	
d KeU	
f lgU	
h 4iU	
j 0kU	
l 2mU	
n JoU	
p :qU	
r GsU	
t 7uU	
v 9wU	
x /0IyU	
z 4{U	
|  6}U	
~ U	
@ wAU	
B !"ECU	
D GEU	
F BGU	
H 7IU	
J ,KU	
L 3MU	
N %4"$"%"#2/.& iU	
[CJ "4 "4H /359(,AE8<3;&*:?;?8<$)@EEID/LL4, DH+/15f6-=/#$
	8=3=000 ;@FJFK$)Q<f124.< :D3 61<
+B10;?86.93
7
6=90 15!6FP4@4,,I
2
E8P=HIE;*;
N35,C:9OE7()<326 L:<1<A;)<A5>	4
665;	=D218:8 ;@&4PC@:E4@412OG6
4"4"E;M22<;@
@@?2;<; =A9>A@H50,6  6   "#$d#A( &*#(*;34
?5
@>6>9
	@;5
@C;4 =B:Ax8
-
2GIH::2A %)L6=(68 BF%* ;D@(<-F^3>DFA	G	G7"7" -2e$86- -  37D!&88:;FGH 6;"'8, 6:t$)588=;F- <9?
9:75BG32:$@;$:
3:A@5<O	M
M<43;$
=8>= AEIM48$=L <@DIHL= %@ %@r   re  c                   ~    \ rS rSrSr\R                  " S5      r\R                  " S5      rS r	S r
S rS rS	 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"(.*?)(?<!\\)"c                 P    Xl         U R                   R                  S5      U l        g )NMONITOR)r  r  r  )rD   r  s     r(   rH   Monitor.__init__  s     ...==iHr   c                     U R                   R                  S5        U R                   R                  5       n[        U5      (       d  [	        SU-  5      eU $ )NrR  zMONITOR failed: %s)r  r8  rA  r  r   rD   r0   s     r(   r"  Monitor.__enter__  sG    $$Y/??002x  1H<==r   c                     U R                   R                  5         U R                  R                  U R                   5        g r   )r  r:  r  r3  r  s     r(   r,  Monitor.__exit__  s*    ""$$$T__5r   c                    U R                   R                  5       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      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.$ )z)Parse the response from a monitor commandTrb  r  r   z\""z\\\luar  unix   Nrk   tcp)r  r  client_addressclient_portclient_typer   )r  rA  r!   r"   rm  rg  r5   
monitor_rer  r   r!  
command_refindallr  r   r   r   r+   )rD   r0   command_timecommand_datar#  db_idclient_infor   r`  ra  rb  s              r(   next_commandMonitor.next_command
  s/   ??002h&&..55hd5KH%-^^C%;"OO!!,/&'hhj#G((4??227;<//%-55fdC%"NKK##F++#N%ab/K K +6*<*<S!*D'NK,'e*,&&
 	
r   c              #   4   #     U R                  5       v   M  7f)z)Listen for commands coming to the server.)rj  r  s    r(   listenMonitor.listen*  s     ##%% s   )r  r  N)r`   ra   rb   rc   rd   recompilerc  rd  rH   r"  r,  rj  rm  re   r_   r   r(   r  r    sB    
 23J-.JI6
@&r   r  c                       \ rS rSrSrSrSrSr  SS jrS r	S	 r
S
 rS rS rS r\S 5       rS rS rSS jrS rS rS rS rS rS rS rS S jrS!S jrS"S jrS#S jrSrg)$r  i0  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-checkNc                 J   Xl         X l        X0l        S U l        U R                   R	                  5       U l        U R
                  R                  (       a  SU R                  /U l        O,SU R
                  R                  U R                  5      /U l        U R                  5         g )Nr6  s   pong)r  r  ignore_subscribe_messagesr  rd  rm  r  HEALTH_CHECK_MESSAGEhealth_check_responserf  rj  )rD   r  r  rv  s       r(   rH   PubSub.__init__<  s    .$)B& ++779<<((*0$2K2K)LD& ##D$=$=>*D& 	

r   c                     U $ r   r_   r  s    r(   r"  PubSub.__enter__N  r$  r   c                 $    U R                  5         g r   rj  r(  s       r(   r,  PubSub.__exit__Q  r.  r   c                 F     U R                  5         g ! [         a     g f = fr   rj  r   r  s    r(   r0  PubSub.__del__T  s$    	 JJL 		    
  c                 >   U R                   (       a`  U R                   R                  5         U R                   R                  5         U R                  R	                  U R                   5        S U l         0 U l        [        5       U l        0 U l        [        5       U l	        g r   )
r  r:  clear_connect_callbacksr  r3  channelsr   pending_unsubscribe_channelspatternspending_unsubscribe_patternsr  s    r(   rj  PubSub.reset]  sj    ??OO&&(OO335  ((9"DO,/E),/E)r   c                 $    U R                  5         g r   r}  r  s    r(   r'  PubSub.closeh  r.  r   c                    U R                   R                  5         U R                  R                  5         U R                  (       aN  0 n[	        U R                  5       H!  u  p4XBU R
                  R                  USS9'   M#     U R                  " S0 UD6  U R                  (       aO  0 n[	        U R                  5       H!  u  p4XEU R
                  R                  USS9'   M#     U R                  " S0 UD6  gg)zBRe-subscribe to any channels and patterns previously subscribed toTrb  Nr_   )
r  clearr  r  r   rm  rg  	subscriber  
psubscribe)rD   r  r  rF   rG   r  s         r(   
on_connectPubSub.on_connectk  s    
 	))//1))//1==H!$--0?@,,Qd,;< 1NN&X&==H!$--0?@,,Qd,;< 1OO'h'	 r   c                 R    [        U R                  =(       d    U R                  5      $ )z@Indicates if there are subscriptions to any channels or patterns)r  r  r  r  s    r(   
subscribedPubSub.subscribed}  s     DMM2T]]33r   c                 <   U R                   cP  U R                  R                  SU R                  5      U l         U R                   R	                  U R
                  5        U R                   nSU R                  (       + 0nU R                  " X"R                  /UQ70 UD6  g)z#Execute a publish/subscribe commandNr  check_health)	r  r  r  r  register_connect_callbackr  r  _executer8  )rD   r'   r  r   s       r(   r>  PubSub.execute_command  s~     ??""22AADO OO55dooF__
 doo"56j"9"9KDKFKr   c                      U" U0 UD6$ ! [         [        4 aY  nUR                  5         UR                  (       a  [	        U[        5      (       d  e UR                  5         U" U0 UD6s S nA$ S nAff = fr   )r   r   r:  r  r!   connect)rD   r  r   r'   r   r=  s         r(   r  PubSub._execute  sq    	,D+F++. 	,!!#//q,//   D+F++	,s   
 A3AA.(A3.A3c                 
   U R                   nUc  [        S5      eU R                  5         U(       d  UR                  US9(       d  gU R	                  X3R
                  5      nUR                  (       a  X@R                  :X  a  gU$ )z3Parse the response from a publish/subscribe commandNNpubsub connection not set: did you forget to call subscribe() or psubscribe()?)r  )r  RuntimeErrorr  can_readr  rA  r  rx  )rD   r&  r  r5  r0   s        r(   r9  PubSub.parse_response  sw    <FG G 	T]]7];=='9'9:%%666r   c                     U R                   nUc  [        S5      eUR                  (       a@  [        R                  " 5       UR                  :  a  UR                  SU R                  SS9  g g g )Nr  r  F)r  )r  r  r  r  next_health_checkr8  rw  r4  s     r(   r  PubSub.check_health  sl    <FG G %%$))+8N8N*Nfd&?&?+0  2 +O%r   c           	          U R                   R                  nU R                   R                  n[        U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.
)rm  rf  rg  r   )rD   rE   rf  rg  rF   rG   s         r(   _normalize_keysPubSub._normalize_keys  sN     $$$$1:4Avay!1$AAAs   Ac                 J   U(       a  [        US   USS 5      n[        R                  U5      nUR                  U5        U R                  " S/[        U5      Q76 nU R                  U5      nU R                  R                  U5        U R                  R                  U5        U$ )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)   r3   r4   r:   r>  r   r  r  r  difference_update)rD   r'   r   new_patternsret_vals        r(   r  PubSub.psubscribe  s     Qab2D}}T*F#&&|Mh|6LM ++L9\*));;LIr   c                     U(       a7  [        US   USS 5      nU R                  [        R                  U5      5      nO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  r3   r4   r  r  r:   r>  )rD   r'   r  s      r(   rt  PubSub.punsubscribe  si    
 Qab2D++DMM$,?@H}}H))00:##N:T::r   c                 J   U(       a  [        US   USS 5      n[        R                  U5      nUR                  U5        U R                  " S/[        U5      Q76 nU R                  U5      nU R                  R                  U5        U R                  R                  U5        U$ )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   N	SUBSCRIBE)
r)   r3   r4   r:   r>  r   r  r  r  r  )rD   r'   r   new_channelsr  s        r(   r  PubSub.subscribe  s     Qab2D}}T*F#&&{LXl5KL ++L9\*));;LIr   c                     U(       a7  [        US   USS 5      nU R                  [        R                  U5      5      nO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  r3   r4   r  r  r:   r>  )rD   r'   r  s      r(   rs  PubSub.unsubscribe  si    
 Qab2D++DMM$,?@H}}H))00:##M9D99r   c              #      #    U R                   (       a9  U R                  U R                  SS95      nUb  Uv   U R                   (       a  M8  gg7f)zBListen for messages on channels this client has been subscribed toT)r&  N)r  handle_messager9  rU  s     r(   rm  PubSub.listen  s@     oo**4+>+>T+>+JKH# ooos   AAAc                 T    U R                  SUS9nU(       a  U R                  X15      $ g)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.
F)r&  r  N)r9  r  )rD   rv  r  r0   s       r(   get_messagePubSub.get_message  s0     &&UG&D&&xKKr   c                 4    Uc  SOUnU R                  SU5      $ )z
Ping the Redis server
r  r  rD  )rD   r  s     r(   r5  PubSub.ping&  s"      "W##FG44r   c                    [        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                  ;   aX  US:X  a   U R                  R                  US
   S5      nOU R                  R                  US   S5      nU(       a	  U" U5        g U$ US:w  a  U(       d  U R                  (       a  gU$ )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.
r   rr  r   r   r   )rO  r  r  rE   r6  Nrt  r  r  )r   UNSUBSCRIBE_MESSAGE_TYPESr  remover  r  r  r  PUBLISH_MESSAGE_TYPESrW   rv  )rD   r0   rv  message_typer  r  r  handlers           r(   r  PubSub.handle_message-  s    !!-:%$#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    V# )D,J,Jr   c                     [        U R                  5       H  u  p4Ub  M
  [        SU-  5      e   [        U R                  5       H  u  pTUb  M
  [        SU-  5      e   [	        XUS9nUR                  5         U$ )Nz'Channel: '%s' has no handler registeredz'Pattern: '%s' has no handler registered)daemon)r   r  r   r  PubSubWorkerThreadrB  )rD   
sleep_timer  r  r  r  threads          r(   run_in_threadPubSub.run_in_threadh  s     )$-- 8G!"K")#* + + !9 !*$-- 8G!"K")#* + + !9
 $DVDr   )
r  r  r  rm  rx  rv  r  r  r  r  NF)Tr   )Fr   r   rI  )r   F) r`   ra   rb   rc   rd   r  r  rw  rH   r"  r,  r0  rj  r'  r  propertyr  r>  r  r9  r  r  r  rt  r  rs  rm  r  r5  r  r  re   r_   r   r(   r  r  0  s     4 ?237+0$	2($ 4 4L&, (	2B*;*:59vr   r  c                   8   ^  \ rS rSrSU 4S jjrS rS rSrU =r$ )r  iw  c                    > [         [        U ]  5         X0l        Xl        X l        [        R                  " 5       U l        g r   )	rK   r  rH   r  r  r  	threadingEvent_running)rD   r  r  r  rN   s       r(   rH   PubSubWorkerThread.__init__x  s.     $02$!)r   c                 h   U R                   R                  5       (       a  g U R                   R                  5         U R                  nU R                  nU R                   R                  5       (       a1  UR                  SUS9  U R                   R                  5       (       a  M1  UR                  5         g )NT)rv  r  )r  is_setr   r  r  r  r'  )rD   r  r  s      r(   runPubSubWorkerThread.run  s    ==!!__
mm""$$'1  3 mm""$$ 	r   c                 8    U R                   R                  5         g r   )r  r  r  s    r(   stopPubSubWorkerThread.stop  s     	r   )r  r  r  r  rI  )	r`   ra   rb   rc   rH   r  r  re   rf   rg   s   @r(   r  r  w  s    *	 r   r  c                       \ rS rSrSr1 SkrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rSS jrS rS rSrg)r  i  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                 p    Xl         S U l        X l        X0l        X@l        SU l        U R                  5         g r  )r  r  r  r  r  watchingrj  )rD   r  r  r  r  s        r(   rH   Pipeline.__init__  s0    ."4&$

r   c                     U $ r   r_   r  s    r(   r"  Pipeline.__enter__  r$  r   c                 $    U R                  5         g r   r}  r(  s       r(   r,  Pipeline.__exit__  r.  r   c                 F     U R                  5         g ! [         a     g f = fr   r  r  s    r(   r0  Pipeline.__del__  s"    	JJL 		r  c                 ,    [        U R                  5      $ r   )ru  command_stackr  s    r(   __len__Pipeline.__len__  s    4%%&&r   c                     g)z@Pipeline instances should  always evaluate to True on Python 2.7Tr_   r  s    r(   __nonzero__Pipeline.__nonzero__      r   c                     g)z?Pipeline instances should  always evaluate to True on Python 3+Tr_   r  s    r(   __bool__Pipeline.__bool__  r  r   c                    / U l         [        5       U l        U R                  (       aG  U R                  (       a6   U R                  R                  S5        U R                  R                  5         SU l        SU l	        U R                  (       a-  U R                  R                  U R                  5        S U l        g g ! [         a    U R                  R                  5          Nsf = f)Nr  F)r  r   scriptsr  r  r8  rA  r   r:  explicit_transactionr  r3  r  s    r(   rj  Pipeline.reset  s    u ==T__- ,,Y7--/
 $)! ??  ((9"DO  # -**,-s   5B< <$C#"C#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  r   r  r  s    r(   multiPipeline.multi  s<    
 $$ABB + , ,$(!r   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)rD   r'   r   s      r(   r>  Pipeline.execute_command  sI    MMT!W/--114B6BB,,d=f==r   c                    US   nU R                   nU(       d,  U R                  R                  UU R                  5      nX@l          UR                  " U6   U R
                  " XC40 UD6$ ! [        [        4 a  nUR                  5         U R                  (       a  U R                  5         [        S5      eUR                  (       a  [        U[        5      (       d  U R                  5         e  UR                  " U6   U R
                  " XC40 UD6s SnA$ ! [        [        4 a    U R                  5         e f = fSnAff = f)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.
r   =A ConnectionError occurred on while watching one or more keysN)r  r  r  r  r8  r9  r   r   r:  r  rj  r   r  r!   )rD   r'   r   r<  r5  r=  s         r(   r  "Pipeline.immediate_execute_command  s    Aw''66|7;HD"O	t$&&tEWEE. 	OO }}

  "= > > ))jL.I.I

!!4(**4III#\2 

)	s1   !A( (D=8A3D8,!DD="D55D88D=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  r   )rD   r'   r   s      r(   r  !Pipeline.pipeline_execute_command  s     	!!4/2r   c                    [        S0 4/US0 4/5      nUR                  U VVs/ s H  u  pV[        U;  d  M  UPM     snn5      nUR                  U5        / n U R	                  US5        [        U5       HC  u  p[        US   ;   a  UR                  XS   [           45        M0   U R	                  US5        ME      U R	                  US5      nSU l
        Uc  [        S5      eU H  u  pUR                  X5        M     [        U5      [        U5      :w  a%  U R                  R                  5         [        S5      eU(       a  U R!                  X,5        / n[#        X5       HZ  u  p[%        U[&        5      (       d/  Uu  pVUS   nUU R(                  ;   a  U R(                  U   " U40 UD6nUR                  U5        M\     U$ s  snnf ! [
         a  n	UR                  SU	45         S n	A	GNS n	A	ff = f! [
         a6  n	U R                  XS-   US   5        UR                  X45         S n	A	GM  S n	A	ff = f! [         a    U(       a  US   S   ee f = f)	N)MULTI)r  r  r   r   FzWatched variable changed.z6Wrong number of response items from pipeline execution)r   pack_commandsr   send_packed_commandr9  r   r   re  annotate_exceptionr   r  r   insertru  r  r:  raise_first_errorr
   r!   r   r  )rD   r  r^  raise_on_errorcmdsr'   r   all_cmdsr  r=  r   r   r0   rE   r   ro  r<  s                    r(   _execute_transactionPipeline._execute_transaction*  sU   {B'((j"5E4FG++t -Otmd0>g0M .2t -O P&&x0	"
C0
 $H-JA+q!*^"<=>*''
C8 .	**:s;H 899 DAOOA!  x=CM)OO&&( !5 6 6 ""86 8.FAa++ ##Aw4#:#:://=aK7KAKKN / {-O  	"MM1a&!!	" % *++A1ugajAMM1&))*  	Qil"	sF   G
G
G
 (G5?H8 

G2G--G25
H5?*H00H58Ic                 h   UR                  U VVs/ s H  u  pEUPM	     snn5      nUR                  U5        / nU H+  u  pH UR                  U R                  " XS   40 UD65        M-     U(       a  U R                  X'5        U$ s  snnf ! [         a  n	UR                  U	5         S n	A	Mp  S n	A	ff = f)Nr   )r  r	  r   r9  r   r  )
rD   r  r^  r  r'   r  r  r0   r   r=  s
             r(   _execute_pipelinePipeline._execute_pipelinek  s    ++,JgdT,JK&&x0%MD#''
GGwGI & ""86 -K ! #""#s   B
%B
B1B,,B1c                     [        U5       H6  u  p4[        U[        5      (       d  M  U R                  XCS-   X   S   5        Ue   g )Nr   r   )re  r!   r   r
  )rD   r^  r0   r   r   s        r(   r  Pipeline.raise_first_error|  s?    h'DA!]++''q5(+a.A (r   c                     SR                  [        [        U5      5      nSX$[        UR                  S   5      4-  nU4UR                  SS  -   Ul        g )Nr  z.Command # %d (%s) of pipeline caused error: %sr   r   )r!  r   r   r'   )rD   	exceptionr  r   ro  msgs         r(   r
  Pipeline.annotate_exception  sS    hhtL'23>innQ&78B: :).."44	r   c                     [         R                  " XU40 UD6nX R                  ;   a	  SU l        U$ US:X  a  SU l        U$ )NFr  T)re  r9  UNWATCH_COMMANDSr  )rD   r  r<  r   r   s        r(   r9  Pipeline.parse_response  sO    %%l7.57000!DM  W$ DMr   c                 $   [        U R                  5      nU R                  nU Vs/ s H  o3R                  PM     nnU" S/UQ76 n[	        U5      (       d6  [        X5       H&  u  p6U(       a  M  U" SUR                  5      Ul        M(     g g s  snf )Nr  r  )r#   r  r  r	  allr
   r  )rD   r  	immediatesshasrp  exists          r(   load_scriptsPipeline.load_scripts  s}    t||$22	&'w!w' ?2T26{{ 1u%mQXX>AE 2 	 (s   Bc                    U R                   nU(       d  U R                  (       d  / $ U R                  (       a  U R                  5         U R                  (       d  U R
                  (       a  U R                  nOU R                  nU R                  nU(       d,  U R                  R                  SU R                  5      nX@l         U" XBU5      U R                  5         $ ! [        [        4 av  nUR                  5         U R                  (       a  [!        S5      eUR"                  (       a  [%        U[        5      (       d  e U" XBU5      s SnAU R                  5         $ SnAff = f! U R                  5         f = f)z0Execute all the commands in the current pipeliner  r  N)r  r  r  r$  r  r  r  r  r  r  r  r  rj  r   r   r:  r   r  r!   )rD   r  stackr  r5  r=  s         r(   r  Pipeline.execute  s   ""T]]I<<t88//G,,G''66w7;HD #O	47  JJL  . 	8OO }}  "= > > ))jL.I.I477JJL	8 JJLs1   C E",AEE"E% E""E% %E7c                 `    U R                   (       a  [        S5      eU R                  " S/UQ76 $ )z$Watches the values at keys ``names``z"Cannot issue a WATCH after a MULTIr  )r  r   r>  rd  s     r(   r  Pipeline.watch  s-    $$ABB##G4e44r   c                 \    U R                   =(       a    U R                  S5      =(       d    S$ )z'Unwatches all previously specified keysr  T)r  r>  r  s    r(   r  Pipeline.unwatch  s!    }}@!5!5i!@HDHr   )	r  r  r  r  r  r  r  r  r  NrN  )r`   ra   rb   rc   rd   r  rH   r"  r,  r0  r  r  r  rj  r  r>  r  r  r  r  r  r
  r9  r$  r  r  r  re   r_   r   r(   r  r    s|    $ 6	'#.
)>(T?B"5?%N5Ir   r  c                   .    \ rS rSrSrS r/ / S4S jrSrg)r  i  z?An executable Lua script object returned by ``register_script``c                     Xl         X l        [        U[        5      (       a+  UR                  R                  5       nUR                  U5      n[        R                  " U5      R                  5       U l
        g r   )registered_clientr  r!   r   r  rd  rf  hashlibsha1	hexdigestr	  )rD   r/  r  rm  s       r(   rH   Script.__init__  sY    !2 fj)) (77CCEG^^F+F<<'113r   Nc                    Uc  U R                   n[        U5      [        U5      -   n[        U[        5      (       a  UR                  R                  U 5         UR                  " U R                  [        U5      /UQ76 $ ! [         aJ    UR                  U R                  5      U l        UR                  " U R                  [        U5      /UQ76 s $ f = f)z1Execute the script, passing any required ``args``)r/  rk  r!   r  r  addr
  r	  ru  r   r  r  )rD   r&   r'   r  s       r(   __call__Script.__call__  s    >++FT{U4[(fh''NNt$	>>>$((CI=== 	> ))$++6DH>>$((CI===	>s   &A? ?ACC)r/  r  r	  )r`   ra   rb   rc   rd   rH   r6  re   r_   r   r(   r  r    s    E
4 R >r   r  c                   Z    \ rS rSrSrSS jrS rS rSS jrS r	S	 r
\S
 5       rS rSrg)rI  i  z(
Command builder for BITFIELD commands.
Nc                 H    Xl         X l        X0l        U R                  5         g r   )r  r   _default_overflowrj  )rD   r  r   rH  s       r(   rH   BitFieldOperation.__init__  s    !1

r   c                 |    / U l         SU l        U R                  U R                  =(       d    U R                  5        g)z<
Reset the state of the instance to when it was constructed
WRAPN)
operations_last_overflowoverflowr:  r  s    r(   rj  BitFieldOperation.reset  s0     $d,,C0C0CDr   c                     UR                  5       nXR                  :w  a#  Xl        U R                  R                  SU45        U $ )z
Update the overflow algorithm of successive INCRBY operations
:param overflow: Overflow algorithm, one of WRAP, SAT, FAIL. See the
    Redis docs for descriptions of these algorithmsself.
:returns: a :py:class:`BitFieldOperation` instance.
OVERFLOW)rC   r?  r>  r   )rD   r@  s     r(   r@  BitFieldOperation.overflow  s>     >>#***"*OO""J#9:r   c                 j    Ub  U R                  U5        U R                  R                  SXU45        U $ )aX  
Increment a bitfield by a given amount.
:param fmt: format-string for the bitfield being updated, e.g. 'u8'
    for an unsigned 8-bit integer.
:param offset: offset (in number of bits). If prefixed with a
    '#', this is an offset multiplier, e.g. given the arguments
    fmt='u8', offset='#2', the offset will be 16.
:param int increment: value to increment the bitfield by.
:param str overflow: overflow algorithm. Defaults to WRAP, but other
    acceptable values are SAT and FAIL. See the Redis docs for
    descriptions of these algorithms.
:returns: a :py:class:`BitFieldOperation` instance.
r  )r@  r>  r   )rD   fmtr  	incrementr@  s        r(   r  BitFieldOperation.incrby  s4     MM(##yABr   c                 @    U R                   R                  SX45        U $ )al  
Get the value of a given bitfield.
:param fmt: format-string for the bitfield being read, e.g. 'u8' for
    an unsigned 8-bit integer.
:param offset: offset (in number of bits). If prefixed with a
    '#', this is an offset multiplier, e.g. given the arguments
    fmt='u8', offset='#2', the offset will be 16.
:returns: a :py:class:`BitFieldOperation` instance.
r  r>  r   )rD   rF  r  s      r(   rW   BitFieldOperation.get%  s      	s34r   c                 B    U R                   R                  SXU45        U $ )a  
Set the value of a given bitfield.
:param fmt: format-string for the bitfield being read, e.g. 'u8' for
    an unsigned 8-bit integer.
:param offset: offset (in number of bits). If prefixed with a
    '#', this is an offset multiplier, e.g. given the arguments
    fmt='u8', offset='#2', the offset will be 16.
:param int value: value to set at the given position.
:returns: a :py:class:`BitFieldOperation` instance.
r  rJ  )rD   rF  r  r   s       r(   r   BitFieldOperation.set2  s"     	sE:;r   c                 j    SU R                   /nU R                   H  nUR                  U5        M     U$ )NBITFIELD)r   r>  r%   )rD   ro  opss      r(   r   BitFieldOperation.command@  s.    488$??CJJsO #
r   c                 l    U R                   nU R                  5         U R                  R                  " U6 $ )z
Execute the operation(s) in a single BITFIELD command. The return value
is a list of values corresponding to each operation. If the client
used to create this instance was a pipeline, the list of values
will be present within the pipeline's execute.
)r   rj  r  r>  )rD   r   s     r(   r  BitFieldOperation.executeG  s+     ,,

{{**G44r   )r:  r?  r  r   r>  r   )r`   ra   rb   rc   rd   rH   rj  r@  r  rW   r   r  r   r  re   r_   r   r(   rI  rI    s?    E(  	5r   rI  rK  )a
__future__r   	itertoolsr   r-   r  r  r  r}  ro  r0  redis._compatr   r   r   r   r	   r
   r   r   r   redis.connectionr   r   r   
redis.lockr   redis.exceptionsr   r   r   r   r   r   r   r   r   	SYM_EMPTYr   r)   r1   r8   r>   r3   r@   rw   r|   r   r   r+   r   r   r   r   r   r   r   r   r   r   r   rz   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r#  r(  r9  r>  rV  rX  r[  rc  r  re  StrictRedisr  r  Threadr  r  r  rI  r_   r   r(   <module>r]     s   '       	 L L L- - 
 
 
 	!"576$ 66$#L
sC s 	
 C # # s c S 3 3 # 3   c!" C#$ / 6	;N@C"&	5;	5C'?	0
'6

6
CK
$>>5'0d+@F d+@NW <&f <&~DV DN
)) 4|Iu |I~	>V >D^5 ^5r   