{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Database.Redis.ManualCommands.JSON where

import Data.ByteString (ByteString)
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NE

import Database.Redis.Core
import Database.Redis.Protocol
import Database.Redis.Types

data JSONGetOpts = JSONGetOpts
    { JSONGetOpts -> Maybe ByteString
jsonGetIndent :: Maybe ByteString
    , JSONGetOpts -> Maybe ByteString
jsonGetNewline :: Maybe ByteString
    , JSONGetOpts -> Maybe ByteString
jsonGetSpace :: Maybe ByteString
    , JSONGetOpts -> [ByteString]
jsonGetPaths :: [ByteString]
    } deriving (Int -> JSONGetOpts -> ShowS
[JSONGetOpts] -> ShowS
JSONGetOpts -> String
(Int -> JSONGetOpts -> ShowS)
-> (JSONGetOpts -> String)
-> ([JSONGetOpts] -> ShowS)
-> Show JSONGetOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JSONGetOpts -> ShowS
showsPrec :: Int -> JSONGetOpts -> ShowS
$cshow :: JSONGetOpts -> String
show :: JSONGetOpts -> String
$cshowList :: [JSONGetOpts] -> ShowS
showList :: [JSONGetOpts] -> ShowS
Show, JSONGetOpts -> JSONGetOpts -> Bool
(JSONGetOpts -> JSONGetOpts -> Bool)
-> (JSONGetOpts -> JSONGetOpts -> Bool) -> Eq JSONGetOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JSONGetOpts -> JSONGetOpts -> Bool
== :: JSONGetOpts -> JSONGetOpts -> Bool
$c/= :: JSONGetOpts -> JSONGetOpts -> Bool
/= :: JSONGetOpts -> JSONGetOpts -> Bool
Eq)

defaultJSONGetOpts :: JSONGetOpts
defaultJSONGetOpts :: JSONGetOpts
defaultJSONGetOpts = JSONGetOpts
    { jsonGetIndent :: Maybe ByteString
jsonGetIndent = Maybe ByteString
forall a. Maybe a
Nothing
    , jsonGetNewline :: Maybe ByteString
jsonGetNewline = Maybe ByteString
forall a. Maybe a
Nothing
    , jsonGetSpace :: Maybe ByteString
jsonGetSpace = Maybe ByteString
forall a. Maybe a
Nothing
    , jsonGetPaths :: [ByteString]
jsonGetPaths = []
    }

data JSONSetCondition
    = JSONSetIfNotExists
    | JSONSetIfExists
    deriving (Int -> JSONSetCondition -> ShowS
[JSONSetCondition] -> ShowS
JSONSetCondition -> String
(Int -> JSONSetCondition -> ShowS)
-> (JSONSetCondition -> String)
-> ([JSONSetCondition] -> ShowS)
-> Show JSONSetCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JSONSetCondition -> ShowS
showsPrec :: Int -> JSONSetCondition -> ShowS
$cshow :: JSONSetCondition -> String
show :: JSONSetCondition -> String
$cshowList :: [JSONSetCondition] -> ShowS
showList :: [JSONSetCondition] -> ShowS
Show, JSONSetCondition -> JSONSetCondition -> Bool
(JSONSetCondition -> JSONSetCondition -> Bool)
-> (JSONSetCondition -> JSONSetCondition -> Bool)
-> Eq JSONSetCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JSONSetCondition -> JSONSetCondition -> Bool
== :: JSONSetCondition -> JSONSetCondition -> Bool
$c/= :: JSONSetCondition -> JSONSetCondition -> Bool
/= :: JSONSetCondition -> JSONSetCondition -> Bool
Eq)

instance RedisArg JSONSetCondition where
    encode :: JSONSetCondition -> ByteString
encode JSONSetCondition
JSONSetIfNotExists = ByteString
"NX"
    encode JSONSetCondition
JSONSetIfExists = ByteString
"XX"

data JSONSetFPHA
    = JSONSetFP16
    | JSONSetBF16
    | JSONSetFP32
    | JSONSetFP64
    deriving (Int -> JSONSetFPHA -> ShowS
[JSONSetFPHA] -> ShowS
JSONSetFPHA -> String
(Int -> JSONSetFPHA -> ShowS)
-> (JSONSetFPHA -> String)
-> ([JSONSetFPHA] -> ShowS)
-> Show JSONSetFPHA
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JSONSetFPHA -> ShowS
showsPrec :: Int -> JSONSetFPHA -> ShowS
$cshow :: JSONSetFPHA -> String
show :: JSONSetFPHA -> String
$cshowList :: [JSONSetFPHA] -> ShowS
showList :: [JSONSetFPHA] -> ShowS
Show, JSONSetFPHA -> JSONSetFPHA -> Bool
(JSONSetFPHA -> JSONSetFPHA -> Bool)
-> (JSONSetFPHA -> JSONSetFPHA -> Bool) -> Eq JSONSetFPHA
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JSONSetFPHA -> JSONSetFPHA -> Bool
== :: JSONSetFPHA -> JSONSetFPHA -> Bool
$c/= :: JSONSetFPHA -> JSONSetFPHA -> Bool
/= :: JSONSetFPHA -> JSONSetFPHA -> Bool
Eq)

instance RedisArg JSONSetFPHA where
    encode :: JSONSetFPHA -> ByteString
encode JSONSetFPHA
JSONSetFP16 = ByteString
"FP16"
    encode JSONSetFPHA
JSONSetBF16 = ByteString
"BF16"
    encode JSONSetFPHA
JSONSetFP32 = ByteString
"FP32"
    encode JSONSetFPHA
JSONSetFP64 = ByteString
"FP64"

data JSONSetOpts = JSONSetOpts
    { JSONSetOpts -> Maybe JSONSetCondition
jsonSetCondition :: Maybe JSONSetCondition
    , JSONSetOpts -> Maybe JSONSetFPHA
jsonSetFPHA :: Maybe JSONSetFPHA
    } deriving (Int -> JSONSetOpts -> ShowS
[JSONSetOpts] -> ShowS
JSONSetOpts -> String
(Int -> JSONSetOpts -> ShowS)
-> (JSONSetOpts -> String)
-> ([JSONSetOpts] -> ShowS)
-> Show JSONSetOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JSONSetOpts -> ShowS
showsPrec :: Int -> JSONSetOpts -> ShowS
$cshow :: JSONSetOpts -> String
show :: JSONSetOpts -> String
$cshowList :: [JSONSetOpts] -> ShowS
showList :: [JSONSetOpts] -> ShowS
Show, JSONSetOpts -> JSONSetOpts -> Bool
(JSONSetOpts -> JSONSetOpts -> Bool)
-> (JSONSetOpts -> JSONSetOpts -> Bool) -> Eq JSONSetOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JSONSetOpts -> JSONSetOpts -> Bool
== :: JSONSetOpts -> JSONSetOpts -> Bool
$c/= :: JSONSetOpts -> JSONSetOpts -> Bool
/= :: JSONSetOpts -> JSONSetOpts -> Bool
Eq)

defaultJSONSetOpts :: JSONSetOpts
defaultJSONSetOpts :: JSONSetOpts
defaultJSONSetOpts = JSONSetOpts
    { jsonSetCondition :: Maybe JSONSetCondition
jsonSetCondition = Maybe JSONSetCondition
forall a. Maybe a
Nothing
    , jsonSetFPHA :: Maybe JSONSetFPHA
jsonSetFPHA = Maybe JSONSetFPHA
forall a. Maybe a
Nothing
    }

data JSONArrIndexOpts
    = JSONArrIndexAll
    | JSONArrIndexFrom Integer
    | JSONArrIndexFromTo Integer Integer
    deriving (Int -> JSONArrIndexOpts -> ShowS
[JSONArrIndexOpts] -> ShowS
JSONArrIndexOpts -> String
(Int -> JSONArrIndexOpts -> ShowS)
-> (JSONArrIndexOpts -> String)
-> ([JSONArrIndexOpts] -> ShowS)
-> Show JSONArrIndexOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> JSONArrIndexOpts -> ShowS
showsPrec :: Int -> JSONArrIndexOpts -> ShowS
$cshow :: JSONArrIndexOpts -> String
show :: JSONArrIndexOpts -> String
$cshowList :: [JSONArrIndexOpts] -> ShowS
showList :: [JSONArrIndexOpts] -> ShowS
Show, JSONArrIndexOpts -> JSONArrIndexOpts -> Bool
(JSONArrIndexOpts -> JSONArrIndexOpts -> Bool)
-> (JSONArrIndexOpts -> JSONArrIndexOpts -> Bool)
-> Eq JSONArrIndexOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: JSONArrIndexOpts -> JSONArrIndexOpts -> Bool
== :: JSONArrIndexOpts -> JSONArrIndexOpts -> Bool
$c/= :: JSONArrIndexOpts -> JSONArrIndexOpts -> Bool
/= :: JSONArrIndexOpts -> JSONArrIndexOpts -> Bool
Eq)

defaultJSONArrIndexOpts :: JSONArrIndexOpts
defaultJSONArrIndexOpts :: JSONArrIndexOpts
defaultJSONArrIndexOpts = JSONArrIndexOpts
JSONArrIndexAll

jsonGetOptsToArgs :: JSONGetOpts -> [ByteString]
jsonGetOptsToArgs :: JSONGetOpts -> [ByteString]
jsonGetOptsToArgs JSONGetOpts{[ByteString]
Maybe ByteString
jsonGetIndent :: JSONGetOpts -> Maybe ByteString
jsonGetNewline :: JSONGetOpts -> Maybe ByteString
jsonGetSpace :: JSONGetOpts -> Maybe ByteString
jsonGetPaths :: JSONGetOpts -> [ByteString]
jsonGetIndent :: Maybe ByteString
jsonGetNewline :: Maybe ByteString
jsonGetSpace :: Maybe ByteString
jsonGetPaths :: [ByteString]
..} =
    [ByteString]
indentArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
newlineArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
spaceArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
jsonGetPaths
  where
    indentArg :: [ByteString]
indentArg = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
indent -> [ByteString
"INDENT", ByteString
indent]) Maybe ByteString
jsonGetIndent
    newlineArg :: [ByteString]
