Normal
  C   ˆl–Ðz¾”ªe¶¥	@ŠãNÜlJbÑ¿�þYrGÖl¢rFÙ–A” þÂ„@h?Á_ŠI|¥�+Wé3ž¯ÁÀ 6Ù    import os
from json import JSONDecodeError, loads
from typing import Dict, List, Optional, Union

from deprecated import deprecated

from redis.exceptions import DataError

from ._util import JsonType
from .decoders import decode_dict_keys
from .path import Path


class JSONCommands:
    """json commands."""

    def arrappend(
        self, name: str, path: Optional[str] = Path.root_path(), *args: List[JsonType]
    ) -> List[Union[int, None]]:
        """Append the objects ``args`` to the array under the
        ``path` in key ``name``.

        For more information see `JSON.ARRAPPEND <https://redis.io/commands/json.arrappend>`_..
        """  # noqa
        pieces = [name, str(path)]
        for o in args:
            pieces.append(self._encode(o))
        return self.execute_command("JSON.ARRAPPEND", *pieces)

    def arrindex(
        self,
        name: str,
        path: str,
        scalar: int,
        start: Optional[int] = 0,
        stop: Optional[int] = -1,
    ) -> List[Union[int, None]]:
        """
        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>`_.
        """  # noqa
        return self.execute_command(
            "JSON.ARRINDEX", name, str(path), self._encode(scalar), start, stop
        )

    def arrinsert(
        self, name: str, path: str, index: int, *args: List[JsonType]
    ) -> List[Union[int, None]]:
        """Insert 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>`_.
        """  # noqa
        pieces = [name, str(path), index]
        for o in args:
            pieces.append(self._encode(o))
        return self.execute_command("JSON.ARRINSERT", *pieces)

    def arrlen(
        self, name: str, path: Optional[str] = Path.root_path()
    ) -> List[Union[int, None]]:
        """Return the length of the array JSON value under ``path``
        at key``name``.

        For more information see `JSON.ARRLEN <https://redis.io/commands/json.arrlen>`_.
        """  # noqa
        return self.execute_command("JSON.ARRLEN", name, str(path))

    def arrpop(
        self,
        name: str,
        path: Optional[str] = Path.root_path(),
        index: Optional[int] = -1,
    ) -> List[Union[str, None]]:

        """Pop 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>`_.
        """  # noqa
        return self.execute_command("JSON.ARRPOP", name, str(path), index)

    def arrtrim(
        self, name: str, path: str, start: int, stop: int
    ) -> List[Union[int, None]]:
        """Trim 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>`_.
        """  # noqa
        return self.execute_command("JSON.ARRTRIM", name, str(path), start, stop)

    def type(self, name: str, path: Optional[str] = Path.root_path()) -> List[str]:
        """Get the type of the JSON value under ``path`` from key ``name``.

        For more information see `JSON.TYPE <https://redis.io/commands/json.type>`_.
        """  # noqa
        return self.execute_command("JSON.TYPE", name, str(path))

    def resp(self, name: str, path: Optional[str] = Path.root_path()) -> List:
        """Return the JSON value under ``path`` at key ``name``.

        For more information see `JSON.RESP <https://redis.io/commands/json.resp>`_.
        """  # noqa
        return self.execute_command("JSON.RESP", name, str(path))

    def objkeys(
        self, name: str, path: Optional[str] = Path.ro