HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/redismod.cpython-310.pyc
o

;jjB�@s�dZddlZzddlZdZWneydZYnwdZdd�Zdcdd	�Zddd
d�Z	dcdd
�Z
dcdd�Zdedd�Zdcdd�Z
dcdd�Zdd�Zdcdd�Zdcdd�Zdcdd�Zdcdd �Zdcd!d"�Zdcd#d$�Zd%d&�Zdcd'd(�Zdcd)d*�Zdcd+d,�Zdfd.d/�Z	dgd1d2�Zdcd3d4�Zd5d6�Zd7d8�Zdcd9d:�Zdcd;d<�Z dcd=d>�Z!	dhd?d@�Z"dcdAdB�Z#dedCdD�Z$dcdEdF�Z%dcdGdH�Z&dcdIdJ�Z'dcdKdL�Z(dcdMdN�Z)dcdOdP�Z*dcdQdR�Z+dcdSdT�Z,	didUdV�Z-dcdWdX�Z.dcdYdZ�Z/dcd[d\�Z0dcd]d^�Z1ddd_d`�Z2dddadb�Z3dS)jaN
Module to provide redis functionality to Salt

.. versionadded:: 2014.7.0

:configuration: This module requires the redis python module and uses the
    following defaults which may be overridden in the minion configuration:

.. code-block:: yaml

    redis.host: 'salt'
    redis.port: 6379
    redis.db: 0
    redis.password: None
�NTF�rediscCstrtSdS)zC
    Only load this module if redis python module is installed
    )FzUThe redis execution module failed to load: the redis python library is not available.)�	HAS_REDIS�__virtualname__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/redismod.py�__virtual__srcCsX|stdd�}|stdd�}|durtdd�}|s"tdd�}tj||||dd�S)	�1
    Returns an instance of the redis client
    �
config.optionz
redis.hostz
redis.portNzredis.dbzredis.passwordT)�decode_responses�Z__salt__rZStrictRedis��host�port�db�passwordrrr�_connect+srcCsR|durtddd�}|durtddd�}|dur tdd�}tj|||dd	�S)
rNr	zredis_sentinel.hostZ	localhostzredis_sentinel.portigzredis_sentinel.passwordT)rr
r�r
rrrrr�	_sconnect>srcC�t||||�}|��S)z�
    Asynchronously rewrite the append-only file

    CLI Example:

    .. code-block:: bash

        salt '*' redis.bgrewriteaof
    )r�bgrewriteaof�r
rrr�serverrrrrL�
rcCr)z|
    Asynchronously save the dataset to disk

    CLI Example:

    .. code-block:: bash

        salt '*' redis.bgsave
    )r�bgsaverrrrrZrr�*cC�t||||�}|�|�S)z�
    Get redis server configuration values

    CLI Example:

    .. code-block:: bash

        salt '*' redis.config_get
        salt '*' redis.config_get port
    )r�
config_get��patternr
rrrrrrrrh�
rcC�t||||�}|�||�S)z�
    Set redis server configuration values

    CLI Example:

    .. code-block:: bash

        salt '*' redis.config_set masterauth luv_kittens
    )r�
config_set)�name�valuer
rrrrrrrr!w�
r!cCr)z�
    Return the number of keys in the selected database

    CLI Example:

    .. code-block:: bash

        salt '*' redis.dbsize
    )r�dbsizerrrrr%�rr%cOs:i}dD]}||vr||||<qtdi|��}|j|�S)z�
    Deletes the keys from redis, returns number of keys deleted

    CLI Example:

    .. code-block:: bash

        salt '*' redis.delete foo
    rNr)r�delete)�keysZconnection_argsZ	conn_args�argrrrrr&�s�
r&cCr)z
    Return true if the key exists in redis

    CLI Example:

    .. code-block:: bash

        salt '*' redis.exists foo
    )r�exists��keyr
rrrrrrrr)��

r)cCr )z
    Set a keys time to live in seconds

    CLI Example:

    .. code-block:: bash

        salt '*' redis.expire foo 300
    )r�expire)r+�secondsr