newlineArg = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
newline -> [ByteString
"NEWLINE", ByteString
newline]) Maybe ByteString
jsonGetNewline
    spaceArg :: [ByteString]
spaceArg = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
space -> [ByteString
"SPACE", ByteString
space]) Maybe ByteString
jsonGetSpace

jsonSetOptsToArgs :: JSONSetOpts -> [ByteString]
jsonSetOptsToArgs :: JSONSetOpts -> [ByteString]
jsonSetOptsToArgs JSONSetOpts{Maybe JSONSetFPHA
Maybe JSONSetCondition
jsonSetCondition :: JSONSetOpts -> Maybe JSONSetCondition
jsonSetFPHA :: JSONSetOpts -> Maybe JSONSetFPHA
jsonSetCondition :: Maybe JSONSetCondition
jsonSetFPHA :: Maybe JSONSetFPHA
..} =
    [ByteString]
conditionArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
fphaArg
  where
    conditionArg :: [ByteString]
conditionArg = [ByteString]
-> (JSONSetCondition -> [ByteString])
-> Maybe JSONSetCondition
-> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\JSONSetCondition
condition -> [JSONSetCondition -> ByteString
forall a. RedisArg a => a -> ByteString
encode JSONSetCondition
condition]) Maybe JSONSetCondition
jsonSetCondition
    fphaArg :: [ByteString]
