
    dh                         S SK JrJrJrJrJrJrJr  S SKJ	r	  S SK
JrJr   " S S\\\4   5      r\	" SSS9 " S	 S
\5      5       r " S S\5      rg)    )AnyIteratorListOptionalSequenceTuplecast)
deprecated)	BaseStore	ByteStorec                       \ rS rSrSrSSSSSS.S\S\\   S\\   S\\   S	\\   S
S4S jjr	S\S
\4S jr
S\\   S
\\\      4S jrS\\\\4      S
S4S jrS\\   S
S4S jrSS.S\\   S
\\   4S jjrSrg)_UpstashRedisStore   zEBaseStore implementation using Upstash Redis as the underlying store.Nclienturltokenttl	namespacer   r   r   r   r   returnc                    SSK Jn  U(       a  U(       a  [        S5      eU(       a5  [	        X5      (       d"  [        S[        U5      R                   S35      eUnOU(       a  U(       d  [        S5      eU" X#S	9nXl        [	        U[        5      (       d  Ub  [        S
[        U5       S35      eX@l
        XPl        g! [         a  n[        S5      UeSnAff = f)a  Initialize the UpstashRedisStore with HTTP API.

Must provide either an Upstash Redis client or a url.

Args:
    client: An Upstash Redis instance
    url: UPSTASH_REDIS_REST_URL
    token: UPSTASH_REDIS_REST_TOKEN
    ttl: time to expire keys in seconds if provided,
         if None keys will never expire
    namespace: if provided, all keys will be prefixed with this namespace
r   )Redisz_UpstashRedisStore requires the upstash_redis library to be installed. pip install upstash_redisNzCEither an Upstash Redis client or a url must be provided, not both.z#Expected Upstash Redis client, got .zAEither an Upstash Redis client or url and token must be provided.)r   r   zExpected int or None, got z	 instead.)upstash_redisr   ImportError
ValueError
isinstance	TypeErrortype__name__r   intr   r   )	selfr   r   r   r   r   r   e_clients	            a/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/storage/upstash_redis.py__init___UpstashRedisStore.__init__
   s    *	+ cU  f,,9$v,:O:O9PPQR  Ge W  1G#s##8c9MNN"=  	, 	s   B? ?
C	CCkeyc                 P    SnU R                   (       a  U R                    U U 3$ U$ )zGet the key with the namespace prefix.

Args:
    key (str): The original key.

Returns:
    str: The key with the namespace prefix.
/)r   )r"   r(   	delimiters      r%   _get_prefixed_key$_UpstashRedisStore._get_prefixed_keyA   s-     	>>nn%i[66
    keysc                     U Vs/ sH  o R                  U5      PM     nn[        [        [        [              U R
                  R                  " U6 5      $ s  snf ).Get the values associated with the given keys.)r,   r	   r   r   strr   mget)r"   r/   r(   s      r%   r3   _UpstashRedisStore.mgetO   sQ     8<<t&&s+t<#KKd#
 	
 =s   Akey_value_pairsc                     U H8  u  p#U R                   R                  U R                  U5      X0R                  S9  M:     g)Set the given key-value pairs.)exN)r   setr,   r   )r"   r5   r(   values       r%   mset_UpstashRedisStore.msetX   s1    )JCKKOOD223788OL *r.   c                 ~    U Vs/ sH  o R                  U5      PM     nnU R                  R                  " U6   gs  snf zDelete the given keys.N)r,   r   delete)r"   r/   r(   _keyss       r%   mdelete_UpstashRedisStore.mdelete]   s6    8<='',=E" >s   :prefixrD   c             #     #    U(       a  U R                  U5      nOU R                  S5      nU R                  R                  SUS9u  p4U H9  nU R                  (       a!  U[	        U R                  5      S-   S nUv   M5  Uv   M;     US:w  ac  U R                  R                  X2S9u  p4U H9  nU R                  (       a!  U[	        U R                  5      S-   S nUv   M5  Uv   M;     US:w  a  Mb  gg7f)Yield keys in the store.*r   )match   N)r,   r   scanr   len)r"   rD   patterncursorr/   r(   relative_keys          r%   
yield_keys_UpstashRedisStore.yield_keysb   s     ,,V4G,,S1G{{'''9C~~"3t~~#6#:#<=""	  k;;++F+BLF>>#&s4>>':Q'>'@#AL&&I  ks   C,C20C2)r   r   r   )r    
__module____qualname____firstlineno____doc__r   r   r2   r!   r&   r,   r   r   r3   r   r;   rA   r   rO   __static_attributes__ r.   r%   r   r      s    O
 !#!#'5# 5# c]	5#
 }5# c]5# C=5# 
5#nS S 
# 
4+> 
MHU38_$= M$ M
#HSM #d #
 59 HSM Xc]  r.   r   z0.0.1UpstashRedisByteStore)alternativec                       \ rS rSrSrSrg)UpstashRedisStore{   z
BaseStore implementation using Upstash Redis
as the underlying store to store strings.

Deprecated in favor of the more generic UpstashRedisByteStore.
rV   N)r    rQ   rR   rS   rT   rU   rV   r.   r%   rZ   rZ   {   s    r.   rZ   c                       \ rS rSrSrSSSSSS.S\S\\   S\\   S\\   S	\\   S
S4S jjr	S\
\   S
\\\      4S jrS\
\\\4      S
S4S jrS\
\   S
S4S jrSS.S\\   S
\\   4S jjrSrg)rW      zZ
BaseStore implementation using Upstash Redis
as the underlying store to store raw bytes.
Nr   r   r   r   r   r   r   c                $    [        XX4US9U l        g )Nr   )r   underlying_store)r"   r   r   r   r   r   s         r%   r&   UpstashRedisByteStore.__init__   s     !3%I!
r.   r/   c                     U R                   R                  U5       Vs/ sH  nUb  UR                  S5      OSPM     sn$ s  snf )r1   Nutf-8)r_   r3   encode)r"   r/   r:   s      r%   r3   UpstashRedisByteStore.mget   sM     ..33D9
9 &+%6ELL!D@9
 	
 
s   A r5   c           
          U R                   R                  U VVs/ sH  u  p#Ub  X#R                  S5      4OSPM     snn5        gs  snnf )r7   Nrb   )r_   r;   decode)r"   r5   kvs       r%   r;   UpstashRedisByteStore.mset   sO    "" ,+DA +,-HHW%&TA+	
s   "A
c                 :    U R                   R                  U5        gr>   )r_   rA   )r"   r/   s     r%   rA   UpstashRedisByteStore.mdelete   s    %%d+r.   rC   rD   c             #   R   #    U R                   R                  US9 Sh  vN   g N7f)rF   rC   N)r_   rO   )r"   rD   s     r%   rO    UpstashRedisByteStore.yield_keys   s"     ((3363BBBs   '%')r_   )r    rQ   rR   rS   rT   r   r   r2   r!   r&   r   r   bytesr3   r   r;   rA   r   rO   rU   rV   r.   r%   rW   rW      s     !#!#'
 
 c]	

 }
 c]
 C=
 


# 
4+@ 

HU3:->$? 
D 
,HSM ,d , 59 CHSM CXc] C Cr.   N)typingr   r   r   r   r   r   r	   langchain_core._api.deprecationr
   langchain_core.storesr   r   r2   r   rZ   rW   rV   r.   r%   <module>rr      s^    G G G 6 6q38, qh G!89*  :)CI )Cr.   