a
    xd                     @   sX   d dl mZmZmZmZ d dlmZ d dlmZ ddl	m
Z
 dd ZG dd	 d	e
Zd
S )    )parse_qs	urlencodeurlparse
urlunparse)ImproperlyConfigured)SentinelConnectionPool   )DefaultClientc                 C   s*   t g | d d t|dd| d R S )N   T)doseq   )r   r   )urlquery r   T/var/www/html/Ranjet/env/lib/python3.9/site-packages/django_redis/client/sentinel.pyreplace_query	   s    r   c                       s,   e Zd ZdZ fddZ fddZ  ZS )SentinelClienta3  
    Sentinel client which uses the single redis URL specified by the CACHE's
    LOCATION to create a LOCATION configuration for two connection pools; One
    pool for the primaries and another pool for the replicas, and upon
    connecting ensures the connection pool factory is configured correctly.
    c                    sf   t |trRt| t jdd}t|}dg|d< dg|d<  fdd||fD }t ||| d S )NT)keep_blank_valuesr   Z	is_masterr   c                    s   g | ]}t  |qS r   )r   ).0ir   r   r   
<listcomp>       z+SentinelClient.__init__.<locals>.<listcomp>)
isinstancestrr   r   r   dictsuper__init__)selfserverparamsbackendZprimary_queryZreplica_query	__class__r   r   r      s    


zSentinelClient.__init__c                    s*   t  j|i |}t|jts&td|S )NznSettings DJANGO_REDIS_CONNECTION_FACTORY or CACHE[].OPTIONS.CONNECTION_POOL_CLASS is not configured correctly.)r   connectr   Zconnection_poolr   r   )r   argskwargs
connectionr"   r   r   r$   !   s    zSentinelClient.connect)__name__
__module____qualname____doc__r   r$   __classcell__r   r   r"   r   r      s   r   N)urllib.parser   r   r   r   Zdjango.core.exceptionsr   Zredis.sentinelr   defaultr	   r   r   r   r   r   r   <module>   s
   