fphaArg = [ByteString]
-> (JSONSetFPHA -> [ByteString])
-> Maybe JSONSetFPHA
-> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\JSONSetFPHA
fpha -> [ByteString
"FPHA", JSONSetFPHA -> ByteString
forall a. RedisArg a => a -> ByteString
encode JSONSetFPHA
fpha]) Maybe JSONSetFPHA
jsonSetFPHA

jsonArrIndexOptsToArgs :: JSONArrIndexOpts -> [ByteString]
jsonArrIndexOptsToArgs :: JSONArrIndexOpts -> [ByteString]
jsonArrIndexOptsToArgs JSONArrIndexOpts
JSONArrIndexAll = []
jsonArrIndexOptsToArgs (JSONArrIndexFrom Integer
start) = [Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start]
jsonArrIndexOptsToArgs (JSONArrIndexFromTo Integer
start Integer
stop) = [Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
stop]

-- |Appends one or more JSON values into the array at path after the last element in it (<https://redis.io/commands/json.arrappend>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonArrappend
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the array.
    -> NonEmpty ByteString -- ^ Serialized JSON values to append.
    -> m (f Reply)
jsonArrappend :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> NonEmpty ByteString -> m (f Reply)
jsonArrappend ByteString
key ByteString
path NonEmpty ByteString
values =
    [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Reply)) -> [ByteString] -> m (f Reply)
