U
    ‘bÖeZ  ã                   @   s   d Z G dd„ dƒZdS )aE  
A client for falling back to older memcached servers when performing reads.

It is sometimes necessary to deploy memcached on new servers, or with a
different configuration. In these cases, it is undesirable to start up an
empty memcached server and point traffic to it, since the cache will be cold,
and the backing store will have a large increase in traffic.

This class attempts to solve that problem by providing an interface identical
to the Client interface, but which can fall back to older memcached servers
when reads to the primary server fail. The approach for upgrading memcached
servers or configuration then becomes:

 1. Deploy a new host (or fleet) with memcached, possibly with a new
    configuration.
 2. From your application servers, use FallbackClient to write and read from
    the new cluster, and to read from the old cluster when there is a miss in
    the new cluster.
 3. Wait until the new cache is warm enough to support the load.
 4. Switch from FallbackClient to a regular Client library for doing all
    reads and writes to the new cluster.
 5. Take down the old cluster.

Best Practices:
---------------
 - Make sure that the old client has "ignore_exc" set to True, so that it
   treats failures like cache misses. That will allow you to take down the
   old cluster before you switch away from FallbackClient.
c                   @   sº   e Zd Zdd„ Zdd„ Zd*dd„Zd+d	d
„Zd,dd„Zd-dd„Zd.dd„Z	d/dd„Z
dd„ Zdd„ Zdd„ Zdd„ Zd0dd„Zd1dd„Zd2dd „Zd3d!d"„Zd#d$„ Zd4d%d&„Zd'd(„ Zd)S )5ÚFallbackClientc                 C   s   t |ƒdkst‚|| _d S ©Né    )ÚlenÚAssertionErrorÚcaches)Úselfr   © r   úU/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pymemcache/fallback.pyÚ__init__/   s    zFallbackClient.__init__c                 C   s   | j D ]}| ¡  qdS )z#Close each of the memcached clientsN)r   Úclose)r   Úcacher   r   r	   r   3   s    
zFallbackClient.closer   Tc                 C   s   | j d  ||||¡ d S r   )r   Úset©r   ÚkeyÚvalueÚexpireÚnoreplyr   r   r	   r   8   s    zFallbackClient.setc                 C   s   | j d  ||||¡ d S r   )r   Úaddr   r   r   r	   r   ;   s    zFallbackClient.addc                 C   s   | j d  ||||¡ d S r   )r   Úreplacer   r   r   r	   r   >   s    zFallbackClient.replacec                 C   s   | j d  ||||¡ d S r   )r   Úappendr   r   r   r	   r   A   s    zFallbackClient.appendc                 C   s   | j d  ||||¡ d S r   )r   Úprependr   r   r   r	   r   D   s    zFallbackClient.prependc                 C   s   | j d  |||||¡ d S r   )r   Úcas)r   r   r   r   r   r   r   r   r	   r   G   s    zFallbackClient.casc                 C   s*   | j D ]}| |¡}|d k	r|  S qd S ©N)r   Úget©r   r   r   Úresultr   r   r	   r   J   s
    


zFallbackClient.getc                 C   s&   | j D ]}| |¡}|r|  S qg S r   )r   Úget_many©r   Úkeysr   r   r   r   r	   r   Q   s
    


zFallbackClient.get_manyc                 C   s*   | j D ]}| |¡}|d k	r|  S qd S r   )r   Úgetsr   r   r   r	   r   X   s
    


zFallbackClient.getsc                 C   s&   | j D ]}| |¡}|r|  S qg S r   )r   Ú	gets_manyr   r   r   r	   r    _   s
    


zFallbackClient.gets_manyc                 C   s   | j d  ||¡ d S r   )r   Údelete)r   r   r   r   r   r	   r!   f   s    zFallbackClient.deletec                 C   s   | j d  |||¡ d S r   )r   Úincr©r   r   r   r   r   r   r	   r"   i   s    zFallbackClient.incrc                 C   s   | j d  |||¡ d S r   )r   Údecrr#   r   r   r	   r$   l   s    zFallbackClient.decrc                 C   s   | j d  |||¡ d S r   )r   Útouch)r   r   r   r   r   r   r	   r%   o   s    zFallbackClient.touchc                 C   s   d S r   r   ©r   r   r   r	   Ústatsr   s    zFallbackClient.statsc                 C   s   | j d  ||¡ d S r   )r   Ú	flush_all)r   Údelayr   r   r   r	   r(   v   s    zFallbackClient.flush_allc                 C   s   d S r   r   r&   r   r   r	   Úquity   s    zFallbackClient.quitN)r   T)r   T)r   T)r   T)r   T)r   T)T)T)T)r   T)r   T)Ú__name__Ú
__module__Ú__qualname__r
   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r$   r%   r'   r(   r*   r   r   r   r	   r   .   s&   










r   N)Ú__doc__r   r   r   r   r	   Ú<module>   s   