rrrrrrrr-�r$r-cCr )z�
    Set a keys expire at given UNIX time

    CLI Example:

    .. code-block:: bash

        salt '*' redis.expireat foo 1400000000
    )r�expireat)r+�	timestampr
rrrrrrrr/�r$r/cCr)zy
    Remove all keys from all databases

    CLI Example:

    .. code-block:: bash

        salt '*' redis.flushall
    )r�flushallrrrrr1�rr1cCr)z�
    Remove all keys from the selected database

    CLI Example:

    .. code-block:: bash

        salt '*' redis.flushdb
    )r�flushdbrrrrr2�rr2cCr)zm
    Get redis key value

    CLI Example:

    .. code-block:: bash

        salt '*' redis.get_key foo
    )r�getr*rrr�get_key�r,r4cO�P|�dd�}|�dd�}|�dd�}|�dd�}t||||�}|j|g|�R�S)z�
    Delete one of more hash fields.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hdel foo_hash bar_field1 bar_field2
    r
Nrrr)r3r�hdel�r+�fields�optionsr
r�databaserrrrrr6��r6cCr )z�
    Determine if a hash fields exists.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hexists foo_hash bar_field
    )r�hexists�r+�fieldr
rrrrrrrr<sr<cCr )z�
    Get specific field value from a redis hash, returns dict

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hget foo_hash bar_field
    )r�hgetr=rrrr?r$r?cCr)z�
    Get all fields and values from a redis hash, returns dict

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hgetall foo_hash
    )r�hgetallr*rrrr@-r,r@�cC�t||||�}|j|||d�S)z�
    Increment the integer value of a hash field by the given number.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hincrby foo_hash bar_field 5
    ��amount)r�hincrby�r+r>Z	incrementr
rrrrrrrrE;srE��?cCrB)z�
    Increment the float value of a hash field by the given number.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hincrbyfloat foo_hash bar_field 5.17
    rC)r�hincrbyfloatrFrrrrHKsrHcCr)z�
    Returns number of fields of a hash.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hlen foo_hash
    )r�hlenr*rrrrI]�
rIcOr5)z�
    Returns the values of all the given hash fields.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hmget foo_hash bar_field1 bar_field2
    r
Nrrr)r3r�hmgetr7rrrrKmr;rKcKsZ|�dd�}|�dd�}|�dd�}|�dd�}t||||�}|�|tjjjdi|���S)z�
    Sets multiple hash fields to multiple values.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hmset foo_hash bar_field1=bar_value1 bar_field2=bar_value2
    r
Nrrrr)�popr�hmset�salt�utils�argsZclean_kwargs)r+Z
fieldsvalsr
rr:rrrrrrM�srMcC�t||||�}|�|||�S)z�
    Set the value of a hash field.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hset foo_hash bar_field bar_value
    )r�hset�r+r>r#r
rrrrrrrrR��rRcCrQ)z�
    Set the value of a hash field only if the field does not exist.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hsetnx foo_hash bar_field bar_value
    )r�hsetnxrSrrrrU�rTrUcCr)z�
    Return all the values in a hash.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hvals foo_hash bar_field1 bar_value1
    )r�hvalsr*rrrrV�rJrVc	Cs t||||�}|j||||d�S)z�
    Incrementally iterate hash fields and associated values.

    .. versionadded:: 2017.7.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.hscan foo_hash match='field_prefix_*' count=1
    )�cursor�match�count)r�hscan)	r+rWrXrYr
rrrrrrrrZ�srZcCr)z�
    Get information and statistics about the server

    CLI Example:

    .. code-block:: bash

        salt '*' redis.info
    )r�inforrrrr[�rr[cCr)z�
    Get redis keys, supports glob style patterns

    CLI Example:

    .. code-block:: bash

        salt '*' redis.keys
        salt '*' redis.keys test*
    )rr'rrrrr'�rr'cCr)zi
    Get redis key type

    CLI Example:

    .. code-block:: bash

        salt '*' redis.type foo
    )r�typer*rrr�key_type�r,r]cCst||||�}t|�����S)z�
    Get the UNIX time in seconds of the last successful save to disk

    CLI Example:

    .. code-block:: bash

        salt '*' redis.lastsave
    )r�int�lastsaver0rrrrr_s
