o
    $i)                     @   s  d dl mZmZmZ d dlmZ d dlmZ dada	dd Z
dd	 Zd
efddZedd Zedddeeef deeeef  defddZedddeeef deeeef  defddZedededdfddZe	d'dddeeef deeef dedeeeef  def
ddZeddd deeef d!edeeeef  defd"d#Zeddd$eeef deeeef  dee fd%d&ZdS )(    )ListOptionalUnion)client_mode_hook)	GcsClientFNc                   C   s   d a dad S )NFglobal_gcs_client_initialized r
   r
   Y/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/experimental/internal_kv.py_internal_kv_reset
   s   r   c                   C   s   t S Nr   r
   r
   r
   r   internal_kv_get_gcs_client   s   r   
gcs_clientc                 C   s   | dusJ | a dadS )z;Initialize the internal KV for use in other function calls.NTr   )r   r
   r
   r   _initialize_internal_kv   s   r   c                   C   s   t d uS r   r   r
   r
   r
   r   _internal_kv_initialized   s   r   )	namespacekeyr   returnc                C   >   t | tr	|  } t |tr| }t | tsJ t| |S )z Fetch the value of a binary key.)
isinstancestrencodebytesr   internal_kv_getr   r   r
   r
   r   _internal_kv_get!      

r   c                C   r   )zCheck key exists or not.)r   r   r   r   r   internal_kv_existsr   r
   r
   r   _internal_kv_exists/   r   r    uriexpiration_sc                C   s   t | |S )z'Pin a runtime_env URI for expiration_s.)r   pin_runtime_env_uri)r!   r"   r
   r
   r   _pin_runtime_env_uri=   s   r$   Tvalue	overwritec                C   sl   t | tr	|  } t |tr| }t |tr| }t | tr*t |tr*t |ts,J t| |||dkS )zGlobally associates a value with a given binary key.

    This only has an effect if the key does not already have a value.

    Returns:
        already_exists: whether the value already exists.
    r   )r   r   r   r   boolr   internal_kv_put)r   r%   r&   r   r
   r
   r   _internal_kv_putC   s   


r)   )del_by_prefixr   r*   c                C   s@   t | tr	|  } t |tr| }t | tsJ t| ||S r   )r   r   r   r   r   internal_kv_del)r   r*   r   r
   r
   r   _internal_kv_dela   s   

r,   prefixc                C   s0   t | tr	|  } t |tr| }t| |S )zBList all keys in the internal KV store that start with the prefix.)r   r   r   r   internal_kv_keys)r-   r   r
   r
   r   _internal_kv_listp   s
   

r/   )T)typingr   r   r   ray._private.client_mode_hookr   ray._rayletr   r	   r   r   r   r   r   r   r   r   r'   r    intr$   r)   r,   r/   r
   r
   r
   r   <module>   s    






