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: //lib/python3.9/site-packages/redis/__pycache__/sentinel.cpython-39.pyc
a

��bR1�@s�ddlZddlZddlmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
mZddlmZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�dee	�ZGdd�de�ZGdd�de�ZdS)�N)�Redis)�SentinelCommands)�
Connection�ConnectionPool�
SSLConnection)�ConnectionError�
ReadOnlyError�
ResponseError�TimeoutError)�str_if_bytesc@seZdZdS)�MasterNotFoundErrorN��__name__�
__module__�__qualname__�rr�2/usr/lib/python3.9/site-packages/redis/sentinel.pyrsrc@seZdZdS)�SlaveNotFoundErrorNr
rrrrrsrcsNeZdZ�fdd�Zdd�Z�fdd�Zdd�Zd	d
�Zd�fdd
�	Z�Z	S)�SentinelManagedConnectioncs"|�d�|_t�jfi|��dS)N�connection_pool)�popr�super�__init__)�self�kwargs��	__class__rrrsz"SentinelManagedConnection.__init__cCsD|j}t|�j�d|j�d�}|jr@d|j�d|j��}||}|S)N�	<service=z%s>z,host=z,port=)r�typer�service_name�host�port)rZpool�sZ	host_inforrr�__repr__sz"SentinelManagedConnection.__repr__csD|\|_|_t���|jjr@|�d�t|���dkr@t	d��dS)NZPINGZPONGzPING failed)
r r!r�connectr�check_connectionZsend_commandr�
read_responser)rZaddressrrr�
connect_to s

z$SentinelManagedConnection.connect_toc	Csd|jr
dS|jjr$|�|j���n<|j��D],}z|�|�WStyXYq.Yq.0q.t�dS�N)Z_sockr�	is_masterr'�get_master_address�
rotate_slavesrr)r�slaverrr�_connect_retry(sz(SentinelManagedConnection._connect_retrycCs|j�|jdd��S)NcSsdSr(r)�errorrrr�<lambda>6�z3SentinelManagedConnection.connect.<locals>.<lambda>)ZretryZcall_with_retryr-�rrrrr$5sz!SentinelManagedConnection.connectFcsBzt�j|d�WSty<|jjr6|��td���Yn0dS)N)�disable_decodingz"The previous master is now a slave)rr&rrr)�
disconnectr)rr2rrrr&8sz'SentinelManagedConnection.read_response)F)
rrrrr#r'r-r$r&�
__classcell__rrrrrs
rc@seZdZdS)�SentinelManagedSSLConnectionNr
rrrrr5Gsr5csPeZdZdZ�fdd�Zdd�Z�fdd�Z�fdd	�Zd
d�Zdd
�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.
    csn|�d|�dd�rtnt�|d<|�dd�|_|�dd�|_t�jfi|��t�	|�|j
d<||_||_dS)NZconnection_classZsslFr)Tr%r)
�getrr5rr)r%rr�weakref�proxy�connection_kwargsr�sentinel_manager)rrr;rrrrrSs
��zSentinelConnectionPool.__init__cCs,|jr
dnd}t|�j�d|j�d|�d�S)NZmasterr,r�(�))r)rrr)rZrolerrrr#aszSentinelConnectionPool.__repr__cst���d|_d|_dSr()r�reset�master_address�slave_rr_counterr1rrrr>es
zSentinelConnectionPool.resetcs4|jp|jo|j|j|jfk}t�}|o2|�|�Sr()r)r?r r!r�owns_connection)rZ
connection�check�parentrrrrAjs
�z&SentinelConnectionPool.owns_connectioncCs4|j�|j�}|jr0|j|kr0||_|jdd�|S)NF)Zinuse_connections)r;�discover_masterrr)r?r3)rr?rrrr*qs
z)SentinelConnectionPool.get_master_addressccs�|j�|j�}|rh|jdur2t�dt|�d�|_tt|��D](}|jdt|�|_||j}|Vq>z|��VWnt	y�Yn0t
d|j����dS)zRound-robin slave balancerNr�zNo slave found for )r;�discover_slavesrr@�randomZrandint�len�ranger*rr)r�slaves�_r,rrrr+{s

z$SentinelConnectionPool.rotate_slaves)rrr�__doc__rr#r>rAr*r+r4rrrrr6Ks
r6c@sfeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
eefdd�Z
eefdd�ZdS)�Sentinelar
    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)
    >>> master.set('foo', 'bar')
    >>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1)
    >>> 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|]\}}t||fi�j���qSr)r�sentinel_kwargs)rO�hostnamer!r1rr�
<listcomp>�s�z%Sentinel.__init__.<locals>.<listcomp>)�itemsrS�	sentinels�min_other_sentinelsr:)rrWrXrSr:rr1rr�s	�
�zSentinel.__init__cOsdt|�dd��}d|��vr&|�d�|rH|jD]}|j|i|��q0nt�|j�j|i|��dS)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.
        �onceFT)�boolr7�keysrrW�execute_commandrG�choice)r�argsrrY�sentinelrrrr\�s

zSentinel.execute_commandcCs@g}|jD]}|�d�|jj��q
t|�j�dd�|��d�S)Nz
{host}:{port}z<sentinels=[�,z]>)rW�append�
format_maprr:rr�join)rZsentinel_addressesr_rrrr#�s
�zSentinel.__repr__cCs2|dr|ds|drdS|d|jkr.dSdS)Nr)�is_sdown�is_odownFznum-other-sentinelsT)rX)r�staterrrr�check_master_state�s
zSentinel.check_master_statec
Cs�t|j�D]z\}}z|��}Wnttfy8Yq
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.
        r�ipr!zNo master found for N)�	enumeraterWZsentinel_mastersrr
r7rgr)rrZsentinel_nor_ZmastersrfrrrrD�s

�zSentinel.discover_mastercCs:g}|D],}|ds|drq|�|d|df�q|S)z1Remove slaves that are in an ODOWN or SDOWN statererdrhr!)ra)rrJZslaves_aliver,rrr�
filter_slaves�szSentinel.filter_slavescCsR|jD]F}z|�|�}Wntttfy4YqYn0|�|�}|r|SqgS)z;Returns a list of alive slaves for service ``service_name``)rWZsentinel_slavesrr	r
rj)rrr_rJrrrrFs



zSentinel.discover_slavescKs4d|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.
        Tr)�r��dictr:�update�rrZredis_classZconnection_pool_classrr:rrr�
master_for
s

���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.
        Fr)rkrlrorrr�	slave_for3s

���zSentinel.slave_for)rN)rrrrLrr\r#rgrDrjrFrr6rprqrrrrrM�s �
	�
)�rM)rGr8Zredis.clientrZredis.commandsrZredis.connectionrrrZredis.exceptionsrrr	r
Zredis.utilsrrrrr5r6rMrrrr�<module>s4B