HEX
Server: LiteSpeed
System: Linux cpir1.prohostdns.com 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP Thu May 7 23:17:13 UTC 2026 x86_64
User: pelakir (2976)
PHP: 8.2.31
Disabled: exec, shell_exec, system, passthru, proc_open, proc_close, proc_terminate, proc_get_status, popen, pclose, pcntl_exec
Upload Files
File: //usr/local/lib/python3.6/site-packages/bmemcached/client/__pycache__/distributed.cpython-36.pyc
3

�':f"#�@sPddlmZddlmZddlmZddlmZddlm	Z	Gdd�de�Z
dS)	�)�defaultdict)�HashRing)�SOCKET_TIMEOUT)�ClientMixin)�picklec	s�eZdZdZd$dddedejejdf	�fdd�	Zdd�Z	d%d	d
�Z
dd�Zd'dd�Zd)dd�Z
d+dd�Zd-dd�Zd.dd�Zd/dd�Zdd�Zd1dd�Zd2d d!�Zd3d"d#�Z�ZS)4�DistributedClientz�This is intended to be a client class which implement standard cache interface that common libs do...

    It tries to distribute keys over the specified servers using `HashRing` consistent hash.
    �127.0.0.1:11211Nrc


s0tt|�j|||||||||	�	t|j�|_dS)N)�superr�__init__r�_servers�_ring)
�self�servers�username�password�compression�socket_timeoutZpickle_protocolZpicklerZ	unpicklerZtls_context)�	__class__��P/tmp/pip-build-5ba02zx6/python-binary-memcached/bmemcached/client/distributed.pyr
szDistributedClient.__init__cCs|jj|�S)N)rZget_node)r
�keyrrr�_get_serverszDistributedClient._get_servercCs|j|�}|j||�S)z�
        Delete a key/value from server. If key does not exist, it returns True.

        :param key: Key's name to be deleted
        :param cas: CAS of the key
        :return: True in case o success and False in case of failure.
        )r�delete)r
r�cas�serverrrrrs
zDistributedClient.deletecCsDtt�}x$|D]}|j|�}||j|�qWtdd�|j�D��S)NcSsg|]\}}|j|��qSr)�delete_multi)�.0rZkeys_rrr�
<listcomp>(sz2DistributedClient.delete_multi.<locals>.<listcomp>)r�listr�append�all�items)r
�keysrr�
server_keyrrrr#s


zDistributedClient.delete_multi�cCs|j|�}|j||||�S)a4
        Set a value for a key on server.

        :param key: Key's name
        :type key: str
        :param value: A value to be stored on server.
        :type value: object
        :param time: Time in seconds that your key will expire.
        :type time: int
        :param compress_level: How much to compress.
            0 = no compression, 1 = fastest, 9 = slowest but best,
            -1 = default compression level.
        :type compress_level: int
        :return: True in case of success and False in case of failure
        :rtype: bool
        )r�set)r
r�value�time�compress_levelrrrrr%*s
zDistributedClient.setcCs~|sgSt�}tt�}x2|j�D]&\}}|j|�}||j||fg�q Wx*|j�D]\}	}
|t|	j|
||��O}qTWt|�S)a
        Set multiple keys with it's values on server.

        :param mappings: A dict with keys/values
        :type mappings: dict
        :param time: Time in seconds that your key will expire.
        :type time: int
        :param compress_level: How much to compress.
            0 = no compression, 1 = fastest, 9 = slowest but best,
            -1 = default compression level.
        :type compress_level: int
        :return: List of keys that failed to be set on any server.
        :rtype: list
        )r%r�dictr!r�update�	set_multir)r
Zmappingsr'r(ZreturnsZserver_mappingsrr&r#r�mrrrr+>s
zDistributedClient.set_multicCs|j|�}|j||||�S)aP
        Add a key/value to server ony if it does not exist.

        :param key: Key's name
        :type key: six.string_types
        :param value: A value to be stored on server.
        :type value: object
        :param time: Time in seconds that your key will expire.
        :type time: int
        :param compress_level: How much to compress.
            0 = no compression, 1 = fastest, 9 = slowest but best,
            -1 = default compression level.
        :type compress_level: int
        :return: True if key is added False if key already exists
        :rtype: bool
        )r�add)r
