Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/aioredis/commands/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/aioredis/commands/__pycache__/generic.cpython-35.pyc



�D�Z�+�@s9ddlmZmZmZmZGdd�d�ZdS)�)�wait_convert�wait_ok�_NOTSET�	_ScanIterc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zde	d
d�Z
dddddd�Zdddddd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zde	d&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/d/d0d1�Zd2d/d3d/d4d5�Zd6d/d7d/d3d/d8d/d9dd:d/d;d<�Zd=d>�Zd?d@�ZdAdB�ZdCdD�ZdEdF�Z d/S)G�GenericCommandsMixinz]Generic commands mixin.

    For commands details see: http://redis.io/commands/#generic
    cGs"|jd||�}t|t�S)z
Delete a key.sDEL)�executer�int)�self�key�keys�fut�r
�J/opt/alt/python35/lib/python3.5/site-packages/aioredis/commands/generic.py�delete
szGenericCommandsMixin.deletecCs|jd|�S)zDump a key.sDUMP)r)r	r
r
r
r�dumpszGenericCommandsMixin.dumpcGs|jd||�S)z�Check if key(s) exists.

        .. versionchanged:: v0.2.9
           Accept multiple keys; **return** type **changed** from bool to int.
        sEXISTS)r)r	r
rr
r
r�existsszGenericCommandsMixin.existscCsot|t�r)|j|t|d��St|t�sMtdj|���|jd||�}t|t�S)z�Set a timeout on key.

        if timeout is float it will be multiplied by 1000
        coerced to int and passed to `pexpire` method.

        Otherwise raises TypeError if timeout argument is not int.
        i�z&timeout argument must be int, not {!r}sEXPIRE)	�
isinstance�float�pexpirer�	TypeError�formatrr�bool)r	r
�timeoutrr
r
r�expireszGenericCommandsMixin.expirecCsot|t�r)|j|t|d��St|t�sMtdj|���|jd||�}t|t�S)z�Set expire timestamp on a key.

        if timeout is float it will be multiplied by 1000
        coerced to int and passed to `pexpireat` method.

        Otherwise raises TypeError if timestamp argument is not int.
        i�z(timestamp argument must be int, not {!r}sEXPIREAT)	rr�	pexpireatrrrrrr)r	r
�	timestamprr
r
r�expireat+s	zGenericCommandsMixin.expireat�encodingcCs|jd|d|�S)z"Returns all keys matching pattern.sKEYSr)r)r	�patternrr
r
rr;szGenericCommandsMixin.keys�copyF�replacec
Cs�t|t�std��t|t�s6td��t|t�sQtd��|sctd��|dkr{td��|dkr�td��g}|r�|jd�|r�|jd	�|jd
||||||�}	t|	�S)z?Atomically transfer a key from a Redis instance to another one.zhost argument must be strztimeout argument must be intzdest_db argument must be intzGot empty hostrzdest_db must be greater equal 0ztimeout must be greater equal 0sCOPYsREPLACEsMIGRATE)r�strrr�
ValueError�appendrr)
r	�host�portr
�dest_dbrrr �flagsrr
r
r�migrate?s(

zGenericCommandsMixin.migratec
Cs7t|t�std��t|t�s6td��t|t�sQtd��t|ttf�srtd��|s�td��|dkr�td��|dkr�td��|s�td	��g}|r�|jd
�|r�|jd�|jd�|j|�|j	d
||d|||�}	t
|	�S)z�Atomically transfer keys from one Redis instance to another one.

        Keys argument must be list/tuple of keys to migrate.
        zhost argument must be strztimeout argument must be intzdest_db argument must be intz#keys argument must be list or tuplezGot empty hostrzdest_db must be greater equal 0ztimeout must be greater equal 0zkeys must not be emptysCOPYsREPLACEsKEYSsMIGRATE�)rr!rr�list�tupler"r#�extendrr)
r	r$r%rr&rrr r'rr
r
r�migrate_keysXs4



z!GenericCommandsMixin.migrate_keyscCsgt|t�s$tdj|���|dkrEtdj|���|jd||�}t|t�S)z�Move key from currently selected database to specified destination.

        :raises TypeError: if db is not int
        :raises ValueError: if db is less then 0
        z!db argument must be int, not {!r}rz)db argument must be not less then 0, {!r}sMOVE)rrrrr"rrr)r	r
Zdbrr
r
r�movezs	zGenericCommandsMixin.movecCs|jdd|�S)zsReturns the number of references of the value associated
        with the specified key (OBJECT REFCOUNT).
        sOBJECTsREFCOUNT)r)r	r
r
r
r�object_refcount�sz$GenericCommandsMixin.object_refcountcCs|jdd|�S)z�Returns the kind of internal representation used in order
        to store the value associated with a key (OBJECT ENCODING).
        sOBJECTsENCODING)r)r	r
r
r
r�object_encoding�sz$GenericCommandsMixin.object_encodingcCs|jdd|�S)zReturns the number of seconds since the object is not requested
        by read or write operations (OBJECT IDLETIME).
        sOBJECTsIDLETIME)r)r	r
