
O'^c           @  s  d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z	 d  d l
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z m Z m Z m Z d  d l m Z m Z d  d l m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& m' Z' m( Z( e d  Z) d	   Z* d
   Z+ d   Z, d   Z- d   Z. d   Z/ d   Z0 i e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d 6e1 d  6e1 d! 6e1 d" 6e1 d# 6e1 d$ 6e1 d% 6e1 d& 6Z2 d'   Z3 d(   Z4 d)   Z5 d*   Z6 d+   Z7 d,   Z8 d-   Z9 d.   Z: d/   Z; d0   Z< d1   Z= d2   Z> d3   Z? d4   Z@ d5   ZA d6   ZB d7   ZC d8   ZD d9 eE f d:     YZF d; eF f d<     YZG d= eE f d>     YZH d? e jI f d@     YZJ dA eE f dB     YZK dC eK eF f dD     YZL dE eK eG f dF     YZM dG eE f dH     YZN d S(I   i(   t   with_statement(   t   chainN(   t   bt
   basestringt   bytest   imapt	   iteritemst   iterkeyst
   itervaluest   izipt   longt	   nativestrt   unicodet   safe_unicode(   t   ConnectionPoolt   UnixDomainSocketConnectiont   SSLConnectiont   Token(   t   Lockt   LuaLock(	   t   ConnectionErrort	   DataErrort   ExecAbortErrort   NoScriptErrort   PubSubErrort
   RedisErrort   ResponseErrort   TimeoutErrort
   WatchErrort    c         C  sf   y/ t  |   t |  t t f  r. |  g }  n  Wn t k
 rK |  g }  n X| rb |  j |  n  |  S(   N(   t   itert
   isinstanceR   R   t	   TypeErrort   extend(   t   keyst   args(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   list_or_args   s    
c         C  s?   |  s
 d Sy t |   }  Wn t k
 r. d SXt j j |   S(   s5   Converts a unix timestamp to a Python datetime objectN(   t   Nonet   intt
   ValueErrort   datetimet   fromtimestamp(   t   response(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   timestamp_to_datetime-   s    c         C  s   t  j |  j   |  S(   N(   t   dictt   fromkeyst   split(   t
   key_stringt   callback(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   string_keys_to_dict8   s    c          G  s(   i  } x |  D] } | j  |  q W| S(   N(   t   update(   t   dictst   mergedt   d(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   dict_merge<   s    c         C  s   t  |   }  d |  }  t g  |  j   D] } | j d  ^ q&  }  d } x1 | D]) } | |  k rQ t |  |  |  | <qQ qQ W|  S(   sD   Parse the results of Redis's DEBUG OBJECT command into a Python dicts   type:t   :t   refcountt   serializedlengtht   lrut   lru_seconds_idle(   R8   R9   R:   R;   (   R   R,   R.   R&   (   R*   t   kvt
   int_fieldst   field(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_debug_objectC   s    
.c         C  s   | d k r t  |   S|  S(   s&   Parse the results of an OBJECT commandt   idletimeR8   (   R@   R8   (   t   int_or_none(   R*   t   infotype(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_objectU   s    
c           s   i  } t  |   }    f d     x |  j   D]x } | r. | j d  r. | j d  d k r | j d d  \ } }   |  | | <q | j d g   j |  q. q. W| S(   s;   Parse the result of Redis's INFO command into a Python dictc           s   d |  k s d |  k rT y$ d |  k r1 t  |   St |   SWq t k
 rP |  SXnL i  } x? |  j d  D]. } | j d d  \ } }   |  | | <qj W| Sd  S(   Nt   ,t   =t   .i   (   t   floatR&   R'   R.   t   rsplit(   t   valuet   sub_dictt   itemt   kt   v(   t	   get_value(    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRN   a   s    
t   #R7   ii   t   __raw__(   R   t
   splitlinest
   startswitht   findR.   t
   setdefaultt   append(   R*   t   infot   linet   keyRI   (    (   RN   s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   parse_info\   s     s   can-failover-its-masters   config-epochs   down-after-millisecondss   failover-timeouts   info-refreshs   last-hello-messages   last-ok-ping-replys   last-ping-replys   last-ping-sents   master-link-down-times   master-ports   num-other-sentinelss
   num-slavess   o-down-times   pending-commandss   parallel-syncst   portt   quorums   role-reported-times   s-down-times   slave-prioritys   slave-repl-offsets   voted-leader-epochc         C  sh   t  |  t  } t | d j d   } x9 d d d d d d d f D] \ } } | | k | | <qD W| S(   Nt   flagsRD   t	   is_mastert   mastert   is_slavet   slavet   is_sdownt   s_downt   is_odownt   o_downt   is_sentinelt   sentinelt   is_disconnectedt   disconnectedt   is_master_downt   master_down(   R]   R^   (   R_   R`   (   Ra   Rb   (   Rc   Rd   (   Re   Rf   (   Rg   Rh   (   Ri   Rj   (   t   pairs_to_dict_typedt   SENTINEL_STATE_TYPESt   setR.   (   RK   t   resultR\   t   namet   flag(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_sentinel_state   s    	c         C  s   t  t t |    S(   N(   Rq   R   R   (   R*   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_sentinel_master   s    c         C  s>   i  } x1 |  D]) } t  t t |   } | | | d <q W| S(   NRo   (   Rq   R   R   (   R*   Rn   RK   t   state(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_sentinel_masters   s
    c         C  s&   g  |  D] } t  t t |   ^ q S(   N(   Rq   R   R   (   R*   RK   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt#   parse_sentinel_slaves_and_sentinels   s    c         C  s$   |  r  |  d t  |  d  f p# d  S(   Ni    i   (   R&   R%   (   R*   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_sentinel_get_master   s    c         C  s   t  |   } t t | |   S(   s-   Create a dict given a list of key/value pairs(   R   R,   R	   (   R*   t   it(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   pairs_to_dict   s    c         C  sm   t  |   } i  } xT t | |  D]C \ } } | | k r[ y | | |  } Wq[ q[ Xn  | | | <q" W| S(   N(   R   R	   (   R*   t	   type_infoRw   Rn   RX   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRk      s    c         K  sP   |  s | d r |  S| j  d t  } t |   } t t | t | |    S(   sr   
    If ``withscores`` is specified in the options, return the response as
    a list of (value, score) pairs
    t
   withscorest   score_cast_func(   t   getRG   R   t   listR	   R   (   R*   t   optionsR{   Rw   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zset_score_pairs   s
    c         K  sV   |  s | d r |  S| d } t  t g  t |  D] } |  | d |  ^ q3    S(   s   
    If ``groups`` is specified, return the response as a list of
    n-element tuples with n being the value found in options['groups']
    t   groupsN(   R}   R	   t   range(   R*   R~   t   nt   i(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sort_return_tuples   s    
c         C  s   |  d  k r d  St |   S(   N(   R%   R&   (   R*   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRA      s    c         C  s   |  d  k r d  St |   S(   N(   R%   RG   (   R*   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   float_or_none   s    c         C  s   t  |   d k S(   Nt   OK(   R   (   R*   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   bool_ok   s    c         K  s_   g  } xR t  |   j   D]> } | j t g  | j d  D] } | j d  ^ q8   q W| S(   Nt    RE   (   R   RQ   RU   R,   R.   (   R*   R~   t   clientst   ct   pair(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_client_list   s    <c         K  sG   g  |  D]$ } | d  k	 r% t |  n d  ^ q }  |  rC t |   pF i  S(   N(   R%   R   Rx   (   R*   R~   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_config_get   s    1c         K  s   |  \ } } t  |  | f S(   N(   R
   (   R*   R~   t   cursort   r(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   parse_scan   s    c         K  s.   |  \ } } t  |  | r' t |  p* i  f S(   N(   R
   Rx   (   R*   R~   R   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_hscan  s    c         K  sR   | j  d t  } |  \ } } t |  } t |  t t | t | |    f S(   NR{   (   R|   RG   R   R
   R}   R	   R   (   R*   R~   R{   R   R   Rw   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_zscan
  s    c         K  s^   g  |  D]S } i | d d 6t  | d  d 6t  | d  d 6t d  j | d  d	 6^ q S(
   Ni    t   idi   t
   start_timei   t   durationR   i   t   command(   R&   R   t   join(   R*   R~   RK   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   parse_slowlog_get  s    t   StrictRedisc           B  s:	  e  Z d  Z e e d e  e d e  e d e  e d d    e d e  e d e	  e d e
  e d	 d
    e d d    e d e  e d e  e d d    i# d   d 6e
 d 6e d 6e
 d 6e d 6e
 d 6e
 d 6e d 6d   d 6e d 6e d 6e d 6e d 6d    d! 6d"   d# 6e d$ 6d%   d& 6e
 d' 6e
 d( 6e d) 6e d* 6e d+ 6e d, 6e
 d- 6e
 d. 6e d/ 6e
 d0 6e d1 6d2   d3 6e d4 6e d5 6e
 d6 6e d7 6d8   d9 6e d: 6 Z e d d;   Z d< d= d> d d d d d d d d? d@ d d e  e  e  d d d d d dA  Z! dB   Z" dC   Z# e$ d dD  Z% dE   Z& d dF d d e$ dG  Z' dH   Z( dI   Z) dJ   Z* dK   Z+ dL   Z, dM   Z- dN   Z. dO   Z/ dP   Z0 dQ dR  Z1 dS   Z2 dT   Z3 dU   Z4 dV   Z5 dW   Z6 dX   Z7 dY   Z8 dZ   Z9 d d[  Z: d\   Z; d]   Z< d^   Z= d_   Z> d`   Z? da   Z@ db   ZA dc   ZB dd   ZC de   ZD df   ZE dg   ZF dh   ZG di   ZH d d dj  ZI d dk  ZJ dl   ZK dm   ZL dn   ZM do   ZN dp   ZO d d dq  ZP dr   ZQ d d ds  ZR dt du  ZS dv   ZT dw   ZU dx   ZV dy   ZW eW ZX dz   ZY d{   ZZ d|   Z[ d}   Z\ d~   Z] d   Z^ d   Z_ dt d  Z` dt d  Za d d  Zb dQ d  Zc d   Zd d   Ze d   Zf d   Zg d   Zh d   Zi d   Zj d   Zk d   Zl d   Zm d   Zn d   Zo d   Zp d d e  e  d  Zq d   Zr d   Zs d   Zt d   Zu d   Zv d   Zw d d  Zx d   Zy d   Zz d   Z{ d   Z| d> d  Z} d> d  Z~ d> d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d d d e  e  d e  d  Z d> d d d  Z d d d  Z d> d d d  Z d d d  Z d> d d d  Z d d d  Z d> d d e d  Z d d e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z dt d  Z d d  Z d   Z e  e  e d  Z d d d  Z d d d  Z d d e  e d  Z d   Z d   Z d   Z d   Z d   Z e  e d  Z d d e  e d  Z d   Z d   Z d d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z dt d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s&  
    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
    si   AUTH EXISTS EXPIRE EXPIREAT HEXISTS HMSET MOVE MSETNX PERSIST PSETEX RENAMENX SISMEMBER SMOVE SETEX SETNXs   BITCOUNT BITPOS DECRBY DEL GETBIT HDEL HLEN INCRBY LINSERT LLEN LPUSHX PFADD PFCOUNT RPUSHX SADD SCARD SDIFFSTORE SETBIT SETRANGE SINTERSTORE SREM STRLEN SUNIONSTORE ZADD ZCARD ZLEXCOUNT ZREM ZREMRANGEBYLEX ZREMRANGEBYRANK ZREMRANGEBYSCOREs   INCRBYFLOAT HINCRBYFLOATs   LPUSH RPUSHc         C  s%   t  |  t  r |  p$ t |   d k S(   NR   (   R   R
   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   <lambda>5  R   t   SORTs   ZSCORE ZINCRBYsZ   FLUSHALL FLUSHDB LSET LTRIM MSET PFMERGE RENAME SAVE SELECT SHUTDOWN SLAVEOF WATCH UNWATCHs   BLPOP BRPOPc         C  s   |  r t  |   p d  S(   N(   t   tupleR%   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   >  R   s   SDIFF SINTER SMEMBERS SUNIONc         C  s   |  r t  |   p t    S(   N(   Rm   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   A  R   s/   ZRANGE ZRANGEBYSCORE ZREVRANGE ZREVRANGEBYSCOREs   ZRANK ZREVRANKs   BGREWRITEAOF BGSAVEc         C  s   t  S(   N(   t   True(   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   H  R   c         C  s   |  o t  |   S(   N(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   J  R   s   CLIENT GETNAMEs   CLIENT KILLs   CLIENT LISTs   CLIENT SETNAMEs
   CONFIG GETs   CONFIG RESETSTATs
   CONFIG SETs   DEBUG OBJECTc         C  s   |  r t  |   p i  S(   N(   Rx   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   R  R   t   HGETALLt   HSCANt   INFOt   LASTSAVEt   OBJECTc         C  s   t  |   d k S(   Nt   PONG(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   W  R   t   PINGc         C  s   |  r |  p d  S(   N(   R%   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   X  R   t	   RANDOMKEYt   SCANc         C  s   t  t t |    S(   N(   R}   R   t   bool(   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   Z  R   s   SCRIPT EXISTSs   SCRIPT FLUSHs   SCRIPT KILLs   SCRIPT LOADs    SENTINEL GET-MASTER-ADDR-BY-NAMEs   SENTINEL MASTERs   SENTINEL MASTERSs   SENTINEL MONITORs   SENTINEL REMOVEs   SENTINEL SENTINELSs   SENTINEL SETs   SENTINEL SLAVESc         C  s   |  o t  |   d k S(   NR   (   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   f  R   t   SETs   SLOWLOG GETs   SLOWLOG LENs   SLOWLOG RESETt   SSCANc         C  s   t  |  d  t  |  d  f S(   Ni    i   (   R&   (   t   x(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   k  R   t   TIMEt   ZSCANc         K  s%   t  j | d | | } |  d |  S(   s[  
        Return a Redis client object configured from the given URL.

        For example::

            redis://[:password]@localhost:6379/0
            unix://[:password]@/path/to/socket.sock?db=0

        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.
        t   dbt   connection_pool(   R   t   from_url(   t   clst   urlR   t   kwargsR   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   p  s    t	   localhosti  i    s   utf-8t   strictc         C  sa  |	 s6| d  k	 r. t j t d   | } n  | d  k	 rV t j t d   | } n  i | d 6| d 6| d 6| d 6| d 6| d 6| d	 6| d
 6} |
 d  k	 r | j i |
 d 6t d 6 ni | j i | d 6| d 6| d 6| d 6| d 6 | r'| j i t d 6| d 6| d 6| d 6| d 6 n  t |   }	 n  |	 |  _ d  |  _	 |  j
 j j   |  _ d  S(   Ns/   "charset" is deprecated. Use "encoding" insteads5   "errors" is deprecated. Use "encoding_errors" insteadR   t   passwordt   socket_timeoutt   encodingt   encoding_errorst   decode_responsest   retry_on_timeoutt   max_connectionst   patht   connection_classt   hostRZ   t   socket_connect_timeoutt   socket_keepalivet   socket_keepalive_optionst   ssl_keyfilet   ssl_certfilet   ssl_cert_reqst   ssl_ca_certs(   R%   t   warningst   warnt   DeprecationWarningR2   R   R   R   R   t   _use_lua_lockt	   __class__t   RESPONSE_CALLBACKSt   copyt   response_callbacks(   t   selfR   RZ   R   R   R   R   R   R   R   t   unix_socket_pathR   R   t   charsett   errorsR   R   t   sslR   R   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __init__  sN    	
		
	
					c         C  s    d t  |   j t |  j  f S(   Ns   %s<%s>(   t   typet   __name__t   reprR   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __repr__  s    c         C  s   | |  j  | <d S(   s   Set a custom Response CallbackN(   R   (   R   R   R0   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   set_response_callback  s    c         C  s   t  |  j |  j | |  S(   s_  
        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.
        (   t   StrictPipelineR   R   (   R   t   transactiont
   shard_hint(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   pipeline  s
    c   
   	   O  s   | j  d d  } | j  d t  } | j  d d  } |  j t |   } x y@ | rg | j |   n  | |  } | j   }	 | r | S|	 SWqN t k
 r | d k	 rN | d k rN t j	 |  qN qN qN XqN WWd QXd S(   s   
        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   t   value_from_callablet   watch_delayi    N(
   t   popR%   t   FalseR   R   t   watcht   executeR   t   timet   sleep(
   R   t   funct   watchesR   R   R   R   t   pipet
   func_valuet
   exec_value(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     s    g?c         C  s   | d k rm |  j d k rU y t j |   t |  _ WqU t k
 rQ t |  _ qU Xn  |  j rd t pg t } n  | |  | d | d | d | d | S(   s$	  
        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.        t   timeoutR   t   blocking_timeoutt   thread_localN(   R%   R   R   t   register_scriptsR   R   R   R   (   R   Ro   R   R   R   t
   lock_classR   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lock  s    -c         K  s   t  |  j |  S(   s   
        Return a Publish/Subscribe object. With this object, you can
        subscribe to channels and listen for messages that get published to
        them.
        (   t   PubSubR   (   R   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   pubsub-  s    c         O  s   |  j  } | d } | j | |  } z y$ | j |   |  j | | |  SWn_ t t f k
 r } | j   | j r t | t  r   n  | j |   |  j | | |  SXWd | j	 |  Xd S(   s.   Execute a command and return a parsed responsei    N(
   R   t   get_connectiont   send_commandt   parse_responseR   R   t
   disconnectR   R   t   release(   R   R#   R~   t   poolt   command_namet
   connectiont   e(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   execute_command6  s    	
 
c         K  s3   | j    } | |  j k r/ |  j | | |  S| S(   s'   Parses a response from the Redis server(   t   read_responseR   (   R   R   R   R~   R*   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   G  s    c         C  s   |  j  d  S(   sB   Tell the Redis server to rewrite the AOF file from data in memory.t   BGREWRITEAOF(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   bgrewriteaofO  s    c         C  s   |  j  d  S(   s   
        Tell the Redis server to save its data to disk.  Unlike save(),
        this method is asynchronous and returns immediately.
        t   BGSAVE(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   bgsaveS  s    c         C  s   |  j  d |  S(   s/   Disconnects the client at ``address`` (ip:port)s   CLIENT KILL(   R   (   R   t   address(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   client_killZ  s    c         C  s   |  j  d  S(   s-   Returns a list of currently connected clientss   CLIENT LIST(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   client_list^  s    c         C  s   |  j  d  S(   s#   Returns the current connection names   CLIENT GETNAME(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   client_getnameb  s    c         C  s   |  j  d |  S(   s    Sets the current connection names   CLIENT SETNAME(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   client_setnamef  s    t   *c         C  s   |  j  d |  S(   s=   Return a dictionary of configuration based on the ``pattern``s
   CONFIG GET(   R   (   R   t   pattern(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   config_getj  s    c         C  s   |  j  d | |  S(   s'   Set config item ``name`` with ``value``s
   CONFIG SET(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   config_setn  s    c         C  s   |  j  d  S(   s   Reset runtime statisticss   CONFIG RESETSTAT(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   config_resetstatr  s    c         C  s   |  j  d  S(   sE   Rewrite config file with the minimal change to reflect running configs   CONFIG REWRITE(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   config_rewritev  s    c         C  s   |  j  d  S(   s2   Returns the number of keys in the current databaset   DBSIZE(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   dbsizez  s    c         C  s   |  j  d |  S(   s;   Returns version specific meta information about a given keys   DEBUG OBJECT(   R   (   R   RX   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   debug_object~  s    c         C  s   |  j  d |  S(   s$   Echo the string back from the servert   ECHO(   R   (   R   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   echo  s    c         C  s   |  j  d  S(   s4   Delete all keys in all databases on the current hostt   FLUSHALL(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   flushall  s    c         C  s   |  j  d  S(   s'   Delete all keys in the current databaset   FLUSHDB(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   flushdb  s    c         C  s-   | d k r |  j d  S|  j d |  Sd S(   s,  
        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   N(   R%   R   (   R   t   section(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRV     s    
c         C  s   |  j  d  S(   sy   
        Return a Python datetime object representing the last time the
        Redis database was saved to disk
        R   (   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lastsave  s    c         C  s   |  j  d | | d | S(   s8   Return the encoding, idletime, or refcount about the keyR   RB   (   R   (   R   RB   RX   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   object  s    c         C  s   |  j  d  S(   s   Ping the Redis serverR   (   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   ping  s    c         C  s   |  j  d  S(   sm   
        Tell the Redis server to save its data to disk,
        blocking until the save is complete
        t   SAVE(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   save  s    c         G  s   t  j t d   d S(   s"   Redis Sentinel's SENTINEL command.s%   Use the individual sentinel_* methodsN(   R   R   R   (   R   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRf     s    c         C  s   |  j  d |  S(   s:   Returns a (host, port) pair for the given ``service_name``s    SENTINEL GET-MASTER-ADDR-BY-NAME(   R   (   R   t   service_name(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt    sentinel_get_master_addr_by_name  s    	c         C  s   |  j  d |  S(   s<   Returns a dictionary containing the specified masters state.s   SENTINEL MASTER(   R   (   R   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sentinel_master  s    c         C  s   |  j  d  S(   s>   Returns a list of dictionaries containing each master's state.s   SENTINEL MASTERS(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sentinel_masters  s    c         C  s   |  j  d | | | |  S(   s,   Add a new master to Sentinel to be monitoreds   SENTINEL MONITOR(   R   (   R   Ro   t   ipRZ   R[   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sentinel_monitor  s    c         C  s   |  j  d |  S(   s*   Remove a master from Sentinel's monitorings   SENTINEL REMOVE(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sentinel_remove  s    c         C  s   |  j  d |  S(   s0   Returns a list of sentinels for ``service_name``s   SENTINEL SENTINELS(   R   (   R   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sentinel_sentinels  s    c         C  s   |  j  d | | |  S(   s5   Set Sentinel monitoring parameters for a given masters   SENTINEL SET(   R   (   R   Ro   t   optionRI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sentinel_set  s    c         C  s   |  j  d |  S(   s-   Returns a list of slaves for ``service_name``s   SENTINEL SLAVES(   R   (   R   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sentinel_slaves  s    c         C  s6   y |  j  d  Wn t k
 r% d SXt d   d S(   s   Shutdown the servert   SHUTDOWNNs   SHUTDOWN seems to have failed.(   R   R   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   shutdown  s
    c         C  sJ   | d k r7 | d k r7 |  j d t d  t d   S|  j d | |  S(   s   
        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.
        t   SLAVEOFt   NOt   ONEN(   R%   R   R   (   R   R   RZ   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   slaveof  s    c         C  s2   d g } | d k	 r% | j |  n  |  j |   S(   sw   
        Get the entries from the slowlog. If ``num`` is specified, get the
        most recent ``num`` items.
        s   SLOWLOG GETN(   R%   RU   R   (   R   t   numR#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   slowlog_get  s    	c         C  s   |  j  d  S(   s&   Get the number of items in the slowlogs   SLOWLOG LEN(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   slowlog_len  s    c         C  s   |  j  d  S(   s   Remove all items in the slowlogs   SLOWLOG RESET(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   slowlog_reset  s    c         C  s   |  j  d  S(   s   
        Returns the server time as a 2-item tuple of ints:
        (seconds since epoch, microseconds into this second).
        R   (   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     s    c         C  s   |  j  d | |  S(   s   
        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.
        t   WAIT(   R   (   R   t   num_replicasR   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   wait  s    c         C  s   |  j  d | |  S(   s   
        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``.
        t   APPEND(   R   (   R   RX   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRU     s    c         C  s   | g } | d k	 r> | d k	 r> | j |  | j |  n? | d k	 rV | d k sn | d k	 r} | d k r} t d   n  |  j d |  S(   s   
        Returns the count of set bits in the value of ``key``.  Optional
        ``start`` and ``end`` paramaters indicate which bytes to consider
        s$   Both start and end must be specifiedt   BITCOUNTN(   R%   RU   R   R   (   R   RX   t   startt   endt   params(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   bitcount  s    	c         G  s   |  j  d | | |  S(   s|   
        Perform a bitwise operation using ``operation`` between ``keys`` and
        store the result in ``dest``.
        t   BITOP(   R   (   R   t	   operationt   destR"   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   bitop%  s    c         C  s   | d k r t  d   n  | | g } | d k	 o? | j |  | d k	 rh | d k	 rh | j |  n' | d k r | d k	 r t  d   n  |  j d |  S(   s  
        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.
        i    i   s   bit must be 0 or 1s0   start argument is not set, when end is specifiedt   BITPOS(   i    i   N(   R   R%   RU   R   (   R   RX   t   bitR5  R6  R7  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   bitpos,  s    i   c         C  s   |  j  d | |  S(   s   
        Decrements the value of ``key`` by ``amount``.  If no key exists,
        the value will be initialized as 0 - ``amount``
        t   DECRBY(   R   (   R   Ro   t   amount(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   decr@  s    c         G  s   |  j  d |  S(   s.   Delete one or more keys specified by ``names``t   DEL(   R   (   R   t   names(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   deleteG  s    c         C  s   |  j  |  d  S(   N(   RE  (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __delitem__K  s    c         C  s   |  j  d |  S(   s   
        Return a serialized version of the value stored at the specified key.
        If key does not exist a nil bulk reply is returned.
        t   DUMP(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   dumpN  s    c         C  s   |  j  d |  S(   s8   Returns a boolean indicating whether key ``name`` existst   EXISTS(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   existsU  s    c         C  s@   t  | t j  r- | j | j d d } n  |  j d | |  S(   s   
        Set an expire flag on key ``name`` for ``time`` seconds. ``time``
        can be represented by an integer or a Python timedelta object.
        i   i  t   EXPIRE(   R   R(   t	   timedeltat   secondst   daysR   (   R   Ro   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   expireZ  s    c         C  sC   t  | t j  r0 t t j | j     } n  |  j d | |  S(   s   
        Set an expire flag on key ``name``. ``when`` can be represented
        as an integer indicating unix time or a Python datetime object.
        t   EXPIREAT(   R   R(   R&   t   mod_timet   mktimet	   timetupleR   (   R   Ro   t   when(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   expireatc  s    c         C  s   |  j  d |  S(   sT   
        Return the value at key ``name``, or None if the key doesn't exist
        t   GET(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR|   l  s    c         C  s)   |  j  |  } | r | St |   d S(   sg   
        Return the value at key ``name``, raises a KeyError if the key
        doesn't exist.
        N(   R|   t   KeyError(   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __getitem__r  s    c         C  s   |  j  d | |  S(   s@   Returns a boolean indicating the value of ``offset`` in ``name``t   GETBIT(   R   (   R   Ro   t   offset(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   getbit|  s    c         C  s   |  j  d | | |  S(   s   
        Returns the substring of the string value stored at ``key``,
        determined by the offsets ``start`` and ``end`` (both are inclusive)
        t   GETRANGE(   R   (   R   RX   R5  R6  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   getrange  s    c         C  s   |  j  d | |  S(   s{   
        Sets the value at key ``name`` to ``value``
        and returns the old value at key ``name`` atomically.
        t   GETSET(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   getset  s    c         C  s   |  j  d | |  S(   s   
        Increments the value of ``key`` by ``amount``.  If no key exists,
        the value will be initialized as ``amount``
        t   INCRBY(   R   (   R   Ro   RA  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   incr  s    c         C  s   |  j  | |  S(   s   
        Increments the value of ``key`` by ``amount``.  If no key exists,
        the value will be initialized as ``amount``
        (   Ra  (   R   Ro   RA  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   incrby  s    g      ?c         C  s   |  j  d | |  S(   s   
        Increments the value at key ``name`` by floating ``amount``.
        If no key exists, the value will be initialized as ``amount``
        t   INCRBYFLOAT(   R   (   R   Ro   RA  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   incrbyfloat  s    c         C  s   |  j  d |  S(   s+   Returns a list of keys matching ``pattern``t   KEYS(   R   (   R   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR"     s    c         G  s   t  | |  } |  j d |  S(   sJ   
        Returns a list of values ordered identically to ``keys``
        t   MGET(   R$   R   (   R   R"   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   mget  s    c         O  s   | rO t  |  d k s, t | d t  r; t d   n  | j | d  n  g  } x! t |  D] } | j |  qb W|  j d |  S(   s   
        Sets key/values based on a mapping. Mapping can be supplied as a single
        dictionary argument or as kwargs.
        i   i    s+   MSET requires **kwargs or a single dict argt   MSET(   t   lenR   R,   R   R2   R   R!   R   (   R   R#   R   t   itemsR   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   mset  s    &c         O  s   | rO t  |  d k s, t | d t  r; t d   n  | j | d  n  g  } x! t |  D] } | j |  qb W|  j d |  S(   s   
        Sets key/values based on a mapping if none of the keys are already set.
        Mapping can be supplied as a single dictionary argument or as kwargs.
        Returns a boolean indicating if the operation was successful.
        i   i    s-   MSETNX requires **kwargs or a single dict argt   MSETNX(   Ri  R   R,   R   R2   R   R!   R   (   R   R#   R   Rj  R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   msetnx  s    &c         C  s   |  j  d | |  S(   s;   Moves the key ``name`` to a different Redis database ``db``t   MOVE(   R   (   R   Ro   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   move  s    c         C  s   |  j  d |  S(   s!   Removes an expiration on ``name``t   PERSIST(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   persist  s    c         C  s[   t  | t j  rH t | j d  } | j | j d d d | } n  |  j d | |  S(   s   
        Set an expire flag on key ``name`` for ``time`` milliseconds.
        ``time`` can be represented by an integer or a Python timedelta
        object.
        i  i   i  t   PEXPIRE(   R   R(   RL  R&   t   microsecondsRM  RN  R   (   R   Ro   R   t   ms(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   pexpire  s    #c         C  s^   t  | t j  rK t | j d  } t t j | j     d | } n  |  j d | |  S(   s   
        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.
        i  t	   PEXPIREAT(   R   R(   R&   t   microsecondRQ  RR  RS  R   (   R   Ro   RT  Rt  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt	   pexpireat  s    &c         C  s^   t  | t j  rH t | j d  } | j | j d d d | } n  |  j d | | |  S(   s   
        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
        i  i   i  t   PSETEX(   R   R(   RL  R&   Rs  RM  RN  R   (   R   Ro   t   time_msRI   Rt  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   psetex  s    #c         C  s   |  j  d |  S(   sE   Returns the number of milliseconds until the key ``name`` will expiret   PTTL(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   pttl  s    c         C  s   |  j  d  S(   s    Returns the name of a random keyR   (   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt	   randomkey  s    c         C  s   |  j  d | |  S(   s/   
        Rename key ``src`` to ``dst``
        t   RENAME(   R   (   R   t   srct   dst(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   rename   s    c         C  s   |  j  d | |  S(   s>   Rename key ``src`` to ``dst`` if ``dst`` doesn't already existt   RENAMENX(   R   (   R   R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   renamenx  s    c         C  s   |  j  d | | |  S(   sk   
        Create a key using the provided serialized value, previously obtained
        using DUMP.
        t   RESTORE(   R   (   R   Ro   t   ttlRI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   restore
  s    c   	      C  s  | | g } | r\ | j  d  t | t j  rL | j | j d d } n  | j  |  n  | r | j  d  t | t j  r t | j d  } | j | j d d d | } n  | j  |  n  | r | j  d  n  | r | j  d  n  |  j d |  S(	   s  
        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`` if it
            does not already exist.

        ``xx`` if set to True, set the value at key ``name`` to ``value`` if it
            already exists.
        t   EXi   i  t   PXi  t   NXt   XXR   (	   RU   R   R(   RL  RM  RN  R&   Rs  R   (	   R   Ro   RI   t   ext   pxt   nxt   xxt   piecesRt  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRm     s"    #c         C  s   |  j  | |  d  S(   N(   Rm   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __setitem__2  s    c         C  s(   | r d p d } |  j  d | | |  S(   s   
        Flag the ``offset`` in ``name`` as ``value``. Returns a boolean
        indicating the previous value of ``offset``.
        i   i    t   SETBIT(   R   (   R   Ro   RZ  RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   setbit5  s    c         C  sC   t  | t j  r- | j | j d d } n  |  j d | | |  S(   s   
        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.
        i   i  t   SETEX(   R   R(   RL  RM  RN  R   (   R   Ro   R   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   setex=  s    c         C  s   |  j  d | |  S(   s?   Set the value of key ``name`` to ``value`` if key doesn't existt   SETNX(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   setnxG  s    c         C  s   |  j  d | | |  S(   s  
        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.
        t   SETRANGE(   R   (   R   Ro   RZ  RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   setrangeK  s    c         C  s   |  j  d |  S(   s:   Return the number of bytes stored in the value of ``name``t   STRLEN(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   strlenX  s    ic         C  s   |  j  d | | |  S(   s   
        Return a substring of the string at key ``name``. ``start`` and ``end``
        are 0-based integers specifying the portion of the string to return.
        t   SUBSTR(   R   (   R   Ro   R5  R6  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   substr\  s    c         C  s   |  j  d |  S(   s@   Returns the number of seconds until the key ``name`` will expiret   TTL(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR  c  s    c         C  s   |  j  d |  S(   s    Returns the type of key ``name``t   TYPE(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   g  s    c         G  s   t  j t d   d S(   sX   
        Watches the values at keys ``names``, or None if the key doesn't exist
        s!   Call WATCH from a Pipeline objectN(   R   R   R   (   R   RD  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   k  s    c         C  s   t  j t d   d S(   sW   
        Unwatches the value at key ``name``, or None of the key doesn't exist
        s#   Call UNWATCH from a Pipeline objectN(   R   R   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   unwatchq  s    c         C  sY   | d k r d } n  t | t  r0 | g } n t |  } | j |  |  j d |  S(   s=  
        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.
        i    t   BLPOPN(   R%   R   R   R}   RU   R   (   R   R"   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   blpopy  s    	c         C  sY   | d k r d } n  t | t  r0 | g } n t |  } | j |  |  j d |  S(   s=  
        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 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.
        i    t   BRPOPN(   R%   R   R   R}   RU   R   (   R   R"   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   brpop  s    	c         C  s+   | d k r d } n  |  j d | | |  S(   s  
        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.
        i    t
   BRPOPLPUSHN(   R%   R   (   R   R  R  R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   brpoplpush  s    		c         C  s   |  j  d | |  S(   s   
        Return the item from list ``name`` at position ``index``

        Negative indexes are supported and will return an item at the
        end of the list
        t   LINDEX(   R   (   R   Ro   t   index(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lindex  s    c         C  s   |  j  d | | | |  S(   s   
        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.
        t   LINSERT(   R   (   R   Ro   t   wheret   refvalueRI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   linsert  s    c         C  s   |  j  d |  S(   s&   Return the length of the list ``name``t   LLEN(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   llen  s    c         C  s   |  j  d |  S(   s5   Remove and return the first item of the list ``name``t   LPOP(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lpop  s    c         G  s   |  j  d | |  S(   s2   Push ``values`` onto the head of the list ``name``t   LPUSH(   R   (   R   Ro   t   values(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lpush  s    c         C  s   |  j  d | |  S(   sD   Push ``value`` onto the head of the list ``name`` if ``name`` existst   LPUSHX(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lpushx  s    c         C  s   |  j  d | | |  S(   s   
        Return a slice of the list ``name`` between
        position ``start`` and ``end``

        ``start`` and ``end`` can be negative numbers just like
        Python slicing notation
        t   LRANGE(   R   (   R   Ro   R5  R6  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lrange  s    c         C  s   |  j  d | | |  S(   s  
        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.
        t   LREM(   R   (   R   Ro   t   countRI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lrem  s    
c         C  s   |  j  d | | |  S(   s.   Set ``position`` of list ``name`` to ``value``t   LSET(   R   (   R   Ro   R  RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   lset  s    c         C  s   |  j  d | | |  S(   s   
        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
        t   LTRIM(   R   (   R   Ro   R5  R6  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   ltrim  s    c         C  s   |  j  d |  S(   s4   Remove and return the last item of the list ``name``t   RPOP(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   rpop  s    c         C  s   |  j  d | |  S(   s   
        RPOP a value off of the ``src`` list and atomically LPUSH it
        on to the ``dst`` list.  Returns the value.
        t	   RPOPLPUSH(   R   (   R   R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt	   rpoplpush  s    c         G  s   |  j  d | |  S(   s2   Push ``values`` onto the tail of the list ``name``t   RPUSH(   R   (   R   Ro   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   rpush   s    c         C  s   |  j  d | |  S(   sD   Push ``value`` onto the tail of the list ``name`` if ``name`` existst   RPUSHX(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   rpushx  s    c
         C  s
  | d k	 r | d k s0 | d k	 r? | d k r? t d   n  | g }
 | d k	 rw |
 j t d   |
 j |  n  | d k	 r | d k	 r |
 j t d   |
 j |  |
 j |  n  | d k	 r1t | t  r |
 j t d   |
 j |  q1x1 | D]& } |
 j t d   |
 j |  qWn  | rM|
 j t d   n  | ri|
 j t d   n  | d k	 r|
 j t d   |
 j |  n  |	 r| st | t  st |  d k  rt d	   qn  i |	 rt |  n d d
 6} |  j d |
 |  S(   s  
        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 int he 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``.

        s,   ``start`` and ``num`` must both be specifiedt   BYt   LIMITRV  t   DESCt   ALPHAt   STOREi   sV   when using "groups" the "get" argument must be specified and contain at least two keysR   R   N(	   R%   R   RU   R   R   R   Ri  R   R   (   R   Ro   R5  R,  t   byR|   t   desct   alphat   storeR   R  t   gR~   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sort  s<    	(c         C  si   | g } | d k	 r1 | j t d  | g  n  | d k	 rY | j t d  | g  n  |  j d |  S(   s   
        Incrementally return lists of key names. 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
        t   MATCHt   COUNTR   N(   R%   R!   R   R   (   R   R   t   matchR  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   scanL  s    		c         c  sW   d } xJ | d k rR |  j  d | d | d |  \ } } x | D] } | Vq@ Wq	 Wd S(   s   
        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`` allows for hint the minimum number of returns
        t   0i    R   R  R  N(   R  (   R   R  R  R   t   dataRK   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt	   scan_iter\  s
    	$c         C  sl   | | g } | d k	 r4 | j t d  | g  n  | d k	 r\ | j t d  | g  n  |  j d |  S(   s   
        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   N(   R%   R!   R   R   (   R   Ro   R   R  R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sscank  s    	c         c  sZ   d } xM | d k rU |  j  | d | d | d | \ } } x | D] } | VqC Wq	 Wd S(   s   
        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  i    R   R  R  N(   R  (   R   Ro   R  R  R   R  RK   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   sscan_iter{  s    	c         C  sl   | | g } | d k	 r4 | j t d  | g  n  | d k	 r\ | j t d  | g  n  |  j d |  S(   s   
        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   N(   R%   R!   R   R   (   R   Ro   R   R  R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hscan  s    	c         c  s`   d } xS | d k r[ |  j  | d | d | d | \ } } x | j   D] } | VqI Wq	 Wd S(   s   
        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  i    R   R  R  N(   R  Rj  (   R   Ro   R  R  R   R  RK   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   hscan_iter  s    	c         C  s|   | | g } | d k	 r4 | j t d  | g  n  | d k	 r\ | j t d  | g  n  i | d 6} |  j d | |  S(   sM  
        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   N(   R%   R!   R   R   (   R   Ro   R   R  R  R{   R  R~   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zscan  s    c      
   c  s`   d } xS | d k r[ |  j  | d | d | d | d | \ } } x | D] } | VqI Wq	 Wd S(   sL  
        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  i    R   R  R  R{   N(   R  (   R   Ro   R  R  R{   R   R  RK   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   zscan_iter  s    c         G  s   |  j  d | |  S(   s    Add ``value(s)`` to set ``name``t   SADD(   R   (   R   Ro   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sadd  s    c         C  s   |  j  d |  S(   s-   Return the number of elements in set ``name``t   SCARD(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   scard  s    c         G  s   t  | |  } |  j d |  S(   s3   Return the difference of sets specified by ``keys``t   SDIFF(   R$   R   (   R   R"   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sdiff  s    c         G  s"   t  | |  } |  j d | |  S(   s   
        Store the difference of sets specified by ``keys`` into a new
        set named ``dest``.  Returns the number of keys in the new set.
        t
   SDIFFSTORE(   R$   R   (   R   R;  R"   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   sdiffstore  s    c         G  s   t  | |  } |  j d |  S(   s5   Return the intersection of sets specified by ``keys``t   SINTER(   R$   R   (   R   R"   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sinter  s    c         G  s"   t  | |  } |  j d | |  S(   s   
        Store the intersection of sets specified by ``keys`` into a new
        set named ``dest``.  Returns the number of keys in the new set.
        t   SINTERSTORE(   R$   R   (   R   R;  R"   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sinterstore  s    c         C  s   |  j  d | |  S(   sD   Return a boolean indicating if ``value`` is a member of set ``name``t	   SISMEMBER(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt	   sismember  s    c         C  s   |  j  d |  S(   s&   Return all members of the set ``name``t   SMEMBERS(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   smembers  s    c         C  s   |  j  d | | |  S(   s9   Move ``value`` from set ``src`` to set ``dst`` atomicallyt   SMOVE(   R   (   R   R  R  RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   smove  s    c         C  s   |  j  d |  S(   s1   Remove and return a random member of set ``name``t   SPOP(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   spop  s    c         C  s(   | r | g p g  } |  j  d | |  S(   s   
        If ``number`` is None, returns a random member of set ``name``.

        If ``number`` is supplied, returns a list of ``number`` random
        memebers of set ``name``. Note this is only available when running
        Redis 2.6+.
        t   SRANDMEMBER(   R   (   R   Ro   t   numberR#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   srandmember  s    c         G  s   |  j  d | |  S(   s#   Remove ``values`` from set ``name``t   SREM(   R   (   R   Ro   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   srem  s    c         G  s   t  | |  } |  j d |  S(   s.   Return the union of sets specified by ``keys``t   SUNION(   R$   R   (   R   R"   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sunion  s    c         G  s"   t  | |  } |  j d | |  S(   s   
        Store the union of sets specified by ``keys`` into a new
        set named ``dest``.  Returns the number of keys in the new set.
        t   SUNIONSTORE(   R$   R   (   R   R;  R"   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   sunionstore  s    c         O  s   g  } | rA t  |  d d k r1 t d   n  | j |  n  x6 t |  D]( } | j | d  | j | d  qN W|  j d | |  S(   s  
        Set any number of score, element-name pairs to the key ``name``. Pairs
        can be specified in two ways:

        As *args, in the form of: score1, name1, score2, name2, ...
        or as **kwargs, in the form of: name1=score1, name2=score2, ...

        The following example would add four values to the 'my-key' key:
        redis.zadd('my-key', 1.1, 'name1', 2.2, 'name2', name3=3.3, name4=4.4)
        i   i    s2   ZADD requires an equal number of values and scoresi   t   ZADD(   Ri  R   R!   R   RU   R   (   R   Ro   R#   R   R  R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zadd#  s    c         C  s   |  j  d |  S(   s8   Return the number of elements in the sorted set ``name``t   ZCARD(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zcard9  s    c         C  s   |  j  d | | |  S(   s   
        Returns the number of elements in the sorted set at key ``name`` with
        a score between ``min`` and ``max``.
        t   ZCOUNT(   R   (   R   Ro   t   mint   max(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zcount=  s    c         C  s   |  j  d | | |  S(   sE   Increment the score of ``value`` in sorted set ``name`` by ``amount``t   ZINCRBY(   R   (   R   Ro   RI   RA  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zincrbyD  s    c         C  s   |  j  d | | |  S(   s   
        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.
        t   ZINTERSTORE(   t   _zaggregate(   R   R;  R"   t	   aggregate(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zinterstoreH  s    c         C  s   |  j  d | | |  S(   s   
        Return the number of items in the sorted set ``name`` between the
        lexicographical range ``min`` and ``max``.
        t	   ZLEXCOUNT(   R   (   R   Ro   R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt	   zlexcountP  s    c   	      C  sq   | r |  j  | | | | |  Sd | | | g } | rM | j t d   n  i | d 6| d 6} |  j | |   S(   s  
        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
        t   ZRANGEt
   WITHSCORESRz   R{   (   t	   zrevrangeRU   R   R   (	   R   Ro   R5  R6  R  Rz   R{   R  R~   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zrangeW  s    
c         C  s   | d k	 r | d k s0 | d k	 r? | d k r? t d   n  d | | | g } | d k	 r | d k	 r | j t d  | | g  n  |  j |   S(   s   
        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.
        s,   ``start`` and ``num`` must both be specifiedt   ZRANGEBYLEXR  N(   R%   R   R!   R   R   (   R   Ro   R  R  R5  R,  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zrangebylexr  s    c         C  s   | d k	 r | d k s0 | d k	 r? | d k r? t d   n  d | | | g } | d k	 r | d k	 r | j t d  | | g  n  |  j |   S(   s   
        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.
        s,   ``start`` and ``num`` must both be specifiedt   ZREVRANGEBYLEXR  N(   R%   R   R!   R   R   (   R   Ro   R  R  R5  R,  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zrevrangebylex  s    c   
      C  s   | d k	 r | d k s0 | d k	 r? | d k r? t d   n  d | | | g } | d k	 r | d k	 r | j t d  | | g  n  | r | j t d   n  i | d 6| d 6}	 |  j | |	   S(   s  
        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
        s,   ``start`` and ``num`` must both be specifiedt   ZRANGEBYSCORER  R  Rz   R{   N(   R%   R   R!   R   RU   R   (
   R   Ro   R  R  R5  R,  Rz   R{   R  R~   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zrangebyscore  s    
c         C  s   |  j  d | |  S(   si   
        Returns a 0-based value indicating the rank of ``value`` in sorted set
        ``name``
        t   ZRANK(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zrank  s    c         G  s   |  j  d | |  S(   s1   Remove member ``values`` from sorted set ``name``t   ZREM(   R   (   R   Ro   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zrem  s    c         C  s   |  j  d | | |  S(   s   
        Remove all elements in the sorted set ``name`` between the
        lexicographical range specified by ``min`` and ``max``.

        Returns the number of elements removed.
        t   ZREMRANGEBYLEX(   R   (   R   Ro   R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zremrangebylex  s    c         C  s   |  j  d | | |  S(   s  
        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
        t   ZREMRANGEBYRANK(   R   (   R   Ro   R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zremrangebyrank  s    c         C  s   |  j  d | | |  S(   s   
        Remove all elements in the sorted set ``name`` with scores
        between ``min`` and ``max``. Returns the number of elements removed.
        t   ZREMRANGEBYSCORE(   R   (   R   Ro   R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zremrangebyscore  s    c         C  sR   d | | | g } | r. | j  t d   n  i | d 6| d 6} |  j | |   S(   s  
        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
        t	   ZREVRANGER  Rz   R{   (   RU   R   R   (   R   Ro   R5  R6  Rz   R{   R  R~   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR    s    
c   
      C  s   | d k	 r | d k s0 | d k	 r? | d k r? t d   n  d | | | g } | d k	 r | d k	 r | j t d  | | g  n  | r | j t d   n  i | d 6| d 6}	 |  j | |	   S(   s  
        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
        s,   ``start`` and ``num`` must both be specifiedt   ZREVRANGEBYSCORER  R  Rz   R{   N(   R%   R   R!   R   RU   R   (
   R   Ro   R  R  R5  R,  Rz   R{   R  R~   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zrevrangebyscore  s    
c         C  s   |  j  d | |  S(   st   
        Returns a 0-based value indicating the descending rank of
        ``value`` in sorted set ``name``
        t   ZREVRANK(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zrevrank  s    c         C  s   |  j  d | |  S(   s<   Return the score of element ``value`` in sorted set ``name``t   ZSCORE(   R   (   R   Ro   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zscore  s    c         C  s   |  j  d | | |  S(   s   
        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.
        t   ZUNIONSTORE(   R  (   R   R;  R"   R	  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   zunionstore  s    c         C  s   | | t  |  g } t | t  r@ t |  t |  } } n d  } | j |  | r| | j t d   | j |  n  | r | j t d   | j |  n  |  j	 |   S(   Nt   WEIGHTSt	   AGGREGATE(
   Ri  R   R,   R   R   R%   R!   RU   R   R   (   R   R   R;  R"   R	  R  t   weights(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR    s    c         G  s   |  j  d | |  S(   s9   Adds the specified elements to the specified HyperLogLog.t   PFADD(   R   (   R   Ro   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   pfadd'  s    c         G  s   |  j  d |  S(   so   
        Return the approximated cardinality of
        the set observed by the HyperLogLog at key(s).
        t   PFCOUNT(   R   (   R   t   sources(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   pfcount+  s    c         G  s   |  j  d | |  S(   s1   Merge N different HyperLogLogs into a single one.t   PFMERGE(   R   (   R   R;  R0  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   pfmerge2  s    c         G  s   |  j  d | |  S(   s"   Delete ``keys`` from hash ``name``t   HDEL(   R   (   R   Ro   R"   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hdel7  s    c         C  s   |  j  d | |  S(   sC   Returns a boolean indicating if ``key`` exists within hash ``name``t   HEXISTS(   R   (   R   Ro   RX   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hexists;  s    c         C  s   |  j  d | |  S(   s4   Return the value of ``key`` within the hash ``name``t   HGET(   R   (   R   Ro   RX   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hget?  s    c         C  s   |  j  d |  S(   s3   Return a Python dict of the hash's name/value pairsR   (   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hgetallC  s    c         C  s   |  j  d | | |  S(   s=   Increment the value of ``key`` in hash ``name`` by ``amount``t   HINCRBY(   R   (   R   Ro   RX   RA  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hincrbyG  s    c         C  s   |  j  d | | |  S(   sX   
        Increment the value of ``key`` in hash ``name`` by floating ``amount``
        t   HINCRBYFLOAT(   R   (   R   Ro   RX   RA  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hincrbyfloatK  s    c         C  s   |  j  d |  S(   s,   Return the list of keys within hash ``name``t   HKEYS(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hkeysQ  s    c         C  s   |  j  d |  S(   s.   Return the number of elements in hash ``name``t   HLEN(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hlenU  s    c         C  s   |  j  d | | |  S(   sz   
        Set ``key`` to ``value`` within hash ``name``
        Returns 1 if HSET created a new field, otherwise 0
        t   HSET(   R   (   R   Ro   RX   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hsetY  s    c         C  s   |  j  d | | |  S(   s   
        Set ``key`` to ``value`` within hash ``name`` if ``key`` does not
        exist.  Returns 1 if HSETNX created a field, otherwise 0.
        t   HSETNX(   R   (   R   Ro   RX   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hsetnx`  s    c         C  sR   | s t  d   n  g  } x! t |  D] } | j |  q( W|  j d | |  S(   s   
        Set key to value within hash ``name`` for each corresponding
        key and value from the ``mapping`` dict.
        s"   'hmset' with 'mapping' of length 0t   HMSET(   R   R   R!   R   (   R   Ro   t   mappingRj  R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hmsetg  s    c         G  s"   t  | |  } |  j d | |  S(   s8   Returns a list of values ordered identically to ``keys``t   HMGET(   R$   R   (   R   Ro   R"   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hmgets  s    c         C  s   |  j  d |  S(   s.   Return the list of values within hash ``name``t   HVALS(   R   (   R   Ro   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   hvalsx  s    c         C  s   |  j  d | |  S(   s}   
        Publish ``message`` on ``channel``.
        Returns the number of subscribers the message was delivered to.
        t   PUBLISH(   R   (   R   t   channelt   message(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   publish|  s    c         G  s   |  j  d | | |  S(   sP  
        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.
        t   EVAL(   R   (   R   t   scriptt   numkeyst   keys_and_args(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   eval  s    	c         G  s   |  j  d | | |  S(   s  
        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.
        t   EVALSHA(   R   (   R   t   shaRT  RU  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   evalsha  s    
c         G  s   |  j  d |  S(   s   
        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.
        s   SCRIPT EXISTS(   R   (   R   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   script_exists  s    c         C  s   |  j  d  S(   s'   Flush all scripts from the script caches   SCRIPT FLUSH(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   script_flush  s    c         C  s   |  j  d  S(   s'   Kill the currently executing Lua scripts   SCRIPT KILL(   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   script_kill  s    c         C  s   |  j  d |  S(   s=   Load a Lua ``script`` into the script cache. Returns the SHA.s   SCRIPT LOAD(   R   (   R   RS  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   script_load  s    c         C  s   t  |  |  S(   s  
        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.
        (   t   Script(   R   RS  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   register_script  s    N(   R   t
   __module__t   __doc__R6   R1   R   R&   RG   R   R   R   R   RA   R   R   R?   R   RY   R+   RC   R   R   Rv   Rr   Rt   Ru   R   R   R   t   classmethodR%   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  RV   R  R  R  R  Rf   R  R  R  R   R!  R"  R$  R%  R'  R+  R-  R.  R/  R   R2  RU   R8  R<  R?  RB  RE  RF  RH  RJ  t   __contains__RO  RU  R|   RX  R[  R]  R_  Ra  Rb  Rd  R"   Rg  Rk  Rm  Ro  Rq  Ru  Rx  R{  R}  R~  R  R  R  Rm   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  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.  R1  R3  R5  R7  R9  R:  R<  R>  R@  RB  RD  RF  RI  RK  RM  RQ  RV  RY  RZ  R[  R\  R]  R_  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     s  			






		3				:																																	

				
												
			
													!			
										
					
			
				C																																																	t   Redisc           B  sa   e  Z d  Z e e j i d   d 6d   d 6 Z e d
 d  Z d   Z	 d d  Z
 d	   Z RS(   s   
    Provides backwards compatibility with older versions of redis-py that
    changed arguments to some commands to be more Pythonic, sane, or by
    accident.
    c         C  s   |  d k r |  p d  S(   Ni    (   R%   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     R   R  c         C  s   |  d k r |  p d  S(   Ni    (   R%   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     R   R|  c         C  s   t  |  j |  j | |  S(   s_  
        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.
        (   t   PipelineR   R   (   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     s
    c         C  sC   t  | t j  r- | j | j d d } n  |  j d | | |  S(   s   
        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.
        i   i  R  (   R   R(   RL  RM  RN  R   (   R   Ro   RI   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR    s    i    c         C  s   |  j  d | | |  S(   s  
        Remove the first ``num`` occurrences of elements equal to ``value``
        from the list stored at ``name``.

        The ``num`` argument influences the operation in the following ways:
            num > 0: Remove elements equal to value moving from head to tail.
            num < 0: Remove elements equal to value moving from tail to head.
            num = 0: Remove all elements equal to value.
        R  (   R   (   R   Ro   RI   R,  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR    s    
c         O  s   g  } | rG t  |  d d k r1 t d   n  | j t |   n  x6 t |  D]( } | j | d  | j | d  qT W|  j d | |  S(   sp  
        NOTE: The order of arguments differs from that of the official ZADD
        command. For backwards compatability, this method accepts arguments
        in the form of name1, score1, name2, score2, while the official Redis
        documents expects score1, name1, score2, name2.

        If you're looking to use the standard syntax, consider using the
        StrictRedis class. See the API Reference section of the docs for more
        information.

        Set any number of element-name, score pairs to the key ``name``. Pairs
        can be specified in two ways:

        As *args, in the form of: name1, score1, name2, score2, ...
        or as **kwargs, in the form of: name1=score1, name2=score2, ...

        The following example would add four values to the 'my-key' key:
        redis.zadd('my-key', 'name1', 1.1, 'name2', 2.2, name3=3.3, name4=4.4)
        i   i    s2   ZADD requires an equal number of values and scoresi   R  (   Ri  R   R!   t   reversedR   RU   R   (   R   Ro   R#   R   R  R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR    s    N(   R   R`  Ra  R6   R   R   R   R%   R   R  R  R  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRd    s   
	
R   c           B  s   e  Z d  Z d Z d Z d e d  Z d   Z d   Z	 d   Z
 d	   Z d
   Z e d    Z d   Z d   Z e d d  Z d   Z d   Z d   Z d   Z d   Z e d d  Z e d  Z d d  Z RS(   s*  
    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.
    RP  t   pmessaget   unsubscribet   punsubscribec         C  s}   | |  _  | |  _ | |  _ d  |  _ | j d |  } z( | j |  _ | j |  _ | j |  _ Wd  | j	 |  X|  j
   d  S(   NR   (   R   R   t   ignore_subscribe_messagesR%   R   R   R   R   R   R   t   reset(   R   R   R   Rj  t   conn(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     s    				c         C  s&   y |  j    Wn t k
 r! n Xd  S(   N(   Rk  t	   Exception(   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __del__(  s    c         C  sX   |  j  rB |  j  j   |  j  j   |  j j |  j   d  |  _  n  i  |  _ i  |  _ d  S(   N(   R   R   t   clear_connect_callbacksR   R   R%   t   channelst   patterns(   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRk  1  s    		c         C  s   |  j    d  S(   N(   Rk  (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   close:  s    c         C  s   |  j  rm i  } xK t |  j   D]: \ } } |  j sO | j |  j |  j  } n  | | | <q W|  j |   n  |  j r i  } xK t |  j  D]: \ } } |  j s | j |  j |  j  } n  | | | <q W|  j |   n  d S(   sB   Re-subscribe to any channels and patterns previously subscribed toN(	   Rp  R   R   t   decodeR   R   t	   subscribeRq  t
   psubscribe(   R   R   Rp  RL   RM   Rq  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   on_connect=  s    				c         C  sk   |  j  r3 t | t  r3 | j |  j |  j  } n4 |  j  rg t | t  rg | j |  j |  j  } n  | S(   sg   
        Encode the value so that it's identical to what we'll
        read off the connection
        (   R   R   R   Rs  R   R   R   t   encode(   R   RI   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRw  Q  s
    c         C  s   t  |  j p |  j  S(   s@   Indicates if there are subscriptions to any channels or patterns(   R   Rp  Rq  (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt
   subscribed\  s    c         O  sc   |  j  d k r@ |  j j d |  j  |  _  |  j  j |  j  n  |  j  } |  j | | j |  d S(   s#   Execute a publish/subscribe commandR   N(	   R   R%   R   R   R   t   register_connect_callbackRv  t   _executeR   (   R   R#   R   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   a  s    		c         G  sh   y | |   SWnS t  t f k
 rc } | j   | j rO t | t  rO   n  | j   | |   SXd  S(   N(   R   R   R   R   R   t   connect(   R   R   R   R#   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRz  s  s    

i    c         C  s:   |  j  } | r' | j d |  r' d S|  j | | j  S(   s3   Parse the response from a publish/subscribe commandR   N(   R   t   can_readR%   Rz  R   (   R   t   blockR   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     s    	c         O  s   | r  t  | d | d  } n  i  } | j t j t |  j |    x- t |  D] \ } } | | |  j |  <qU W|  j d t |   } |  j	 j |  | S(   sE  
        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()``.
        i    i   t
   PSUBSCRIBE(
   R$   R2   R,   R-   R   Rw  R   R   R   Rq  (   R   R#   R   t   new_patternsR  t   handlert   ret_val(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRu    s    "c         G  s0   | r  t  | d | d  } n  |  j d |  S(   si   
        Unsubscribe from the supplied patterns. If empy, unsubscribe from
        all patterns.
        i    i   t   PUNSUBSCRIBE(   R$   R   (   R   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRi    s    c         O  s   | r  t  | d | d  } n  i  } | j t j t |  j |    x- t |  D] \ } } | | |  j |  <qU W|  j d t |   } |  j	 j |  | S(   sR  
        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()``.
        i    i   t	   SUBSCRIBE(
   R$   R2   R,   R-   R   Rw  R   R   R   Rp  (   R   R#   R   t   new_channelsRO  R  R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRt    s    "c         G  s0   | r  t  | d | d  } n  |  j d |  S(   si   
        Unsubscribe from the supplied channels. If empty, unsubscribe from
        all channels
        i    i   t   UNSUBSCRIBE(   R$   R   (   R   R#   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRh    s    c         c  sC   x< |  j  r> |  j |  j d t   } | d k	 r | Vq q Wd S(   sB   Listen for messages on channels this client has been subscribed toR}  N(   Rx  t   handle_messageR   R   R%   (   R   R*   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   listen  s    c         C  s2   |  j  d t d |  } | r. |  j | |  Sd S(   s   
        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.
        R}  R   N(   R   R   R  R%   (   R   Rj  R   R*   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   get_message  s    c         C  sW  t  | d  } | d k rM i | d 6| d d 6| d d 6| d d	 6} n* i | d 6d d 6| d d 6| d d	 6} | |  j k r d } | d
 k r |  j } n	 |  j } y | | d =Wq t k
 r q Xn  | |  j k r@d } | d k r|  j j | d d  } n |  j j | d d  } | rS| |  d Sn | sO|  j rSd S| S(   s   
        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.
        i    Rg  R   i   R  i   RO  i   R  Ri  N(	   R   R%   t   UNSUBSCRIBE_MESSAGE_TYPESRq  Rp  RW  t   PUBLISH_MESSAGE_TYPESR|   Rj  (   R   R*   Rj  t   message_typeRP  t   subscribed_dictR  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR    s@    	
c         C  s   x8 t  |  j  D]' \ } } | d  k r t d   q q Wx8 t  |  j  D]' \ } } | d  k rK t d   qK qK Wt |  |  } | j   | S(   Ns'   Channel: '%s' has no handler registereds'   Pattern: '%s' has no handler registered(   R   Rp  R%   R   Rq  t   PubSubWorkerThreadR5  (   R   t
   sleep_timeRO  R  R  t   thread(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   run_in_thread	  s    
(   RP  Rg  (   Rh  Ri  N(   R   R`  Ra  R  R  R%   R   R   Rn  Rk  Rr  Rv  Rw  t   propertyRx  R   Rz  R   R   Ru  Ri  Rt  Rh  R  R  R  R  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR     s,   																4R  c           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s2   t  t |   j   | |  _ | |  _ t |  _ d  S(   N(   t   superR  R   R   R  R   t   _running(   R   R   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   	  s    		c         C  se   |  j  r d  St |  _  |  j } |  j } x# | j rM | j d t d |  q+ W| j   t |  _  d  S(   NRj  R   (   R  R   R   R  Rx  R  Rr  R   (   R   R   R  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   run!	  s    				
c         C  s   |  j  j   |  j  j   d  S(   N(   R   Rh  Ri  (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   stop-	  s    (   R   R`  R   R  R  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR  	  s   		t   BasePipelinec           B  s   e  Z d  Z e d  Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z RS(   s_  
    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.
    t   DISCARDt   EXECt   UNWATCHc         C  sD   | |  _  d  |  _ | |  _ | |  _ | |  _ t |  _ |  j   d  S(   N(	   R   R%   R   R   R   R   R   t   watchingRk  (   R   R   R   R   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   J	  s    						c         C  s   |  S(   N(    (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt	   __enter__U	  s    c         C  s   |  j    d  S(   N(   Rk  (   R   t   exc_typet	   exc_valuet	   traceback(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __exit__X	  s    c         C  s&   y |  j    Wn t k
 r! n Xd  S(   N(   Rk  Rm  (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRn  [	  s    c         C  s   t  |  j  S(   N(   Ri  t   command_stack(   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __len__a	  s    c         C  s   g  |  _  t   |  _ |  j rl |  j rl y! |  j j d  |  j j   Wql t k
 rh |  j j   ql Xn  t	 |  _ t	 |  _
 |  j r |  j j |  j  d  |  _ n  d  S(   NR  (   R  Rm   t   scriptsR  R   R   R   R   R   R   t   explicit_transactionR   R   R%   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRk  d	  s    				c         C  s=   |  j  r t d   n  |  j r0 t d   n  t |  _  d S(   s   
        Start a transactional block of the pipeline after WATCH commands
        are issued. End the transactional block with `execute`.
        s"   Cannot issue nested calls to MULTIs:   Commands without an initial WATCH have already been issuedN(   R  R   R  R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   multi{	  s
    		c         O  sC   |  j  s | d d k r3 |  j r3 |  j | |   S|  j | |   S(   Ni    t   WATCH(   R  R  t   immediate_execute_commandt   pipeline_execute_command(   R   R#   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   	  s    
c         O  s  | d } |  j  } | s= |  j j | |  j  } | |  _  n  y$ | j |   |  j | | |  SWn t t f k
 r } | j   | j	 r t
 | t  r   n  y- |  j s | j |   |  j | | |  SWq t k
 r | j   |  j     q Xn Xd S(   s   
        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.
        i    N(   R   R   R   R   R   R   R   R   R   R   R   R  Rk  (   R   R#   R~   R   Rl  R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR  	  s*    
	
	

c         O  s   |  j  j | | f  |  S(   sr  
        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  RU   (   R   R#   R~   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR  	  s    c         C  s  t  d	 i  f g | d
 i  f g  } | j g  | D] \ } } | ^ q1  } | j |  g  } y |  j | d  Wn. t k
 r | j d t j   d f  n Xx t |  D]r \ }	 }
 y |  j | d  Wq t k
 r"t j   d } |  j	 | |	 d |
 d  | j |	 | f  q Xq Wy |  j | d  } WnQ t
 k
 r|  j rf|  j d  n  | r}| d d  n  t j   d  n X| d  k rt d   n  x$ | D] \ }	 } | j |	 |  qWt |  t |  k r|  j j   t d   n  | r |  j | |  n  g  } xz t | |  D]i \ } } t | t  s| \ } } | d } | |  j k r|  j | | |  } qn  | j |  q6W| S(   Nt   MULTIR  t   _i    i   R  s   Watched variable changed.s6   Wrong number of response items from pipeline execution(   R  (   R  (   R   t   pack_commandst   send_packed_commandR   R   RU   t   syst   exc_infot	   enumeratet   annotate_exceptionR   R  R  R%   R   t   insertRi  R   R   t   raise_first_errorR	   R   Rm  R   (   R   R   t   commandst   raise_on_errort   cmdsR#   R  t   all_cmdsR   R   R   R  R*   R   R  R   t   cmdR~   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   _execute_transaction	  sR    $(!	
c   	      C  s   | j  g  | D] \ } } | ^ q  } | j |  g  } xc | D][ \ } } y$ | j |  j | | d |   WqB t k
 r | j t j   d  qB XqB W| r |  j | |  n  | S(   Ni    i   (   R  R  RU   R   R   R  R  R  (	   R   R   R  R  R#   R  R  R*   R~   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   _execute_pipeline	  s    (c         C  sX   xQ t  |  D]C \ } } t | t  r |  j | | d | | d  |  q q Wd  S(   Ni   i    (   R  R   R   R  (   R   R  R*   R   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR  

  s    c         C  s_   t  d  j t t  |   } t d  | | t  | j d  f } | f | j d | _ d  S(   NR   s.   Command # %d (%s) of pipeline caused error: %si    i   (   R   R   R   R   R#   (   R   t	   exceptionR  R   R  t   msg(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR  
  s    	c         K  sO   t  j |  | | |  } | |  j k r3 t |  _ n | d k rK t |  _ n  | S(   NR  (   R   R   t   UNWATCH_COMMANDSR   R  R   (   R   R   R   R~   Rn   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   
  s    c         C  s   t  |  j  } |  j } g  | D] } | j ^ q } | d d | i d d 6 } t |  s xK t | |  D]7 \ } } | sl | d d | j i d d 6 | _ ql ql Wn  d  S(   Nt   SCRIPTRI  t   parset   LOAD(   R}   R  R  RX  t   allR	   RS  (   R   R  t	   immediatet   st   shasRJ  t   exist(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   load_scripts
  s    	c         C  s  |  j  } | s g  S|  j r) |  j   n  |  j s; |  j rG |  j } n	 |  j } |  j } | s |  j j	 d |  j
  } | |  _ n  z y | | | |  SWng t t f k
 r} | j   | j r t | t  r   n  |  j r t d   n  | | | |  SXWd |  j   Xd S(   s0   Execute all the commands in the current pipelineR  s<   A ConnectionError occured on while watching one or more keysN(   R  R  R  R   R  R  R  R   R   R   R   R   R   R   R   R   R  R   Rk  (   R   R  t   stackR   Rl  R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   -
  s0    				 
	c         G  s(   |  j  r t d   n  |  j d |  S(   s$   Watches the values at keys ``names``s"   Cannot issue a WATCH after a MULTIR  (   R  R   R   (   R   RD  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   U
  s    	c         C  s   |  j  r |  j d  p t S(   s'   Unwatches all previously specified keysR  (   R  R   R   (   R   (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR  [
  s    c         C  sE   | j  s1 |  j d d | j i d d 6 | _  n  |  j j |  d S(   s8   Make sure scripts are loaded prior to pipeline executionR  R  R  N(   RX  R  RS  R  t   add(   R   RS  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   script_load_for_pipeline_
  s
    	(   R  R  R  (   R   R`  Ra  Rm   R  R   R  R  Rn  R  Rk  R  R   R  R  R  R  R  R  R   R  R   R   R   R  R  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR  5	  s,   									 		=						(		R   c           B  s   e  Z d  Z RS(   s"   Pipeline for the StrictRedis class(   R   R`  Ra  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   j
  s   Re  c           B  s   e  Z d  Z RS(   s   Pipeline for the Redis class(   R   R`  Ra  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyRe  o
  s   R^  c           B  s)   e  Z d  Z d   Z g  g  d d  Z RS(   s?   An executable Lua script object returned by ``register_script``c         C  s   | |  _  | |  _ d |  _ d  S(   NR   (   t   registered_clientRS  RX  (   R   R  RS  (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR   w
  s    		c         C  s   | d k r |  j } n  t |  t |  } t | t  rM | j |   n  y  | j |  j t |  |  SWn? t	 k
 r | j
 |  j  |  _ | j |  j t |  |  SXd S(   s1   Execute the script, passing any required ``args``N(   R%   R  R   R   R  R  RY  RX  Ri  R   R]  RS  (   R   R"   R#   t   client(    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   __call__|
  s     N(   R   R`  Ra  R   R%   R  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyR^  t
  s   	(O   t
   __future__R    t	   itertoolsR   R(   R  R   R   t	   threadingRQ  t   redis._compatR   R   R   R   R   R   R   R	   R
   R   R   R   t   redis.connectionR   R   R   R   t
   redis.lockR   R   t   redis.exceptionsR   R   R   R   R   R   R   R   R   t	   SYM_EMPTYR$   R+   R1   R6   R?   RC   RY   R&   Rl   Rq   Rr   Rt   Ru   Rv   Rx   Rk   R   R   RA   R   R   R   R   R   R   R   R   R  R   Rd  R   t   ThreadR  R  R   Re  R^  (    (    (    s.   /tmp/pip-unpacked-wheel-5e_doG/redis/client.pyt   <module>   s   R"@							!
																			      T  6