forall a b. (a -> b) -> a -> b
$ [ByteString
"JSON.ARRAPPEND", ByteString
key, ByteString
path] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ByteString
values

-- |Returns the index of the first occurrence of a JSON scalar value in the array at path (<https://redis.io/commands/json.arrindex>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the array, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonArrindex
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the array.
    -> ByteString -- ^ Serialized JSON scalar to search for.
    -> m (f Reply)
jsonArrindex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Reply)
jsonArrindex ByteString
key ByteString
path ByteString
value = ByteString
-> ByteString -> ByteString -> JSONArrIndexOpts -> m (f Reply)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> JSONArrIndexOpts -> m (f Reply)
jsonArrindexOpts ByteString
key ByteString
path ByteString
value JSONArrIndexOpts
defaultJSONArrIndexOpts

-- |Returns the index of the first occurrence of a JSON scalar value in the array at path (<https://redis.io/commands/json.arrindex>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the array, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonArrindexOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the array.
    -> ByteString -- ^ Serialized JSON scalar to search for.
    -> JSONArrIndexOpts -- ^ Optional search range.
    -> m (f Reply)
jsonArrindexOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> JSONArrIndexOpts -> m (f Reply)
jsonArrindexOpts ByteString
key ByteString
path ByteString
value JSONArrIndexOpts
opts =
    [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Reply)) -> [ByteString] -> m (f Reply)
forall a b. (a -> b) -> a -> b
$ [ByteString
"JSON.ARRINDEX", ByteString
key, ByteString
path, ByteString
value] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ JSONArrIndexOpts -> [ByteString]
jsonArrIndexOptsToArgs JSONArrIndexOpts
opts

-- |Returns the length of the array at the root path (<https://redis.io/commands/json.arrlen>).
--
-- /O(1)/ where path is evaluated to a single value, /O(N)/ where path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonArrlen
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Reply)
jsonArrlen :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Reply)
jsonArrlen ByteString
key = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.ARRLEN", ByteString
key]

-- |Returns the length of the array at path (<https://redis.io/commands/json.arrlen>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ where path is evaluated to a single value, /O(N)/ where path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonArrlenAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the array.
    -> m (f Reply)
jsonArrlenAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonArrlenAt ByteString
key ByteString
path = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.ARRLEN", ByteString
key, ByteString
path]

-- |Inserts the JSON scalar(s) value at the specified index in the array at path (<https://redis.io/commands/json.arrinsert>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the array, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonArrinsert
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the array.
    -> Integer -- ^ Insertion index.
    -> NonEmpty ByteString -- ^ Serialized JSON values to insert.
    -> m (f Reply)
jsonArrinsert :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> Integer -> NonEmpty ByteString -> m (f Reply)
jsonArrinsert ByteString
key ByteString
path Integer
index NonEmpty ByteString
values =
    [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Reply)) -> [ByteString] -> m (f Reply)
forall a b. (a -> b) -> a -> b
$ [ByteString
"JSON.ARRINSERT", ByteString
key, ByteString
path, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
index] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ByteString
values

-- |Removes and returns the element at the end of the array at the root path (<https://redis.io/commands/json.arrpop>).
--
-- /O(1)/ when the popped item is the last element, otherwise /O(N)/ where /N/ is the size of the array
--
-- Since RedisJSON 1.0.0
jsonArrpop
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Reply)
jsonArrpop :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Reply)
jsonArrpop ByteString
key = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.ARRPOP", ByteString
key]

-- |Removes and returns the element at the end of the array at path (<https://redis.io/commands/json.arrpop>).
--
-- The reply shape depends on the path syntax and popped value type, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when the popped item is the last element, otherwise /O(N)/ where /N/ is the size of the array
--
-- Since RedisJSON 1.0.0
jsonArrpopAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the array.
    -> m (f Reply)
jsonArrpopAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonArrpopAt ByteString
key ByteString
path = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.ARRPOP", ByteString
key, ByteString
path]

-- |Removes and returns the element at the specified index in the array at path (<https://redis.io/commands/json.arrpop>).
--
-- The reply shape depends on the path syntax and popped value type, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when the specified index is not the last element, otherwise /O(1)/
--
-- Since RedisJSON 1.0.0
jsonArrpopAtIndex
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the array.
    -> Integer -- ^ Index to pop.
    -> m (f Reply)
jsonArrpopAtIndex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> Integer -> m (f Reply)
jsonArrpopAtIndex ByteString
key ByteString
path Integer
index =
    [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.ARRPOP", ByteString
key, ByteString
path, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
index]

-- |Trims the array at path to contain only the specified inclusive range of indices from start to stop (<https://redis.io/commands/json.arrtrim>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the array, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonArrtrim
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the array.
    -> Integer -- ^ Start index.
    -> Integer -- ^ Stop index.
    -> m (f Reply)
jsonArrtrim :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> Integer -> Integer -> m (f Reply)
jsonArrtrim ByteString
key ByteString
path Integer
start Integer
stop =
    [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.ARRTRIM", ByteString
key, ByteString
path, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
stop]

-- |Clears all values from an array or an object and sets numeric values at the root path to @0@ (<https://redis.io/commands/json.clear>).
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the values, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 2.0.0
jsonClear
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Integer)
jsonClear :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
jsonClear ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.CLEAR", ByteString
key]

-- |Clears all values from an array or an object and sets numeric values at path to @0@ (<https://redis.io/commands/json.clear>).
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the values, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 2.0.0
jsonClearAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to clear.
    -> m (f Integer)
jsonClearAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Integer)
jsonClearAt ByteString
key ByteString
path = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.CLEAR", ByteString
key, ByteString
path]

-- |Executes the JSON debug container command (<https://redis.io/commands/json.debug>).
--
-- This is a container command for debugging related tasks.
--
-- N\/A
--
-- Since RedisJSON 1.0.0
jsonDebug
    :: (RedisCtx m f)
    => m (f Reply)
jsonDebug :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Reply)
jsonDebug = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.DEBUG"]

-- |Reports the size in bytes of a key at the root path (<https://redis.io/commands/json.debug-memory>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value, where /N/ is the size of the value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonDebugMemory
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Reply)
jsonDebugMemory :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Reply)
jsonDebugMemory ByteString
key = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.DEBUG", ByteString
"MEMORY", ByteString
key]

-- |Reports the size in bytes of a key at path (<https://redis.io/commands/json.debug-memory>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value, where /N/ is the size of the value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonDebugMemoryAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to inspect.
    -> m (f Reply)
jsonDebugMemoryAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonDebugMemoryAt ByteString
key ByteString
path = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.DEBUG", ByteString
"MEMORY", ByteString
key, ByteString
path]

