
    5j                        S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  \" SSS9\" S	S
S9\" SSS9 " S S\	5      5       5       5       r
g)    )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                     ^  \ rS rSr% SrSS/r SS0rS\S'    \" S	5      \" S
5      S.r	\
R                  S4         SU 4S jjjrSS jrSrU =r$ )RedisClusterStorage
   z
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valkeyFc                V  > [        U5      n0 nUR                  SUR                  5      =n(       a  XvS'   UR                  SUR                  5      =n(       a  XS'   UR                  n	X l        SU l        UR                  S5      (       a  SOSU l        U R                  U R                     R                  U l        U	 V
s/ s H%  oR                  R                  R                  " U
6 PM'     nn
0 U R                  ESU0EUEUEnU R                  S:X  a,  U R                  R                  R                  " S0 UD6U l        O+U R                  R                  R                   " S0 UD6U l        U R                  (       d   eU R#                  U5        [$        [&        U ]R  " X40 UD6  gs  sn
f )aX  
: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   startup_nodes )r   getr   r   	locations
key_prefixstorage
startswithtarget_serverdependenciesmodule
dependencyclusterClusterNoder   RedisClusterValkeyClusterinitialize_storagesuperr   __init__)selfurir   wrap_exceptionsoptionsstorage_uri_optionsparsed_authr   r   cluster_hostscr   merged_options	__class__s                [/root/lseg-credit/backend/venv/lib/python3.13/site-packages/limits/storage/redis_cluster.pyr%   RedisClusterStorage.__init__7   s   * 04{{:/B/K/KLL8L&.
#{{:/B/K/KLL8L&.
#+55$),)A)AXw++D,>,>?FFJWX-Q00<<a@-X
""
.
 
 	
 (??22??Q.QDL??22@@R>RDL|||$lD*3K7K Ys   ,F&c                H   U R                  S5      nSnU R                  R                  5        Hk  nU R                  R                  U5      nUR	                  U5      nU[        U Vs/ s H"  odR                  UR                  S5      5      PM$     sn5      -  nMm     U$ s  snf )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   zutf-8)prefixed_keyr   get_primariesget_redis_connectionkeyssumdeletedecode)r&   prefixcountprimarynoder7   ks          r0   resetRedisClusterStorage.reseti   s     ""3'||113G<<44W=D99V$DS$G$Q++ahhw&78$GHHE 4  Hs   ')B)r   r   r   r   )
r'   strr   rB   r(   boolr)   zfloat | str | boolreturnNone)rD   z
int | None)__name__
__module____qualname____firstlineno____doc__STORAGE_SCHEMEr   __annotations__r   DEPENDENCIESr   PREFIXr%   r@   __static_attributes____classcell__)r/   s   @r0   r   r   
   s    2 &'78N. 	46O2  I !%.L '-- %	0L0L 0L 	0L
 &0L 
0L 0Ld     r   N)
__future__r   deprecated.sphinxr   packaging.versionr   limits._storage_schemer   limits.storage.redisr   r   r   rQ   r0   <module>rW      sn    " , % 4 -  	 	CY, Y	0YrQ   