rr&r'r(rrrrr-Ys
zDistributedClient.addcCs|j|�}|j||||�S)aS
        Replace a key/value to server ony if it does exist.

        :param key: Key's name
        :type key: six.string_types
        :param value: A value to be stored on server.
        :type value: object
        :param time: Time in seconds that your key will expire.
        :type time: int
        :param compress_level: How much to compress.
            0 = no compression, 1 = fastest, 9 = slowest but best,
            -1 = default compression level.
        :type compress_level: int
        :return: True if key is replace False if key does not exists
        :rtype: bool
        )r�replace)r
rr&r'r(rrrrr.ms
zDistributedClient.replaceFcCsT|j|�}|j|�\}}|dk	r0|r,||fS|S|dk	rH|rD|dfS|S|rPdSdS)a
        Get a key from server.

        :param key: Key's name
        :type key: six.string_types
        :param default: In case memcached does not find a key, return a default value
        :param get_cas: If true, return (value, cas), where cas is the new CAS value.
        :type get_cas: boolean
        :return: Returns a key data from server.
        :rtype: object
        N)NN)r�get)r
r�default�get_casrr&rrrrr/�s
zDistributedClient.getcCs�tt�}i}x$|D]}|j|�}||j|�qWxN|j�D]B\}}|j|�}|stx |j�D]\}\}	}
|	||<q\W|j|�q<W|S)aH
        Get multiple keys from server.

        :param keys: A list of keys to from server.
        :type keys: list
        :param get_cas: If get_cas is true, each value is (data, cas), with each result's CAS value.
        :type get_cas: boolean
        :return: A dict with all requested keys.
        :rtype: dict
        )rrrrr!�	get_multir*)r
r"r1r�drr#r�resultsr&rrrrr2�s


zDistributedClient.get_multicCs|j|�}|j|�S)N)rr/)r
rrrrr�gets�s
zDistributedClient.getscCs|j|�}|j|||||�S)a�
        Set a value for a key on server if its CAS value matches cas.

        :param key: Key's name
        :type key: six.string_types
        :param value: A value to be stored on server.
        :type value: object
        :param cas: The CAS value previously obtained from a call to get*.
        :type cas: int
        :param time: Time in seconds that your key will expire.
        :type time: int
        :param compress_level: How much to compress.
            0 = no compression, 1 = fastest, 9 = slowest but best,
            -1 = default compression level.
        :type compress_level: int
        :return: True in case of success and False in case of failure
        :rtype: bool
        )rr)r
rr&rr'r(rrrrr�s
zDistributedClient.cas�@BcCs|j|�}|j||||d�S)a�
        Increment a key, if it exists, returns it's actual value, if it don't, return 0.

        :param key: Key's name
        :type key: six.string_types
        :param value: Number to be incremented
        :type value: int
        :param default: If key not set, initialize to this value
        :type default: int
        :param time: Time in seconds that your key will expire.
        :type time: int
        :return: Actual value of the key on server
        :rtype: int
        )r0r')r�incr)r
rr&r0r'rrrrr7�s
zDistributedClient.incrcCs|j|�}|j||||d�S)a
        Decrement a key, if it exists, returns it's actual value, if it don't, return 0.
        Minimum value of decrement return is 0.

        :param key: Key's name
        :type key: six.string_types
        :param value: Number to be decremented
        :type value: int
        :param default: If key not set, initialize to this value
        :type default: int
        :param time: Time in seconds that your key will expire.
        :type time: int
        :return: Actual value of the key on server
        :rtype: int
        )r0r')r�decr)r
rr&r0r'rrrrr8�s
zDistributedClient.decr)r)r���)rr9r9)rr9r9)rr9r9)rr9)NF)Fr9)rr9)rr6)rr6)�__name__�
__module__�__qualname__�__doc__rr�Pickler�	Unpicklerr
rrrr%r+r-r.r/r2r5rr7r8�
__classcell__rr)rrr	s"








rN)�collectionsrZ	uhashringrZbmemcached.clientrZbmemcached.client.mixinrZbmemcached.compatrrrrrr�<module>s