-- |Deletes a value at the root path (<https://redis.io/commands/json.del>).
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the deleted value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonDel
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Integer)
jsonDel :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
jsonDel ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.DEL", ByteString
key]

-- |Deletes a value at path (<https://redis.io/commands/json.del>).
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the deleted value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonDelAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to delete.
    -> m (f Integer)
jsonDelAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Integer)
jsonDelAt ByteString
key ByteString
path = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.DEL", ByteString
key, ByteString
path]

-- |Deletes a value at the root path (<https://redis.io/commands/json.forget>).
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the deleted value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonForget
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Integer)
jsonForget :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
jsonForget ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.FORGET", ByteString
key]

-- |Deletes a value at path (<https://redis.io/commands/json.forget>).
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the deleted value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonForgetAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to delete.
    -> m (f Integer)
jsonForgetAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Integer)
jsonForgetAt ByteString
key ByteString
path = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.FORGET", ByteString
key, ByteString
path]

-- |Gets the value at the root path in JSON serialized form (<https://redis.io/commands/json.get>).
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonGet
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f (Maybe ByteString))
jsonGet :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
jsonGet ByteString
key = ByteString -> JSONGetOpts -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> JSONGetOpts -> m (f (Maybe ByteString))
jsonGetOpts ByteString
key JSONGetOpts
defaultJSONGetOpts

-- |Gets the value at one or more paths in JSON serialized form (<https://redis.io/commands/json.get>).
--
-- /O(N)/ when path is evaluated to a single value where /N/ is the size of the value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonGetOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> JSONGetOpts -- ^ Formatting and path selection options.
    -> m (f (Maybe ByteString))
jsonGetOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> JSONGetOpts -> m (f (Maybe ByteString))
jsonGetOpts ByteString
key JSONGetOpts
opts =
    [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe ByteString)))
-> [ByteString] -> m (f (Maybe ByteString))
forall a b. (a -> b) -> a -> b
$ [ByteString
"JSON.GET", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ JSONGetOpts -> [ByteString]
jsonGetOptsToArgs JSONGetOpts
opts

-- |Merges a given JSON value into matching paths (<https://redis.io/commands/json.merge>).
--
-- Consequently, JSON values at matching paths are updated, deleted, or expanded with new children.
--
-- /O(M+N)/ when path is evaluated to a single value where /M/ is the size of the original value and /N/ is the size of the new value, /O(M+N)/ when path is evaluated to multiple values where /M/ is the size of the key and /N/ is the size of the new value times the number of matches
--
-- Since RedisJSON 2.6.0
jsonMerge
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to merge into.
    -> ByteString -- ^ Serialized JSON value.
    -> m (f Status)
jsonMerge :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Status)
jsonMerge ByteString
key ByteString
path ByteString
value = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.MERGE", ByteString
key, ByteString
path, ByteString
value]

-- |Returns the values at a path from one or more keys (<https://redis.io/commands/json.mget>).
--
-- /O(M*N)/ when path is evaluated to a single value where /M/ is the number of keys and /N/ is the size of the value, /O(N1+N2+\dots+Nm)/ when path is evaluated to multiple values
--
-- Since RedisJSON 1.0.0
jsonMget
    :: (RedisCtx m f)
    => NonEmpty ByteString -- ^ Keys holding JSON values.
    -> ByteString -- ^ Path to fetch from each key.
    -> m (f [Maybe ByteString])
jsonMget :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> ByteString -> m (f [Maybe ByteString])
jsonMget NonEmpty ByteString
keys ByteString
path = [ByteString] -> m (f [Maybe ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [Maybe ByteString]))
-> [ByteString] -> m (f [Maybe ByteString])
forall a b. (a -> b) -> a -> b
$ ByteString
"JSON.MGET" ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: NonEmpty ByteString -> [ByteString]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ByteString
keys [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
path]

-- |Sets or updates the JSON value of one or more keys (<https://redis.io/commands/json.mset>).
--
-- /O(K*(M+N))/ where /K/ is the number of keys in the command
--
-- Since RedisJSON 2.6.0
jsonMset
    :: (RedisCtx m f)
    => NonEmpty (ByteString, ByteString, ByteString) -- ^ Key, path, serialized JSON value triplets.
    -> m (f Status)
jsonMset :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty (ByteString, ByteString, ByteString) -> m (f Status)
jsonMset NonEmpty (ByteString, ByteString, ByteString)
triplets =
    [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Status)) -> [ByteString] -> m (f Status)
forall a b. (a -> b) -> a -> b
$ ByteString
"JSON.MSET" ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ((ByteString, ByteString, ByteString) -> [ByteString])
-> [(ByteString, ByteString, ByteString)] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (ByteString, ByteString, ByteString) -> [ByteString]
forall {a}. (a, a, a) -> [a]
encodeTriplet (NonEmpty (ByteString, ByteString, ByteString)
-> [(ByteString, ByteString, ByteString)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (ByteString, ByteString, ByteString)
triplets)
  where
    encodeTriplet :: (a, a, a) -> [a]
encodeTriplet (a
key, a
path, a
value) = [a
key, a
path, a
value]

-- |Increments the numeric value at path by a value (<https://redis.io/commands/json.numincrby>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonNumincrby
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the numeric value.
    -> Double -- ^ Increment value.
    -> m (f Reply)
jsonNumincrby :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> Double -> m (f Reply)
jsonNumincrby ByteString
key ByteString
path Double
value =
    [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.NUMINCRBY", ByteString
key, ByteString
path, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
value]

-- |Multiplies the numeric value at path by a value (<https://redis.io/commands/json.nummultby>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonNummultby
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the numeric value.
    -> Double -- ^ Multiplier value.
    -> m (f Reply)
jsonNummultby :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> Double -> m (f Reply)
jsonNummultby ByteString
key ByteString
path Double
value =
    [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.NUMMULTBY", ByteString
key, ByteString
path, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
value]

-- |Returns the key names of JSON objects at the root path (<https://redis.io/commands/json.objkeys>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value, where /N/ is the number of keys in the object, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonObjkeys
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Reply)
jsonObjkeys :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Reply)
jsonObjkeys ByteString
key = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.OBJKEYS", ByteString
key]

-- |Returns the key names of JSON objects at path (<https://redis.io/commands/json.objkeys>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value, where /N/ is the number of keys in the object, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonObjkeysAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the object.
    -> m (f Reply)
jsonObjkeysAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonObjkeysAt ByteString
key ByteString
path = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.OBJKEYS", ByteString
key, ByteString
path]

-- |Returns the number of keys in JSON objects at the root path (<https://redis.io/commands/json.objlen>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonObjlen
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Reply)
jsonObjlen :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Reply)
jsonObjlen ByteString
key = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.OBJLEN", ByteString
key]

-- |Returns the number of keys in JSON objects at path (<https://redis.io/commands/json.objlen>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonObjlenAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the object.
    -> m (f Reply)
jsonObjlenAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonObjlenAt ByteString
key ByteString
path = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.OBJLEN", ByteString
key, ByteString
path]

-- |Returns the JSON value at the root path in Redis Serialization Protocol (RESP) (<https://redis.io/commands/json.resp>).
--
-- The reply may be any RESP shape depending on the JSON value, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value, where /N/ is the size of the value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonResp
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Reply)
jsonResp :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Reply)
jsonResp ByteString
key = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.RESP", ByteString
key]

-- |Returns the JSON value at path in Redis Serialization Protocol (RESP) (<https://redis.io/commands/json.resp>).
--
-- The reply may be any RESP shape depending on the JSON value, so this wrapper returns the raw 'Reply'.
--
-- /O(N)/ when path is evaluated to a single value, where /N/ is the size of the value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonRespAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to inspect.
    -> m (f Reply)
jsonRespAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonRespAt ByteString
key ByteString
path = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.RESP", ByteString
key, ByteString
path]

