
    i                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	  edd           ed	d
           edd           G d de	                                              Z
dS )    )annotations)versionchanged)Version)parse_storage_uri)RedisStoragez3.14.0z_
Dropped support for the :pypi:`redis-py-cluster` library
which has been abandoned/deprecated.
)versionreasonz2.5.0aa  
Cluster support was provided by the :pypi:`redis-py-cluster` library
which has been absorbed into the official :pypi:`redis` client. By
default the :class:`redis.cluster.RedisCluster` client will be used
however if the version of the package is lower than ``4.2.0`` the implementation
will fallback to trying to use :class:`rediscluster.RedisCluster`.
z4.3ztAdded support for using the redis client from :pypi:`valkey` if :paramref:`uri` has the ``valkey+cluster://`` schemac                       e Zd ZU dZddgZ	 ddiZded<   	  ed           ed	          d
Ze	j
        dfd fdZddZ xZS )RedisClusterStoragez
    Rate limit storage with redis cluster as backend

    Depends on :pypi:`redis` (or :pypi:`valkey` if :paramref:`uri`
    starts with ``valkey+cluster://``).
    zredis+clusterzvalkey+clustermax_connectionsi  zdict[str, float | str | bool]DEFAULT_OPTIONSz4.2.0z6.0)redisvalkeyFuristr
key_prefixwrap_exceptionsbooloptionsfloat | str | boolreturnNonec                    t          |          }i }|                    d|j                  x}r||d<   |                    d|j                  x}r||d<   |j        }	| _        d _        |                    d          rdnd _         j	         j                 j
         _         fd|	D             }
i  j        d|
i||} j        dk    r  j        j        j        di | _        n  j        j        j        di | _         j        sJ                      |            t#          t$                     j        ||fi | dS )	a  
        :param uri: url of the form
         ``redis+cluster://[:password]@host:port,host:port``

         If the uri scheme is ``valkey+cluster`` the implementation used will be from
         :pypi:`valkey`.
        :param key_prefix: the prefix for each key created in redis
        :param wrap_exceptions: Whether to wrap storage exceptions in
         :exc:`limits.errors.StorageError` before raising it.
        :param options: all remaining keyword arguments are passed
         directly to the constructor of :class:`redis.cluster.RedisCluster`
        :raise ConfigurationError: when the :pypi:`redis` library is not
         available or if the redis cluster cannot be reached.
        usernamepasswordNr   r   c                8    g | ]} j         j        j        | S  )
dependencyclusterClusterNode).0cselfs     l/var/www/html/crypto-mining-system/backend/venv/lib/python3.11/site-packages/limits/storage/redis_cluster.py
<listcomp>z0RedisClusterStorage.__init__.<locals>.<listcomp>Y   s)    XXXQ<0<a@XXX    startup_nodesr   )r   getr   r   	locationsr   storage
startswithtarget_serverdependenciesmoduler   r   r   RedisClusterValkeyClusterinitialize_storagesuperr   __init__)r#   r   r   r   r   storage_uri_optionsparsed_authr   r   cluster_hostsr'   merged_options	__class__s   `           r$   r3   zRedisClusterStorage.__init__7   s   * 044{{:/B/KLLL8 	/&.K
#{{:/B/KLLL8 	/&.K
#+5$),)A)ANXXw+D,>?FXXXX-XXX
"
.
 
 	
 ((?4?2?QQ.QQDLL@4?2@RR>RRDL||$$$*lD!!*3KK7KKKKKr&   
int | Nonec                   |                      d          }d}| j                                        D ]O}| j                            |                              |          }|t          fd|D                       z  }P|S )a  
        Redis Clusters are sharded and deleting across shards
        can't be done atomically. Because of this, this reset loops over all
        keys that are prefixed with :paramref:`RedisClusterStorage.prefix` and
        calls delete on them one at a time.

        .. warning::
         This operation was not tested with extremely large data sets.
         On a large production based system, care should be taken with its
         usage as it could be slow on very large data sets*r   c                `    g | ]*}                     |                    d                     +S )zutf-8)deletedecode)r!   knodes     r$   r%   z-RedisClusterStorage.reset.<locals>.<listcomp>z   s1    GGGQ$++ahhw&7&788GGGr&   )prefixed_keyr*   get_primariesget_redis_connectionkeyssum)r#   prefixcountprimaryrD   r@   s        @r$   resetzRedisClusterStorage.reseti   s     ""3''|1133 	I 	IG<44W==D99V$$DSGGGG$GGGHHHEEr&   )
r   r   r   r   r   r   r   r   r   r   )r   r9   )__name__
__module____qualname____doc__STORAGE_SCHEMEr   __annotations__r   DEPENDENCIESr   PREFIXr3   rI   __classcell__)r8   s   @r$   r   r   
   s         2  &'78N. 	46O     I !!'%.. L '- %	0L 0L 0L 0L 0L 0L 0Ld       r&   r   N)
__future__r   deprecated.sphinxr   packaging.versionr   limits._storage_schemer   limits.storage.redisr   r   r   r&   r$   <module>rX      s   " " " " " " , , , , , , % % % % % % 4 4 4 4 4 4 - - - - - -    	 	 	 	C  Y Y Y Y Y, Y Y 	 	 0Y Y Yr&   