r
r
r�object_idletime�sz$GenericCommandsMixin.object_idletimecCs|jd|�}t|t�S)z#Remove the existing timeout on key.sPERSIST)rrr)r	r
rr
r
r�persist�szGenericCommandsMixin.persistcCsFt|t�s$tdj|���|jd||�}t|t�S)z]Set a milliseconds timeout on key.

        :raises TypeError: if timeout is not int
        z&timeout argument must be int, not {!r}sPEXPIRE)rrrrrrr)r	r
rrr
r
rr�s
	zGenericCommandsMixin.pexpirecCsFt|t�s$tdj|���|jd||�}t|t�S)zrSet expire timestamp on key, timestamp in milliseconds.

        :raises TypeError: if timeout is not int
        z(timestamp argument must be int, not {!r}s	PEXPIREAT)rrrrrrr)r	r
rrr
r
rr�s
	zGenericCommandsMixin.pexpireatcCs|jd|�S)z�Returns time-to-live for a key, in milliseconds.

        Special return values (starting with Redis 2.8):

        * command returns -2 if the key does not exist.
        * command returns -1 if the key exists but has no associated expire.
        sPTTL)r)r	r
r
r
r�pttl�szGenericCommandsMixin.pttlcCs|jdd|�S)z9Return a random key from the currently selected database.s	RANDOMKEYr)r)r	rr
r
r�	randomkey�szGenericCommandsMixin.randomkeycCs7||krtd��|jd||�}t|�S)zMRenames key to newkey.

        :raises ValueError: if key == newkey
        zkey and newkey are the samesRENAME)r"rr)r	r
�newkeyrr
r
r�rename�szGenericCommandsMixin.renamecCs:||krtd��|jd||�}t|t�S)zkRenames key to newkey only if newkey does not exist.

        :raises ValueError: if key == newkey
        zkey and newkey are the samesRENAMENX)r"rrr)r	r
r5rr
r
r�renamenx�szGenericCommandsMixin.renamenxcCs|jd|||�S)z@Creates a key associated with a value that is obtained via DUMP.sRESTORE)r)r	r
�ttl�valuer
r
r�restore�szGenericCommandsMixin.restorerNcCsfg}|dk	r"|d|g7}|dk	r>|d|g7}|jd||�}t|dd��S)a"Incrementally iterate the keys space.

        Usage example:

        >>> match = 'something*'
        >>> cur = b'0'
        >>> while cur:
        ...     cur, keys = await redis.scan(cur, match=match)
        ...     for key in keys:
        ...         print('Matched:', key)

        NsMATCHsCOUNTsSCANcSst|d�|dfS)Nr�)r)�or
r
r�<lambda>�sz+GenericCommandsMixin.scan.<locals>.<lambda>)rr)r	Zcursor�match�count�argsrr
r
r�scan�s
zGenericCommandsMixin.scanr>r?cst���fdd��S)z�Incrementally iterate the keys space using async for.

        Usage example:

        >>> async for key in redis.iscan(match='something*'):
        ...     print('Matched:', key)

        cs�j|d�d��S)Nr>r?)rA)�cur)r?r>r	r
rr=�sz,GenericCommandsMixin.iscan.<locals>.<lambda>)r)r	r>r?r
)r?r>r	r�iscan�s	zGenericCommandsMixin.iscan�by�offset�asc�alpha�storec
Gs�g}	|dk	r"|	d|g7}	|dk	rM|dk	rM|	d||g7}	|rs|	tdd�|D�g�7}	|dk	r�|	|dkr�dp�dg7}	|r�|	d	g7}	|dk	r�|	d
|g7}	|jd||	�S)z/Sort the elements in a list, set or sorted set.NsBYsLIMITcss|]}d|gVqdS)sGETNr
)�.0rr
r
r�	<genexpr>
sz,GenericCommandsMixin.sort.<locals>.<genexpr>TsASCsDESCsALPHAsSTOREsSORT)�sumr)
r	r
rDrEr?rFrGrHZget_patternsr@r
r
r�sorts 
zGenericCommandsMixin.sortcGs|jd||�S)zhAlters the last access time of a key(s).

        Returns the number of keys that were touched.
        sTOUCH)r)r	r
rr
r
r�touchszGenericCommandsMixin.touchcCs|jd|�S)z�Returns time-to-live for a key, in seconds.

        Special return values (starting with Redis 2.8):
        * command returns -2 if the key does not exist.
        * command returns -1 if the key exists but has no associated expire.
        sTTL)r)r	r
r
r
rr8s
zGenericCommandsMixin.ttlcCs|jd|�S)zMReturns the string representation of the value's type stored at key.
        sTYPE)r)r	r
r
r
r�type&szGenericCommandsMixin.typecGst|jd||�t�S)z.Delete a key asynchronously in another thread.sUNLINK)rrr)r	r
rr
r
r�unlink,szGenericCommandsMixin.unlinkcCs|jd||�S)z~Wait for the synchronous replication of all the write
        commands sent in the context of the current connection.
        sWAIT)r)r	Z	numslavesrr
r
r�wait0szGenericCommandsMixin.wait)!�__name__�
__module__�__qualname__�__doc__rrrrrrrr(r-r.r/r0r1r2rrr3r4r6r7r:rArCrLrMr8rNrOrPr
r
r
rrsB!


rN)Z
aioredis.utilrrrrrr
r
r
r�<module>s"