-- |Sets or updates the JSON value at a path (<https://redis.io/commands/json.set>).
--
-- $O(M+N)$ when path is evaluated to a single value where $M$ is the size of the original value and $N$ is the size of the new value, $O(M+N)$ when path is evaluated to multiple values where $M$ is the size of the key and $N$ is the size of the new value times the number of matches
--
-- Since RedisJSON 1.0.0
jsonSet
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to set.
    -> ByteString -- ^ Serialized JSON value.
    -> m (f (Maybe Status))
jsonSet :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f (Maybe Status))
jsonSet ByteString
key ByteString
path ByteString
value = ByteString
-> ByteString -> ByteString -> JSONSetOpts -> m (f (Maybe Status))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> JSONSetOpts -> m (f (Maybe Status))
jsonSetOpts ByteString
key ByteString
path ByteString
value JSONSetOpts
defaultJSONSetOpts

-- |Sets or updates the JSON value at a path (<https://redis.io/commands/json.set>).
--
-- /O(M+N)/ when path is evaluated to a single value where /M/ is the size of the original value and /N/ is the size of the new value, /O(M+N)/ when path is evaluated to multiple values where /M/ is the size of the key and /N/ is the size of the new value times the number of matches
--
-- Since RedisJSON 1.0.0
jsonSetOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to set.
    -> ByteString -- ^ Serialized JSON value.
    -> JSONSetOpts -- ^ Conditional and FPHA options.
    -> m (f (Maybe Status))
jsonSetOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> JSONSetOpts -> m (f (Maybe Status))
jsonSetOpts ByteString
key ByteString
path ByteString
value JSONSetOpts
opts =
    [ByteString] -> m (f (Maybe Status))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe Status)))
-> [ByteString] -> m (f (Maybe Status))
forall a b. (a -> b) -> a -> b
$ [ByteString
"JSON.SET", ByteString
key, ByteString
path, ByteString
value] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ JSONSetOpts -> [ByteString]
jsonSetOptsToArgs JSONSetOpts
opts

-- |Appends a string to JSON strings at the root path (<https://redis.io/commands/json.strappend>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonStrappend
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ String value to append.
    -> m (f Reply)
jsonStrappend :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonStrappend ByteString
key ByteString
value = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.STRAPPEND", ByteString
key, ByteString
value]

-- |Appends a string to JSON strings at path (<https://redis.io/commands/json.strappend>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonStrappendAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the JSON string.
    -> ByteString -- ^ String value to append.
    -> m (f Reply)
jsonStrappendAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Reply)
jsonStrappendAt ByteString
key ByteString
path ByteString
value = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.STRAPPEND", ByteString
key, ByteString
path, ByteString
value]

-- |Toggles a boolean value (<https://redis.io/commands/json.toggle>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 2.0.0
jsonToggle
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to the boolean value.
    -> m (f Reply)
jsonToggle :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonToggle ByteString
key ByteString
path = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.TOGGLE", ByteString
key, ByteString
path]

-- |Returns the type of the JSON value at the root path (<https://redis.io/commands/json.type>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonType
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> m (f Reply)
jsonType :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Reply)
jsonType ByteString
key = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.TYPE", ByteString
key]

-- |Returns the type of the JSON value at path (<https://redis.io/commands/json.type>).
--
-- The reply shape depends on the path syntax, so this wrapper returns the raw 'Reply'.
--
-- /O(1)/ when path is evaluated to a single value, /O(N)/ when path is evaluated to multiple values, where /N/ is the size of the key
--
-- Since RedisJSON 1.0.0
jsonTypeAt
    :: (RedisCtx m f)
    => ByteString -- ^ Key holding a JSON value.
    -> ByteString -- ^ Path to inspect.
    -> m (f Reply)
jsonTypeAt :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Reply)
jsonTypeAt ByteString
key ByteString
path = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"JSON.TYPE", ByteString
key, ByteString
path]