r_cCr)z}
    Get the length of a list in Redis

    CLI Example:

    .. code-block:: bash

        salt '*' redis.llen foo_list
    )r�llenr*rrrr`r,r`cCrQ)z�
    Get a range of values from a list in Redis

    CLI Example:

    .. code-block:: bash

        salt '*' redis.lrange foo_list 0 10
    )r�lrange�r+�start�stopr
rrrrrrrra!�
racCs0t||||�}z|��WStjyYdSw)z�
    Ping the server, returns False on connection errors

    CLI Example:

    .. code-block:: bash

        salt '*' redis.ping
    F)r�pingr�ConnectionErrorrrrrrf/s

�rfcCr)zy
    Synchronously save the dataset to disk

    CLI Example:

    .. code-block:: bash

        salt '*' redis.save
    )r�saverrrrrh@rrhcCr )zq
    Set redis key value

    CLI Example:

    .. code-block:: bash

        salt '*' redis.set_key foo bar
    )r�set)r+r#r
rrrrrrr�set_keyNr$rjcCs`t||||�}z|��WntjyYdSw|��z|��WdStjy/YdSw)z�
    Synchronously save the dataset to disk and then shut down the server

    CLI Example:

    .. code-block:: bash

        salt '*' redis.shutdown
    FT)rrfrrg�shutdownrrrrrk\s
�
��rkcCs&|r|sd}t||||�}|�||�S)aV
    Make the server a slave of another instance, or promote it as master

    CLI Example:

    .. code-block:: bash

        # Become slave of redis-n01.example.com:6379
        salt '*' redis.slaveof redis-n01.example.com 6379
        salt '*' redis.slaveof redis-n01.example.com
        # Become master
        salt '*' redis.slaveof
    i�)r�slaveof)�master_host�master_portr
rrrrrrrrlvsrlcCst||||�}t|�|��S)zy
    Get members in a Redis set

    CLI Example:

    .. code-block:: bash

        salt '*' redis.smembers foo_set
    )r�list�smembersr*rrrrp�rerpcCst||||�}|��dS)z�
    Return the current server UNIX time in seconds

    CLI Example:

    .. code-block:: bash

        salt '*' redis.time
    r)r�timerrrrrq�r$rqcCr)z�
    Get the length of a sorted set in Redis

    CLI Example:

    .. code-block:: bash

        salt '*' redis.zcard foo_sorted
    )r�zcardr*rrrrr�r,rrcCrQ)z�
    Get a range of values from a sorted set in Redis by index

    CLI Example:

    .. code-block:: bash

        salt '*' redis.zrange foo_sorted 0 10
    )r�zrangerbrrrrs�rerscCs(t|||�}|�|�}tttd|���S)z�
    Get ip for sentinel master

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.sentinel_get_master_ip 'mymaster'
    �rmrn)rZ sentinel_get_master_addr_by_name�dictro�zip)Zmasterr
rrr�retrrr�sentinel_get_master_ip�s
rxcCs@t|||d�}|��}|�dd�|�dd�f}tttd|���S)z�
    Get host information about slave

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' redis.get_master_ip
    rrm�rnrt)rr[r3rurorv)r
rrrZsrv_inforwrrr�
get_master_ip�srz)NNNN)NNN)rNNNN)rANNNN)rGNNNN)rNNNNNN)NNNNNN)4�__doc__Zsalt.utils.argsrNrr�ImportErrorrrrrrrrr!r%r&r)r-r/r1r2r4r6r<r?r@rErHrIrKrMrRrUrVrZr[r'r]r_r`rarfrhrjrkrlrprqrrrsrxrzrrrr�<module>sr�

















�




�










