o
    Ljs                     @   s   d dl Z d dlmZ d dlmZmZ d dlmZmZm	Z	 d dl
mZ d dlmZmZ d dlmZ dd	lmZ dd
lmZ ddlmZ G dd deeZG dd dZdS )    N)Enum)JSONDecodeErrorloads)Any	Awaitableoverload)	DataError)AsyncClientProtocolSyncClientProtocol)deprecated_function   )JsonType)decode_dict_keys)Pathc                   @   s.   e Zd ZdZdZdZdZdZedd	d
Z	dS )FPHATypezFloating-point type options for homogeneous array storage in JSON.SET.

    Used with the ``fpha`` parameter to force Redis to store all FP arrays
    using the specified floating-point type.
    BF16FP16FP32FP64valueFPHAType | strreturnc                 C   sP   t || r|S z| | W S  ty'   td| dddd | D  w )ap  Convert a string or FPHAType instance to a validated FPHAType.

        Args:
            value: An ``FPHAType`` member or a case-insensitive string
                (e.g. ``"bf16"``, ``"FP32"``).

        Returns:
            The corresponding ``FPHAType`` enum member.

        Raises:
            DataError: If the string does not match any valid FPHA type.
        zInvalid FPHA type: z. Must be one of z, c                 s   s    | ]}|j V  qd S N)r   ).0t r   Z/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/redis/commands/json/commands.py	<genexpr>0   s    z&FPHAType.from_value.<locals>.<genexpr>)
isinstanceupper
ValueErrorr   join)clsr   r   r   r   
from_value   s   
zFPHAType.from_valueN)r   r   r   r   )
__name__
__module____qualname____doc__r   r   r   r   classmethodr#   r   r   r   r   r      s    r   c                   @   s  e Zd ZdZee fdedededB de	de
ee
dB  B dB f
dd	Zee fdedededB de	dee
ee
dB  B dB  f
d
d	Ze fdededB de	de
ee
dB  B dB ee
ee
dB  B dB  B fdd	Ze		ddededede
de
dB de
dB de
ee
dB  B dB fddZe		ddededede
de
dB de
dB dee
ee
dB  B dB  fddZ		ddedede
de
dB de
dB de
ee
dB  B dB ee
ee
dB  B dB  B fddZedededede
de	de
ee
dB  B dB fddZedededede
de	dee
ee
dB  B dB  fddZdedede
de	de
ee
dB  B dB ee
ee
dB  B dB  B f
ddZee fdedededB de
ee
dB  B dB fddZee fdedededB dee
ee
dB  B dB  fddZe fdededB de
ee
dB  B dB ee
ee
dB  B dB  B fddZee dfdedededB de
dB de	eB ee B dB f
ddZee dfdedededB de
dB dee	eB ee B dB  f
ddZe dfdededB de
dB de	eB ee B dB ee	eB ee B dB  B fd dZedededede
de
de
ee
dB  B dB fd!d"Zedededede
de
dee
ee
dB  B dB  fd#d"Zdedede
de
de
ee
dB  B dB ee
ee
dB  B dB  B f
d$d"Zee fdedededB dedB eedB  B eee  B fd%d&Zee fdedededB deedB eedB  B eee  B  fd'd&Ze fdededB dedB eedB  B eee  B eedB eedB  B eee  B  B fd(d&Zee fdedededB defd)d*Zee fdedededB dee fd+d*Ze fdededB deee B fd,d*Zee fdedededB dee eee dB  B dB fd-d.Zee fdedededB deee eee dB  B dB  fd/d.Ze fdededB dee eee dB  B dB eee eee dB  B dB  B fd0d.Zee fdedededB de
ee
dB  B dB fd1d2Zee fdedededB dee
ee
dB  B dB  fd3d2Ze fdededB de
ee
dB  B dB ee
ee
dB  B dB  B fd4d2Zedededed5e
de
eB ee
eB dB  B f
d6d7Zedededed5e
dee
eB ee
eB dB  B  f
d8d7Zdeded5e
de
eB ee
eB dB  B ee
eB ee
eB dB  B  B fd9d7Zedededed5e
de
eB ee
eB dB  B f
d:d;Zedededed5e
dee
eB ee
eB dB  B  f
d<d;Zed=d>d?deded5e
de
eB ee
eB dB  B ee
eB ee
eB dB  B  B fd@d;Zee fdedededB de
fdAdBZee fdedededB dee
 fdCdBZe fdededB de
ee
 B fdDdBZee fdedEededB de
fdFdGZee fdedEededB dee
 fdHdGZe fdEededB de
ee
 B fdIdGZeZedJdKdededLe dB de	dB fdMdNZ!edJdKdededLe dB dee	dB  fdOdNZ!dJdKdedLe dB de	dB ee	dB  B fdPdNZ!ededQee dedee	dB  fdRdSZ"ededQee dedeee	dB   fdTdSZ"dQee dedee	dB  eee	dB   B fdUdSZ"e	J	J	J	ddedededVe	dWe dB dXe dB dYe dB dZe#eB dB de dB fd[d\Z$e	J	J	J	ddedededVe	dWe dB dXe dB dYe dB dZe#eB dB dee dB  fd]d\Z$	J	J	J	ddededVe	dWe dB dXe dB dYe dB dZe#eB dB de dB ee dB  B fd^d\Z$eded_ee%eee	f  de fd`daZ&eded_ee%eee	f  dee  fdbdaZ&d_ee%eee	f  de ee  B fdcdaZ&e	JddedededVe	dYe dB de fdddeZ'e	JddedededVe	dYe dB dee  fdfdeZ'	JddededVe	dYe dB de ee  B f
dgdeZ'e	J	J	J	ddedededhedWe dB dXe dB dYe dB dZe#eB dB de dB fdidjZ(e	J	J	J	ddedededhedWe dB dXe dB dYe dB dZe#eB dB dee dB  fdkdjZ(	J	J	J	ddededhedWe dB dXe dB dYe dB dZe#eB dB de dB ee dB  B fdldjZ(e	J	J	J	ddedmednedWe dB dXe dB dYe dB dZe#eB dB de)ee f fdodpZ*e	J	J	J	ddedmednedWe dB dXe dB dYe dB dZe#eB dB dee)ee f  fdqdpZ*	J	J	J	ddmednedWe dB dXe dB dYe dB dZe#eB dB de)ee f ee)ee f  B fdrdpZ*e	ddedededB de
ee
dB  B dB fdsdtZ+e	ddedededB dee
ee
dB  B dB  fdudtZ+ddededB de
ee
dB  B dB ee
ee
dB  B dB  B fdvdtZ+ee fdedededB de ee
dB  B dB fdwdxZ,ee fdedededB dee ee
dB  B dB  fdydxZ,e fdededB de ee
dB  B dB ee ee
dB  B dB  B fdzdxZ,ee fdeded{ededB de
ee
dB  B dB f
d|d}Z-ee fdeded{ededB dee
ee
dB  B dB  f
d~d}Z-e fded{ededB de
ee
dB  B dB ee
ee
dB  B dB  B fdd}Z-ede fdededEedB dedB de
ee B f
ddZ.ede fdededEedB dedB dee
ee B  f
ddZ.de fdedEedB dedB de
ee B ee
ee B  B fddZ.edede	dB fddZ/ededee	dB  fddZ/ed=dd?de	dB ee	dB  B fddZ/ededee	dB  fddZ0ededeee	dB   fddZ0ed=dd?dee	dB  eee	dB   B fddZ0edede dB fddZ1ededee dB  fddZ1ed=dd?de dB ee dB  B fddZ1dS )JSONCommandszjson commands.selfnamepathNargsr   c                 G      d S r   r   r*   r+   r,   r-   r   r   r   	arrappend7      zJSONCommands.arrappendc                 G   r.   r   r   r/   r   r   r   r0   ?   r1   c                 G   s8   |t |g}|D ]
}|| | q| jdg|R  S )zAppend the objects ``args`` to the array under the
        ``path` in key ``name``.

        For more information see `JSON.ARRAPPEND <https://redis.io/commands/json.arrappend>`_..
        zJSON.ARRAPPENDstrappend_encodeexecute_command)r*   r+   r,   r-   piecesor   r   r   r0   G   s   scalarstartstopc                 C   r.   r   r   r*   r+   r,   r9   r:   r;   r   r   r   arrindexT      zJSONCommands.arrindexc                 C   r.   r   r   r<   r   r   r   r=   ^   r>   c                 C   sR   |t || |g}|dur|| |dur|| | jdg|R d|giS )a:  
        Return the index of ``scalar`` in the JSON array under ``path`` at key
        ``name``.

        The search can be limited using the optional inclusive ``start``
        and exclusive ``stop`` indices.

        For more information see `JSON.ARRINDEX <https://redis.io/commands/json.arrindex>`_.
        NzJSON.ARRINDEXkeys)r3   r5   r4   r6   )r*   r+   r,   r9   r:   r;   r7   r   r   r   r=   h   s   

indexc                 G   r.   r   r   r*   r+   r,   r@   r-   r   r   r   	arrinsert      zJSONCommands.arrinsertc                 G   r.   r   r   rA   r   r   r   rB         c                 G   s:   |t ||g}|D ]
}|| | q	| jdg|R  S )zInsert the objects ``args`` to the array at index ``index``
        under the ``path` in key ``name``.

        For more information see `JSON.ARRINSERT <https://redis.io/commands/json.arrinsert>`_.
        zJSON.ARRINSERTr2   )r*   r+   r,   r@   r-   r7   r8   r   r   r   rB      s   c                 C   r.   r   r   r*   r+   r,   r   r   r   arrlen   rC   zJSONCommands.arrlenc                 C   r.   r   r   rE   r   r   r   rF      rC   c                 C      | j d|t||gdS )zReturn the length of the array JSON value under ``path``
        at key``name``.

        For more information see `JSON.ARRLEN <https://redis.io/commands/json.arrlen>`_.
        zJSON.ARRLENr?   r6   r3   rE   r   r   r   rF         c                 C   r.   r   r   r*   r+   r,   r@   r   r   r   arrpop   r1   zJSONCommands.arrpopc                 C   r.   r   r   rL   r   r   r   rM      r1   c                 C   s   |  d|t||S )zPop the element at ``index`` in the array JSON value under
        ``path`` at key ``name``.

        For more information see `JSON.ARRPOP <https://redis.io/commands/json.arrpop>`_.
        zJSON.ARRPOPrI   rL   r   r   r   rM      s   c                 C   r.   r   r   r*   r+   r,   r:   r;   r   r   r   arrtrim   rC   zJSONCommands.arrtrimc                 C   r.   r   r   rN   r   r   r   rO      rC   c                 C   s   |  d|t|||S )zTrim the array JSON value under ``path`` at key ``name`` to the
        inclusive range given by ``start`` and ``stop``.

        For more information see `JSON.ARRTRIM <https://redis.io/commands/json.arrtrim>`_.
        zJSON.ARRTRIMrI   rN   r   r   r   rO      s   c                 C   r.   r   r   rE   r   r   r   type   rC   zJSONCommands.typec                 C   r.   r   r   rE   r   r   r   rP      rC   c                 C   rG   )zGet the type of the JSON value under ``path`` from key ``name``.

        For more information see `JSON.TYPE <https://redis.io/commands/json.type>`_.
        z	JSON.TYPErH   rI   rE   r   r   r   rP         c                 C   r.   r   r   rE   r   r   r   resp   rC   zJSONCommands.respc                 C   r.   r   r   rE   r   r   r   rR      rC   c                 C   rG   )zReturn the JSON value under ``path`` at key ``name``.

        For more information see `JSON.RESP <https://redis.io/commands/json.resp>`_.
        z	JSON.RESPrH   rI   rE   r   r   r   rR      rQ   c                 C   r.   r   r   rE   r   r   r   objkeys	  rC   zJSONCommands.objkeysc                 C   r.   r   r   rE   r   r   r   rS     rC   c                 C   rG   )zReturn the key names in the dictionary JSON value under ``path`` at
        key ``name``.

        For more information see `JSON.OBJKEYS <https://redis.io/commands/json.objkeys>`_.
        zJSON.OBJKEYSrH   rI   rE   r   r   r   rS     rJ   c                 C   r.   r   r   rE   r   r   r   objlen  rC   zJSONCommands.objlenc                 C   r.   r   r   rE   r   r   r   rT   "  rC   c                 C   rG   )zReturn the length of the dictionary JSON value under ``path`` at key
        ``name``.

        For more information see `JSON.OBJLEN <https://redis.io/commands/json.objlen>`_.
        zJSON.OBJLENrH   rI   rE   r   r   r   rT   '  rJ   numberc                 C   r.   r   r   r*   r+   r,   rU   r   r   r   	numincrby1  rC   zJSONCommands.numincrbyc                 C   r.   r   r   rV   r   r   r   rW   6  rC   c                 C   "   t |}| jd||| ||dS )zIncrement the numeric (integer or floating point) JSON value under
        ``path`` at key ``name`` by the provided ``number``.

        For more information see `JSON.NUMINCRBY <https://redis.io/commands/json.numincrby>`_.
        zJSON.NUMINCRBY
_json_pathr3   r6   r5   rV   r   r   r   rW   ;  s   c                 C   r.   r   r   rV   r   r   r   	nummultbyH  rC   zJSONCommands.nummultbyc                 C   r.   r   r   rV   r   r   r   r\   M  rC   z4.0.0z deprecated since redisjson 1.0.0)versionreasonc                 C   rX   )zMultiply the numeric (integer or floating point) JSON value under
        ``path`` at key ``name`` with the provided ``number``.

        For more information see `JSON.NUMMULTBY <https://redis.io/commands/json.nummultby>`_.
        zJSON.NUMMULTBYrY   r[   rV   r   r   r   r\   R  s   	c                 C   r.   r   r   rE   r   r   r   clear`  rC   zJSONCommands.clearc                 C   r.   r   r   rE   r   r   r   r_   e  rC   c                 C      |  d|t|S )a  Empty arrays and objects (to have zero slots/keys without deleting the
        array/object).

        Return the count of cleared paths (ignoring non-array and non-objects
        paths).

        For more information see `JSON.CLEAR <https://redis.io/commands/json.clear>`_.
        z
JSON.CLEARrI   rE   r   r   r   r_   j  s   keyc                 C   r.   r   r   r*   ra   r,   r   r   r   deletew  rC   zJSONCommands.deletec                 C   r.   r   r   rb   r   r   r   rc   |  rC   c                 C   r`   )zDelete the JSON value stored at key ``key`` under ``path``.

        For more information see `JSON.DEL <https://redis.io/commands/json.del>`_.
        zJSON.DELrI   rb   r   r   r   rc     s   F)	no_escaperd   c                G   r.   r   r   r*   r+   rd   r-   r   r   r   get  rC   zJSONCommands.getc                G   r.   r   r   re   r   r   r   rf     rC   c                G   sz   |g}|r
| d t|dkr| t  n|D ]	}| t| qz| jdg|R d|giW S  ty<   Y dS w )aD  
        Get the object stored as a JSON value at key ``name``.

        ``args`` is zero or more paths, and defaults to root path
        ```no_escape`` is a boolean flag to add no_escape option to get
        non-ascii characters

        For more information see `JSON.GET <https://redis.io/commands/json.get>`_.
        noescaper   zJSON.GETr?   N)r4   lenr   	root_pathr3   r6   	TypeError)r*   r+   rd   r-   r7   pr   r   r   rf     s   
r?   c                 C   r.   r   r   r*   r?   r,   r   r   r   mget  rC   zJSONCommands.mgetc                 C   r.   r   r   rl   r   r   r   rm     rC   c                 C   s2   g }||7 }| t| | jdg|R d|iS )z
        Get the objects stored as a JSON values under ``path``. ``keys``
        is a list of one or more keys.

        For more information see `JSON.MGET <https://redis.io/commands/json.mget>`_.
        z	JSON.MGETr?   r4   r3   r6   )r*   r?   r,   r7   r   r   r   rm     s   	objnxxxdecode_keysfphac                 C   r.   r   r   r*   r+   r,   ro   rp   rq   rr   rs   r   r   r   set     
