HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/memcached.cpython-310.pyc
o

�N�g0�@s�dZddlZddlmZmZzddlZdZWney!dZYnwdZdZ	dZ
dZe�e
�Zdd	iZd
d�Zddd
�Zdd�Ze
efdd�Zdd�ZdS)a�
Utilities for working with memcache

:depends:  - python-memcached

This library sets up a connection object for memcache, using the configuration
passed into the get_conn() function. Normally, this is __opts__. Optionally,
a profile or specific host and port may be passed in. If neither profile nor
host and port are provided, the defaults of '`127.0.0.`` and ``11211`` are
used. The following configurations are both valid:

.. code-block:: yaml

    # No profile name
    memcached.host: 127.0.0.1
    memcached.port: 11211

    # One or more profiles defined
    my_memcached_config:
      memcached.host: 127.0.0.1
      memcached.port: 11211

Once configured, the get_conn() function is passed a set of opts, and,
optionally, the name of a profile to be used.

.. code-block:: python

    import salt.utils.memcached_utils.py
    conn = salt.utils.memcached_utils.get_conn(__opts__,
                                              profile='my_memcached_config')

It should be noted that some usages of memcached may require a profile to be
specified, rather than top-level configurations. This being the case, it is
better to always use a named configuration profile, as shown above.
�N)�CommandExecutionError�SaltInvocationErrorTFz	127.0.0.1i�+�set_�setcCstrdSdS)z4
    Only load if python-memcached is installed
    TF)�HAS_LIBS�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/memcached.py�__virtual__>sr	cCs�|r|s8|�di�}|�di�}i}|�|�|�|�|�|�|r*|�|i�}n|}|�dt�}|�dt�}t|���sBtd��trOt�	|�d|��g�St
d��)z6
    Return a conn object for accessing memcached
    ZpillarZmasterzmemcached.hostzmemcached.portzport must be an integer�:z=(unable to import memcache, module most likely not installed))�get�update�DEFAULT_HOST�DEFAULT_PORT�str�isdigitrr�memcacheZClientr)�optsZprofile�host�portZopts_pillarZopts_masterZopts_mergedZconfrrr�get_connEs&


�rcCs|��}|s
td��|S)z�
    Helper function to check the stats data passed into it, and raise an
    exception if none are returned. Otherwise, the stats are returned.
    z*memcached server is down or does not exist)Z	get_statsr)�connZstatsrrr�_check_statsesrcCs<t|t�s	td��t|t�std��t|�|�||||�S)zP
    Set a key on the memcached server, overwriting the value if it exists.
    z'time' must be an integerz%'min_compress_len' must be an integer)�
isinstance�intrrr)r�key�value�timeZmin_compress_lenrrrrps

cCst|�|�|�S)z"
    Retrieve value for a key
    )rr)rrrrrr~s
r)NNN)�__doc__�loggingZsalt.exceptionsrrrr�ImportErrorr
rZDEFAULT_TIMEZDEFAULT_MIN_COMPRESS_LEN�	getLogger�__name__�logZ__func_alias__r	rrrrrrrr�<module>s*$�

 
