HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/lib/python3.9/site-packages/redis/asyncio/__pycache__/sentinel.cpython-39.pyc
a

��bG4�@s�ddlZddlZddlZddlmZmZmZmZmZm	Z	ddl
mZddlm
Z
mZmZmZddlmZddlmZmZmZmZddlmZGdd	�d	e�ZGd
d�de�ZGdd
�d
e
�ZGdd�dee�ZGdd�de�ZGdd�de�ZdS)�N)�
AsyncIterator�Iterable�Mapping�Sequence�Tuple�Type)�Redis)�
Connection�ConnectionPool�
EncodableT�
SSLConnection)�AsyncSentinelCommands)�ConnectionError�
ReadOnlyError�
ResponseError�TimeoutError)�str_if_bytesc@seZdZdS)�MasterNotFoundErrorN��__name__�
__module__�__qualname__�rr�:/usr/lib/python3.9/site-packages/redis/asyncio/sentinel.pyrsrc@seZdZdS)�SlaveNotFoundErrorNrrrrrrsrcsLeZdZ�fdd�Zdd�Z�fdd�Zdd�Zd
ed
��fdd�
Z�Z	S)�SentinelManagedConnectioncs"|�d�|_t�jfi|��dS)N�connection_pool)�popr�super�__init__)�self�kwargs��	__class__rrrsz"SentinelManagedConnection.__init__cCsD|j}|jj�d|j��}|jr<d|j�d|j��}||7}|dS)N�	<service=z,host=z,port=�>)rr#r�service_name�host�port)r Zpool�sZ	host_inforrr�__repr__sz"SentinelManagedConnection.__repr__c�sV|\|_|_t���IdH|jjrR|�d�IdHt|��IdH�dkrRt	d��dS)NZPINGZPONGzPING failed)
r'r(r�connectr�check_connectionZsend_commandr�
read_responser)r Zaddressr"rr�
connect_to'sz$SentinelManagedConnection.connect_toc	�s�|jr
dS|jjr0|�|j��IdH�IdHnL|j��2z:3dHW}z|�|�IdHWStyrYq:Yq:0q:6t�dS�N)Z_readerr�	is_masterr.�get_master_address�
rotate_slavesrr)r �slaverrrr+/sz!SentinelManagedConnection.connectF��disable_decodingc�sNzt�j|d�IdHWStyH|jjrB|��IdHtd���Yn0dS)Nr4z"The previous master is now a slave)rr-rrr0�
disconnectr)r r5r"rrr-<sz'SentinelManagedConnection.read_response)F)
rrrrr*r.r+�boolr-�
__classcell__rrr"rrs

rc@seZdZdS)�SentinelManagedSSLConnectionNrrrrrr9Ksr9cs\eZdZdZ�fdd�Zdd�Z�fdd�Zed��fd	d
�Zdd�Z	e
d
�dd�Z�ZS)�SentinelConnectionPoolz�
    Sentinel backed connection pool.

    If ``check_connection`` flag is set to True, SentinelManagedConnection
    sends a PING command right after establishing the connection.
    csz|�d|�dd�rtnt�|d<|�dd�|_|�dd�|_t�jfi|��t�	|�|j
d<||_||_d|_
d|_dS)NZconnection_classZsslFr0Tr,r)�getrr9rr0r,rr�weakref�proxy�connection_kwargsr&�sentinel_manager�master_address�slave_rr_counter)r r&r?r!r"rrrWs
��zSentinelConnectionPool.__init__cCs&|jj�d|j�d|jrdpd�d�S)Nr$�(Zmasterr3z)>)r#rr&r0�r rrrr*gs
���zSentinelConnectionPool.__repr__cst���d|_d|_dSr/)r�resetr@rArCr"rrrDms
zSentinelConnectionPool.reset)�
connectioncs0|jp|jo|j|j|jfk}|o.t��|�Sr/)r0r@r'r(r�owns_connection)r rE�checkr"rrrFrs�z&SentinelConnectionPool.owns_connectionc�s@|j�|j�IdH}|jr<|j|kr<||_|jdd�IdH|S)NF)Zinuse_connections)r?�discover_masterr&r0r@r6)r r@rrrr1xs
z)SentinelConnectionPool.get_master_address)�returncCs�|j�|j�IdH}|rn|jdur8t�dt|�d�|_tt|��D](}|jdt|�|_||j}|VqDz|��IdHVWnt	y�Yn0t
d|j����dS)zRound-robin slave balancerNr�zNo slave found for )r?�discover_slavesr&rA�randomZrandint�len�ranger1rr)r �slaves�_r3rrrr2�s

z$SentinelConnectionPool.rotate_slaves)
rrr�__doc__rr*rDr	rFr1rr2r8rrr"rr:Os
r:c@s�eZdZdZddd�Zdd�Zdd	�Zeee	d
�dd�Z
ed
�dd�Zee
eeeefd�dd�Zeeeeefd�dd�Zeefeeeeed�dd�Zeefeeeeed�dd�ZdS)�Sentinela~
    Redis Sentinel cluster client

    >>> from redis.sentinel import Sentinel
    >>> sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1)
    >>> master = sentinel.master_for('mymaster', socket_timeout=0.1)
    >>> await master.set('foo', 'bar')
    >>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1)
    >>> await slave.get('foo')
    b'bar'

    ``sentinels`` is a list of sentinel nodes. Each node is represented by
    a pair (hostname, port).

    ``min_other_sentinels`` defined a minimum number of peers for a sentinel.
    When querying a sentinel, if it doesn't meet this threshold, responses
    from that sentinel won't be considered valid.

    ``sentinel_kwargs`` is a dictionary of connection arguments used when
    connecting to sentinel instances. Any argument that can be passed to
    a normal Redis connection can be specified here. If ``sentinel_kwargs`` is
    not specified, any socket_timeout and socket_keepalive options specified
    in ``connection_kwargs`` will be used.

    ``connection_kwargs`` are keyword arguments that will be used when
    establishing a connection to a Redis server.
    rNcsD|durdd�|��D�}|�_�fdd�|D��_|�_|�_dS)NcSs i|]\}}|�d�r||�qS)Zsocket_)�
startswith)�.0�k�vrrr�
<dictcomp>�sz%Sentinel.__init__.<locals>.<dictcomp>cs&g|]\}}tf||d��j���qS))r'r()r�sentinel_kwargs)rT�hostnamer(rCrr�
<listcomp>�s�z%Sentinel.__init__.<locals>.<listcomp>)�itemsrX�	sentinels�min_other_sentinelsr>)r r\r]rXr>rrCrr�s	�
�zSentinel.__init__c�stt��dd��}d���vr&��d�|rR��fdd�|jD�}tj|�IdHnt�|j�j	�i���IdHdS)z�
        Execute Sentinel command in sentinel nodes.
        once - If set to True, then execute the resulting command on a single
               node at random, rather than across the entire sentinel cluster.
        �onceFcs"g|]}t�|j�i�����qSr)�asyncioZTask�execute_command)rT�sentinel��argsr!rrrZ�s�z,Sentinel.execute_command.<locals>.<listcomp>NT)
r7r;�keysrr\r_ZgatherrL�choicer`)r rcr!r^Ztasksrrbrr`�s
�zSentinel.execute_commandcCsNg}|jD](}|�|jjd�d|jjd���q
|jj�dd�|��d�S)Nr'�:r(z<sentinels=[�,z]>)r\�appendrr>r#r�join)r Zsentinel_addressesrarrrr*�s

��zSentinel.__repr__)�stater&rIcCs2|dr|ds|drdS|d|jkr.dSdS)Nr0�is_sdown�is_odownFznum-other-sentinelsT)r])r rjr&rrr�check_master_state�s
zSentinel.check_master_state)r&c
�s�t|j�D]�\}}z|��IdH}Wnttfy>Yq
Yn0|�|�}|r
|�||�r
||jd|jd<|j|<|d|dfSq
td|����dS)z�
        Asks sentinel servers for the Redis master's address corresponding
        to the service labeled ``service_name``.

        Returns a pair (address, port) or raises MasterNotFoundError if no
        master is found.
        Nr�ipr(zNo master found for )�	enumerater\Zsentinel_mastersrrr;rmr)r r&Zsentinel_noraZmastersrjrrrrH�s

�zSentinel.discover_master)rOrIcCs:g}|D],}|ds|drq|�|d|df�q|S)z1Remove slaves that are in an ODOWN or SDOWN staterlrkrnr()rh)r rOZslaves_aliver3rrr�
filter_slavesszSentinel.filter_slaves)r&rIc�sX|jD]L}z|�|�IdH}Wntttfy:YqYn0|�|�}|r|SqgS)z;Returns a list of alive slaves for service ``service_name``N)r\Zsentinel_slavesrrrrp)r r&rarOrrrrKs



zSentinel.discover_slaves)r&�redis_class�connection_pool_classcKs4d|d<t|j�}|�|�||||fi|��d�S)a�
        Returns a redis client instance for the ``service_name`` master.

        A :py:class:`~redis.sentinel.SentinelConnectionPool` class is
        used to retrieve the master's address before establishing a new
        connection.

        NOTE: If the master's address has changed, any cached connections to
        the old master are closed.

        By default clients will be a :py:class:`~redis.Redis` instance.
        Specify a different class to the ``redis_class`` argument if you
        desire something different.

        The ``connection_pool_class`` specifies the connection pool to
        use.  The :py:class:`~redis.sentinel.SentinelConnectionPool`
        will be used by default.

        All other keyword arguments are merged with any connection_kwargs
        passed to this class and passed to the connection pool as keyword
        arguments to be used to initialize Redis connections.
        Tr0�r��dictr>�update�r r&rqrrr!r>rrr�
master_fors

���zSentinel.master_forcKs4d|d<t|j�}|�|�||||fi|��d�S)a�
        Returns redis client instance for the ``service_name`` slave(s).

        A SentinelConnectionPool class is used to retrieve the slave's
        address before establishing a new connection.

        By default clients will be a :py:class:`~redis.Redis` instance.
        Specify a different class to the ``redis_class`` argument if you
        desire something different.

        The ``connection_pool_class`` specifies the connection pool to use.
        The SentinelConnectionPool will be used by default.

        All other keyword arguments are merged with any connection_kwargs
        passed to this class and passed to the connection pool as keyword
        arguments to be used to initialize Redis connections.
        Fr0rsrtrwrrr�	slave_forBs

���zSentinel.slave_for)rN)rrrrQrr`r*ru�strr7rmrHrrrrrrprKrr:rrxryrrrrrR�s8�
	����)��rR) r_rLr<�typingrrrrrrZredis.asyncio.clientrZredis.asyncio.connectionr	r
rrZredis.commandsr
Zredis.exceptionsrrrrZredis.utilsrrrrr9r:rRrrrr�<module>s 1E