zJSONCommands.setc                 C   r.   r   r   rt   r   r   r   ru     rv   c           	      C   s~   |rt |}|t|| |g}|r|rtd|r |d n|r'|d |dur6|dt|jg | j	dg|R  S )a  
        Set the JSON value at key ``name`` under the ``path`` to ``obj``.

        ``nx`` if set to True, set ``value`` only if it does not exist.
        ``xx`` if set to True, set ``value`` only if it exists.
        ``decode_keys`` If set to True, the keys of ``obj`` will be decoded
        with utf-8.
        ``fpha`` if set, forces Redis to use the specified floating-point type
        for storing all FP homogeneous arrays in ``obj``.
        Accepts a :class:`FPHAType` enum value or a string
        (``"BF16"``, ``"FP16"``, ``"FP32"``, ``"FP64"``).

        For the purpose of using this within a pipeline, this command is also
        aliased to JSON.SET.

        For more information see `JSON.SET <https://redis.io/commands/json.set>`_.
        zNnx and xx are mutually exclusive: use one, the other or neither - but not bothNXXXNFPHAzJSON.SET)
r   r3   r5   	Exceptionr4   extendr   r#   r   r6   )	r*   r+   r,   ro   rp   rq   rr   rs   r7   r   r   r   ru     s   
tripletsc                 C   r.   r   r   r*   r|   r   r   r   mset  rC   zJSONCommands.msetc                 C   r.   r   r   r}   r   r   r   r~     rC   c              	   C   sF   g }|D ]}| |d t|d | |d g q| jdg|R  S )a  
        Set the JSON value at key ``name`` under the ``path`` to ``obj``
        for one or more keys.

        ``triplets`` is a list of one or more triplets of key, path, value.

        For the purpose of using this within a pipeline, this command is also
        aliased to JSON.MSET.

        For more information see `JSON.MSET <https://redis.io/commands/json.mset>`_.
        r   r      z	JSON.MSET)r{   r3   r5   r6   )r*   r|   r7   tripletr   r   r   r~     s   (c                 C   r.   r   r   r*   r+   r,   ro   rr   r   r   r   merge0  rD   zJSONCommands.mergec                 C   r.   r   r   r   r   r   r   r   9  rD   c                 C   s2   |rt |}|t|| |g}| jdg|R  S )aa  
        Merges a given JSON value into matching paths. Consequently, JSON values
        at matching paths are updated, deleted, or expanded with new children

        ``decode_keys`` If set to True, the keys of ``obj`` will be decoded
        with utf-8.

        For more information see `JSON.MERGE <https://redis.io/commands/json.merge>`_.
        z
JSON.MERGE)r   r3   r5   r6   )r*   r+   r,   ro   rr   r7   r   r   r   r   B  s   	file_namec                 C   r.   r   r   r*   r+   r,   r   rp   rq   rr   rs   r   r   r   set_fileY  rv   zJSONCommands.set_filec                 C   r.   r   r   r   r   r   r   r   e  rv   c           
   	   C   sL   t |}t| }	W d   n1 sw   Y  | j|||	||||dS )ao  
        Set the JSON value at key ``name`` under the ``path`` to the content
        of the json file ``file_name``.

        ``nx`` if set to True, set ``value`` only if it does not exist.
        ``xx`` if set to True, set ``value`` only if it exists.
        ``decode_keys`` If set to True, the keys of ``obj`` will be decoded
        with utf-8.
        ``fpha`` if set, forces Redis to use the specified floating-point type
        for storing all FP homogeneous arrays in the file content.
        Accepts a :class:`FPHAType` enum value or a string
        (``"BF16"``, ``"FP16"``, ``"FP32"``, ``"FP64"``).

        Nrp   rq   rr   rs   )openr   readru   )
r*   r+   r,   r   rp   rq   rr   rs   fpfile_contentr   r   r   r   q  s   
	json_pathroot_folderc                 C   r.   r   r   r*   r   r   rp   rq   rr   rs   r   r   r   set_path     	zJSONCommands.set_pathc                 C   r.   r   r   r   r   r   r   r     r   c                 C   s   i }t |D ]7\}}	}
|
D ]/}t j||}z|dd }| j|||||||d d||< W q ty=   d||< Y qw q|S )a|  
        Iterate over ``root_folder`` and set each JSON file to a value
        under ``json_path`` with the file name as the key.

        ``nx`` if set to True, set ``value`` only if it does not exist.
        ``xx`` if set to True, set ``value`` only if it exists.
        ``decode_keys`` If set to True, the keys of ``obj`` will be decoded
        with utf-8.
        ``fpha`` if set, forces Redis to use the specified floating-point type
        for storing all FP homogeneous arrays in the file content.
        Accepts a :class:`FPHAType` enum value or a string
        (``"BF16"``, ``"FP16"``, ``"FP32"``, ``"FP64"``).

        .r   r   TF)oswalkr,   r!   rsplitr   r   )r*   r   r   rp   rq   rr   rs   set_files_resultrootdirsfilesfile	file_pathr   r   r   r   r     s*   	c                 C   r.   r   r   rE   r   r   r   strlen  rC   zJSONCommands.strlenc                 C   r.   r   r   rE   r   r   r   r     rC   c                 C   s6   |g}|dur| t| | jdg|R d|giS )zReturn the length of the string JSON value under ``path`` at key
        ``name``.

        For more information see `JSON.STRLEN <https://redis.io/commands/json.strlen>`_.
        NzJSON.STRLENr?   rn   )r*   r+   r,   r7   r   r   r   r     s   c                 C   r.   r   r   rE   r   r   r   toggle  rC   zJSONCommands.togglec                 C   r.   r   r   rE   r   r   r   r     rC   c                 C   r`   )zToggle boolean value under ``path`` at key ``name``.
        returning the new value.

        For more information see `JSON.TOGGLE <https://redis.io/commands/json.toggle>`_.
        zJSON.TOGGLErI   rE   r   r   r   r     s   r   c                 C   r.   r   r   r*   r+   r   r,   r   r   r   	strappend  r1   zJSONCommands.strappendc                 C   r.   r   r   r   r   r   r   r   	  r1   c                 C   s&   |t || |g}| jdg|R  S )aC  Append to the string JSON value. If two options are specified after
        the key name, the path is determined to be the first. If a single
        option is passed, then the root_path (i.e Path.root_path()) is used.

        For more information see `JSON.STRAPPEND <https://redis.io/commands/json.strappend>`_.
        zJSON.STRAPPEND)r3   r5   r6   )r*   r+   r   r,   r7   r   r   r   r     s   	
subcommandc                 C   r.   r   r   r*   r   ra   r,   r   r   r   debug  r1   zJSONCommands.debugc                 C   r.   r   r   r   r   r   r   r   %  r1   c                 C   sf   ddg}||vrt dt||g}|dkr*|du rt d|| |t| | jdg|R  S )zReturn the memory usage in bytes of a value under ``path`` from
        key ``name``.

        For more information see `JSON.DEBUG <https://redis.io/commands/json.debug>`_.
        MEMORYHELPzThe only valid subcommands are NzNo key specifiedz
JSON.DEBUG)r   r3   r4   r6   )r*   r   ra   r,   valid_subcommandsr7   r   r   r   r   -  s   
c                 O   r.   r   r   r*   r-   kwargsr   r   r   jsongetC     zJSONCommands.jsongetc                 O   r.   r   r   r   r   r   r   r   F  rC   z/redisjson-py supported this, call get directly.c                 O      | j |i |S r   )rf   r   r   r   r   r   K     c                 O   r.   r   r   r   r   r   r   jsonmgetS  rC   zJSONCommands.jsonmgetc                 O   r.   r   r   r   r   r   r   r   X  rC   c                 O   r   r   )rm   r   r   r   r   r   ]  r   c                 O   r.   r   r   r   r   r   r   jsonsete  r   zJSONCommands.jsonsetc                 O   r.   r   r   r   r   r   r   r   h  rC   c                 O   r   r   )ru   r   r   r   r   r   m  s   )NN)FFFN)Fr   )2r$   r%   r&   r'   r   r   ri   r
   r3   r   intlistr0   r	   r   r=   rB   rF   r   rM   rO   rP   rR   rS   rT   floatrW   r\   r   r_   rc   forgetboolrf   rm   r   ru   tupler~   r   r   dictr   r   r   r   r   r   r   r   r   r   r   r   r)   4   s8   *
	*




""	

	












	

	
	
0(


	

	
	
 





/







$r)   )r   enumr   jsonr   r   typingr   r   r   redis.exceptionsr   redis.typingr	   r
   redis.utilsr   _utilr   decodersr   r,   r   r3   r   r)   r   r   r   r   <module>   s    %