{-# LANGUAGE CPP, OverloadedStrings, RecordWildCards, FlexibleContexts #-}

module Database.Redis.ManualCommands where

import Prelude hiding (min, max)
import Data.ByteString (ByteString, empty, append)
import qualified Data.ByteString.Char8 as Char8
import qualified Data.ByteString as BS
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NE
import Data.Maybe (maybeToList, catMaybes, fromMaybe)
#if __GLASGOW_HASKELL__ < 808
import Data.Semigroup ((<>))
#endif



import Database.Redis.Core
import Database.Redis.Protocol
import Database.Redis.Types
import qualified Database.Redis.Cluster.Command as CMD

-- |Inspect the internals of Redis objects (<http://redis.io/commands/object>). The Redis command @OBJECT@ is split up into 'objectRefcount', 'objectEncoding', 'objectIdletime'. Since Redis 2.2.3
objectRefcount
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> m (f Integer)
objectRefcount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
objectRefcount ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"OBJECT", ByteString
"refcount", ByteString
key]

-- |Inspect the internals of Redis objects (<http://redis.io/commands/object>). The Redis command @OBJECT@ is split up into 'objectRefcount', 'objectEncoding', 'objectIdletime'. Since Redis 2.2.3
objectIdletime
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> m (f Integer)
objectIdletime :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
objectIdletime ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"OBJECT", ByteString
"idletime", ByteString
key]

-- |Inspect the internals of Redis objects (<http://redis.io/commands/object>). The Redis command @OBJECT@ is split up into 'objectRefcount', 'objectEncoding', 'objectIdletime'. Since Redis 2.2.3
objectEncoding
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> m (f ByteString)
objectEncoding :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f ByteString)
objectEncoding ByteString
key = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"OBJECT", ByteString
"encoding", ByteString
key]

-- |Insert an element before or after another element in a list (<http://redis.io/commands/linsert>). The Redis command @LINSERT@ is split up into 'linsertBefore', 'linsertAfter'. Since Redis 2.2.0
linsertBefore
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> ByteString -- ^ pivot
    -> ByteString -- ^ value
    -> m (f Integer)
linsertBefore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Integer)
linsertBefore ByteString
key ByteString
pivot ByteString
value =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"LINSERT", ByteString
key, ByteString
"BEFORE", ByteString
pivot, ByteString
value]

-- |Insert an element before or after another element in a list (<http://redis.io/commands/linsert>). The Redis command @LINSERT@ is split up into 'linsertBefore', 'linsertAfter'. Since Redis 2.2.0
linsertAfter
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> ByteString -- ^ pivot
    -> ByteString -- ^ value
    -> m (f Integer)
linsertAfter :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Integer)
linsertAfter ByteString
key ByteString
pivot ByteString
value =
        [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"LINSERT", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, ByteString
"AFTER", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
pivot, ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
value]

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

instance RedisArg ListDirection where
    encode :: ListDirection -> ByteString
encode ListDirection
ListLeft = ByteString
"LEFT"
    encode ListDirection
ListRight = ByteString
"RIGHT"

data LPosOpts = LPosOpts
    { LPosOpts -> Maybe Integer
lposRank :: Maybe Integer
    , LPosOpts -> Maybe Integer
lposMaxlen :: Maybe Integer
    } deriving (Int -> LPosOpts -> ShowS
[LPosOpts] -> ShowS
LPosOpts -> String
(Int -> LPosOpts -> ShowS)
-> (LPosOpts -> String) -> ([LPosOpts] -> ShowS) -> Show LPosOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LPosOpts -> ShowS
showsPrec :: Int -> LPosOpts -> ShowS
$cshow :: LPosOpts -> String
show :: LPosOpts -> String
$cshowList :: [LPosOpts] -> ShowS
showList :: [LPosOpts] -> ShowS
Show, LPosOpts -> LPosOpts -> Bool
(LPosOpts -> LPosOpts -> Bool)
-> (LPosOpts -> LPosOpts -> Bool) -> Eq LPosOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LPosOpts -> LPosOpts -> Bool
== :: LPosOpts -> LPosOpts -> Bool
$c/= :: LPosOpts -> LPosOpts -> Bool
/= :: LPosOpts -> LPosOpts -> Bool
Eq)

defaultLPosOpts :: LPosOpts
defaultLPosOpts :: LPosOpts
defaultLPosOpts = LPosOpts
    { lposRank :: Maybe Integer
lposRank = Maybe Integer
forall a. Maybe a
Nothing -- ^ The RANK option specifies the "rank" of the first element to return, in case there are multiple matches. A rank of 1 means to return the first match, 2 to return the second match, and so forth.
    , lposMaxlen :: Maybe Integer
lposMaxlen = Maybe Integer
forall a. Maybe a
Nothing -- ^ The MAXLEN option limits the number of elements to examine, which can improve performance for large lists.
    }

-- |Returns the index of the first matching element in a list (<https://redis.io/commands/lpos>).
--
-- /O(N)/ where /N/ is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time.
--
-- Since Redis 6.0.6
lpos
    :: (RedisCtx m f)
    => ByteString
    -> ByteString
    -> m (f (Maybe Integer))
lpos :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f (Maybe Integer))
lpos ByteString
key ByteString
element = ByteString -> ByteString -> LPosOpts -> m (f (Maybe Integer))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> LPosOpts -> m (f (Maybe Integer))
lposOpts ByteString
key ByteString
element LPosOpts
defaultLPosOpts

-- |Returns the index of the first matching element in a list (<https://redis.io/commands/lpos>).
--
-- /O(N)/ where /N/ is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time.
--
-- Since Redis 6.0.6
lposOpts
    :: (RedisCtx m f)
    => ByteString
    -> ByteString
    -> LPosOpts
    -> m (f (Maybe Integer))
lposOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> LPosOpts -> m (f (Maybe Integer))
lposOpts ByteString
key ByteString
element LPosOpts
opts =
    [ByteString] -> m (f (Maybe Integer))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe Integer)))
-> [ByteString] -> m (f (Maybe Integer))
forall a b. (a -> b) -> a -> b
$ [ByteString
"LPOS", ByteString
key, ByteString
element] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ LPosOpts -> [ByteString]
lposOptsToArgs LPosOpts
opts

-- |Returns the indexes of matching elements in a list (<https://redis.io/commands/lpos>).
--
-- /O(N)/ where /N/ is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time.
--
-- Since Redis 6.0.6
lposCount
    :: (RedisCtx m f)
    => ByteString
    -> ByteString
    -> Integer
    -> m (f [Integer])
lposCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> Integer -> m (f [Integer])
lposCount ByteString
key ByteString
element Integer
count = ByteString -> ByteString -> Integer -> LPosOpts -> m (f [Integer])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> Integer -> LPosOpts -> m (f [Integer])
lposCountOpts ByteString
key ByteString
element Integer
count LPosOpts
defaultLPosOpts

-- |Returns the indexes of matching elements in a list (<https://redis.io/commands/lpos>).
--
-- /O(N)/ where /N/ is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time.
--
-- Since Redis 6.0.6
lposCountOpts
    :: (RedisCtx m f)
    => ByteString
    -> ByteString
    -> Integer
    -> LPosOpts
    -> m (f [Integer])
lposCountOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> Integer -> LPosOpts -> m (f [Integer])
lposCountOpts ByteString
key ByteString
element Integer
count LPosOpts
opts =
    [ByteString] -> m (f [Integer])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [Integer]))
-> [ByteString] -> m (f [Integer])
forall a b. (a -> b) -> a -> b
$ [ByteString
"LPOS", ByteString
key, ByteString
element] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
rankArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
maxlenArg
  where
    ([ByteString]
rankArg, [ByteString]
maxlenArg) = LPosOpts -> ([ByteString], [ByteString])
lposOptsParts LPosOpts
opts

lposOptsToArgs :: LPosOpts -> [ByteString]
lposOptsToArgs :: LPosOpts -> [ByteString]
lposOptsToArgs LPosOpts
opts =
    [ByteString]
rankArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
maxlenArg
  where
    ([ByteString]
rankArg, [ByteString]
maxlenArg) = LPosOpts -> ([ByteString], [ByteString])
lposOptsParts LPosOpts
opts

lposOptsParts :: LPosOpts -> ([ByteString], [ByteString])
lposOptsParts :: LPosOpts -> ([ByteString], [ByteString])
lposOptsParts LPosOpts{Maybe Integer
lposRank :: LPosOpts -> Maybe Integer
lposMaxlen :: LPosOpts -> Maybe Integer
lposRank :: Maybe Integer
lposMaxlen :: Maybe Integer
..} =
    ( [ByteString]
rankArg
    , [ByteString]
maxlenArg
    )
  where
    rankArg :: [ByteString]
rankArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
rank -> [ByteString
"RANK", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
rank]) Maybe Integer
lposRank
    maxlenArg :: [ByteString]
maxlenArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
maxlen -> [ByteString
"MAXLEN", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
maxlen]) Maybe Integer
lposMaxlen

-- |Move an element after taking it from one list and pushing it to another (<https://redis.io/commands/lmove>).
--
-- In clustered environments source and destination keys must be in the same hash slot, which can be ensured by using hash tags (e.g. @{tag}source@ and @{tag}destination@).
-- /O(1)/
--
-- Since Redis 6.2.0
lmove
    :: (RedisCtx m f)
    => ByteString    -- ^ Source
    -> ByteString    -- ^ Destination
    -> ListDirection -- ^ Direction where to get the element from in the source list
    -> ListDirection -- ^ Direction where to push the element to in the destination list
    -> m (f (Maybe ByteString))
lmove :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ListDirection
-> ListDirection
-> m (f (Maybe ByteString))
lmove ByteString
source ByteString
destination ListDirection
from ListDirection
to =
    [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"LMOVE", ByteString
source, ByteString
destination, ListDirection -> ByteString
forall a. RedisArg a => a -> ByteString
encode ListDirection
from, ListDirection -> ByteString
forall a. RedisArg a => a -> ByteString
encode ListDirection
to]

-- |Move an element after taking it from one list and pushing it to another, or blocks until one is available (<https://redis.io/commands/blmove>).
--
-- In clustered environments source and destination keys must be in the same hash slot, which can be ensured by using hash tags (e.g. @{tag}source@ and @{tag}destination@).
--
-- /O(1)/
--
-- Since Redis 6.2.0
blmove
    :: (RedisCtx m f)
    => ByteString    -- ^ Source
    -> ByteString    -- ^ Destination
    -> ListDirection -- ^ Direction where to get the element from in the source list
    -> ListDirection -- ^ Direction where to push the element to in the destination list
    -> Integer
    -> m (f (Maybe ByteString))
blmove :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ListDirection
-> ListDirection
-> Integer
-> m (f (Maybe ByteString))
blmove ByteString
source ByteString
destination ListDirection
from ListDirection
to Integer
timeout =
    [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"BLMOVE", ByteString
source, ByteString
destination, ListDirection -> ByteString
forall a. RedisArg a => a -> ByteString
encode ListDirection
from, ListDirection -> ByteString
forall a. RedisArg a => a -> ByteString
encode ListDirection
to, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
timeout]

-- |Pops one or more elements from the first non-empty list from a list of keys (<https://redis.io/commands/lmpop>).
--
-- /O(N+M)/ where /N/ is the number of provided keys and /M/ is the number of elements returned.
--
-- Since Redis 7.0.0
lmpop
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> ListDirection
    -> m (f (Maybe (ByteString, [ByteString])))
lmpop :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ListDirection -> m (f (Maybe (ByteString, [ByteString])))
lmpop NonEmpty ByteString
keys ListDirection
direction = NonEmpty ByteString
-> ListDirection
-> Integer
-> m (f (Maybe (ByteString, [ByteString])))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ListDirection
-> Integer
-> m (f (Maybe (ByteString, [ByteString])))
lmpopCount NonEmpty ByteString
keys ListDirection
direction Integer
1

-- |Pops one or more elements from the first non-empty list from a list of keys (<https://redis.io/commands/lmpop>).
--
-- /O(N+M)/ where /N/ is the number of provided keys and /M/ is the number of elements returned.
--
-- Since Redis 7.0.0
lmpopCount
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> ListDirection
    -> Integer
    -> m (f (Maybe (ByteString, [ByteString])))
lmpopCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ListDirection
-> Integer
-> m (f (Maybe (ByteString, [ByteString])))
lmpopCount NonEmpty ByteString
keys ListDirection
direction Integer
count =
    [ByteString] -> m (f (Maybe (ByteString, [ByteString])))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe (ByteString, [ByteString]))))
-> [ByteString] -> m (f (Maybe (ByteString, [ByteString])))
forall a b. (a -> b) -> a -> b
$ [ByteString
"LMPOP", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty ByteString -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty ByteString
keys)] [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]
++ [ListDirection -> ByteString
forall a. RedisArg a => a -> ByteString
encode ListDirection
direction, ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Pops one or more elements from the first non-empty list from a list of keys, or blocks until one is available (<https://redis.io/commands/blmpop>).
--
-- /O(N+M)/ where /N/ is the number of provided keys and /M/ is the number of elements returned.
--
-- Since Redis 7.0.0
blmpop
    :: (RedisCtx m f)
    => Double
    -> NonEmpty ByteString
    -> ListDirection
    -> m (f (Maybe (ByteString, [ByteString])))
blmpop :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Double
-> NonEmpty ByteString
-> ListDirection
-> m (f (Maybe (ByteString, [ByteString])))
blmpop Double
timeout NonEmpty ByteString
keys ListDirection
direction = Double
-> NonEmpty ByteString
-> ListDirection
-> Integer
-> m (f (Maybe (ByteString, [ByteString])))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Double
-> NonEmpty ByteString
-> ListDirection
-> Integer
-> m (f (Maybe (ByteString, [ByteString])))
blmpopCount Double
timeout NonEmpty ByteString
keys ListDirection
direction Integer
1

-- |Pops one or more elements from the first non-empty list from a list of keys, or blocks until one is available (<https://redis.io/commands/blmpop>).
--
-- /O(N+M)/ where /N/ is the number of provided keys and /M/ is the number of elements returned.
--
-- Since Redis 7.0.0
blmpopCount
    :: (RedisCtx m f)
    => Double
    -> NonEmpty ByteString
    -> ListDirection
    -> Integer
    -> m (f (Maybe (ByteString, [ByteString])))
blmpopCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Double
-> NonEmpty ByteString
-> ListDirection
-> Integer
-> m (f (Maybe (ByteString, [ByteString])))
blmpopCount Double
timeout NonEmpty ByteString
keys ListDirection
direction Integer
count =
    [ByteString] -> m (f (Maybe (ByteString, [ByteString])))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe (ByteString, [ByteString]))))
-> [ByteString] -> m (f (Maybe (ByteString, [ByteString])))
forall a b. (a -> b) -> a -> b
$ [ByteString
"BLMPOP", Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
timeout, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty ByteString -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty ByteString
keys)] [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]
++ [ListDirection -> ByteString
forall a. RedisArg a => a -> ByteString
encode ListDirection
direction, ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Determine the type stored at key (<http://redis.io/commands/type>). Since Redis 1.0.0
getType
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> m (f RedisType)
getType :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f RedisType)
getType ByteString
key = [ByteString] -> m (f RedisType)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"TYPE", ByteString
key]

-- |A single entry from the slowlog.
data Slowlog = Slowlog
    { Slowlog -> Integer
slowlogId        :: Integer
      -- ^ A unique progressive identifier for every slow log entry.
    , Slowlog -> Integer
slowlogTimestamp :: Integer
      -- ^ The unix timestamp at which the logged command was processed.
    , Slowlog -> Integer
slowlogMicros    :: Integer
      -- ^ The amount of time needed for its execution, in microseconds.
    , Slowlog -> [ByteString]
slowlogCmd       :: [ByteString]
      -- ^ The command and it's arguments.
    , Slowlog -> Maybe ByteString
slowlogClientIpAndPort :: Maybe ByteString
    , Slowlog -> Maybe ByteString
slowlogClientName :: Maybe ByteString
    } deriving (Int -> Slowlog -> ShowS
[Slowlog] -> ShowS
Slowlog -> String
(Int -> Slowlog -> ShowS)
-> (Slowlog -> String) -> ([Slowlog] -> ShowS) -> Show Slowlog
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Slowlog -> ShowS
showsPrec :: Int -> Slowlog -> ShowS
$cshow :: Slowlog -> String
show :: Slowlog -> String
$cshowList :: [Slowlog] -> ShowS
showList :: [Slowlog] -> ShowS
Show, Slowlog -> Slowlog -> Bool
(Slowlog -> Slowlog -> Bool)
-> (Slowlog -> Slowlog -> Bool) -> Eq Slowlog
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Slowlog -> Slowlog -> Bool
== :: Slowlog -> Slowlog -> Bool
$c/= :: Slowlog -> Slowlog -> Bool
/= :: Slowlog -> Slowlog -> Bool
Eq)

instance RedisResult Slowlog where
    decode :: Reply -> Either Reply Slowlog
decode (MultiBulk (Just [Reply
logId,Reply
timestamp,Reply
micros,Reply
cmd])) = do
        slowlogId        <- Reply -> Either Reply Integer
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
logId
        slowlogTimestamp <- decode timestamp
        slowlogMicros    <- decode micros
        slowlogCmd       <- decode cmd
        let slowlogClientIpAndPort = Maybe a
forall a. Maybe a
Nothing
            slowlogClientName = Maybe a
forall a. Maybe a
Nothing
        return Slowlog{..}
    decode (MultiBulk (Just [Reply
logId,Reply
timestamp,Reply
micros,Reply
cmd,Reply
ip,Reply
cname])) = do
        slowlogId        <- Reply -> Either Reply Integer
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
logId
        slowlogTimestamp <- decode timestamp
        slowlogMicros    <- decode micros
        slowlogCmd       <- decode cmd
        slowlogClientIpAndPort <- Just <$> decode ip
        slowlogClientName <- Just <$> decode cname
        return Slowlog{..}
    decode Reply
r = Reply -> Either Reply Slowlog
forall a b. a -> Either a b
Left Reply
r

slowlogGet
    :: (RedisCtx m f)
    => Integer -- ^ cnt
    -> m (f [Slowlog])
slowlogGet :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Integer -> m (f [Slowlog])
slowlogGet Integer
n = [ByteString] -> m (f [Slowlog])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SLOWLOG", ByteString
"GET", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
n]

slowlogLen :: (RedisCtx m f) => m (f Integer)
slowlogLen :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Integer)
slowlogLen = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SLOWLOG", ByteString
"LEN"]

slowlogReset :: (RedisCtx m f) => m (f Status)
slowlogReset :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Status)
slowlogReset = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SLOWLOG", ByteString
"RESET"]

-- |Return a range of members in a sorted set, by index (<http://redis.io/commands/zrange>). The Redis command @ZRANGE@ is split up into 'zrange', 'zrangeWithscores'. Since Redis 1.2.0
zrange
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ start
    -> Integer -- ^ stop
    -> m (f [ByteString])
zrange :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> Integer -> m (f [ByteString])
zrange ByteString
key Integer
start Integer
stop =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANGE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
stop]

-- |Return a range of members in a sorted set, by index (<http://redis.io/commands/zrange>). The Redis command @ZRANGE@ is split up into 'zrange', 'zrangeWithscores'. Since Redis 1.2.0
zrangeWithscores
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ start
    -> Integer -- ^ stop
    -> m (f [(ByteString, Double)])
zrangeWithscores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> Integer -> m (f [(ByteString, Double)])
zrangeWithscores ByteString
key Integer
start Integer
stop =
    [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANGE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
stop, ByteString
"WITHSCORES"]

zrevrange
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ start
    -> Integer -- ^ stop
    -> m (f [ByteString])
zrevrange :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> Integer -> m (f [ByteString])
zrevrange ByteString
key Integer
start Integer
stop =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZREVRANGE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
stop]

zrevrangeWithscores
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ start
    -> Integer -- ^ stop
    -> m (f [(ByteString, Double)])
zrevrangeWithscores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> Integer -> m (f [(ByteString, Double)])
zrevrangeWithscores ByteString
key Integer
start Integer
stop =
    [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZREVRANGE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
stop
                ,ByteString
"WITHSCORES"]

zrangebyscore
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Double -- ^ min
    -> Double -- ^ max
    -> m (f [ByteString])
zrangebyscore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Double -> Double -> m (f [ByteString])
zrangebyscore ByteString
key Double
min Double
max =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANGEBYSCORE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
min, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
max]

zrangebyscoreWithscores
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Double -- ^ min
    -> Double -- ^ max
    -> m (f [(ByteString, Double)])
zrangebyscoreWithscores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Double -> Double -> m (f [(ByteString, Double)])
zrangebyscoreWithscores ByteString
key Double
min Double
max =
    [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANGEBYSCORE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
min, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
max
                ,ByteString
"WITHSCORES"]

zrangebyscoreLimit
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Double -- ^ min
    -> Double -- ^ max
    -> Integer -- ^ offset
    -> Integer -- ^ count
    -> m (f [ByteString])
zrangebyscoreLimit :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Double -> Double -> Integer -> Integer -> m (f [ByteString])
zrangebyscoreLimit ByteString
key Double
min Double
max Integer
offset Integer
count =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANGEBYSCORE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
min, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
max
                ,ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
offset, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

zrangebyscoreWithscoresLimit
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Double -- ^ min
    -> Double -- ^ max
    -> Integer -- ^ offset
    -> Integer -- ^ count
    -> m (f [(ByteString, Double)])
zrangebyscoreWithscoresLimit :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Double
-> Double
-> Integer
-> Integer
-> m (f [(ByteString, Double)])
zrangebyscoreWithscoresLimit ByteString
key Double
min Double
max Integer
offset Integer
count =
    [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANGEBYSCORE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
min, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
max
                ,ByteString
"WITHSCORES",ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
offset, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

zrevrangebyscore
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Double -- ^ max
    -> Double -- ^ min
    -> m (f [ByteString])
zrevrangebyscore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Double -> Double -> m (f [ByteString])
zrevrangebyscore ByteString
key Double
min Double
max =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZREVRANGEBYSCORE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
min, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
max]

zrevrangebyscoreWithscores
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Double -- ^ max
    -> Double -- ^ min
    -> m (f [(ByteString, Double)])
zrevrangebyscoreWithscores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Double -> Double -> m (f [(ByteString, Double)])
zrevrangebyscoreWithscores ByteString
key Double
min Double
max =
    [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZREVRANGEBYSCORE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
min, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
max
                ,ByteString
"WITHSCORES"]

zrevrangebyscoreLimit
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Double -- ^ max
    -> Double -- ^ min
    -> Integer -- ^ offset
    -> Integer -- ^ count
    -> m (f [ByteString])
zrevrangebyscoreLimit :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Double -> Double -> Integer -> Integer -> m (f [ByteString])
zrevrangebyscoreLimit ByteString
key Double
min Double
max Integer
offset Integer
count =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZREVRANGEBYSCORE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
min, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
max
                ,ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
offset, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

zrevrangebyscoreWithscoresLimit
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Double -- ^ max
    -> Double -- ^ min
    -> Integer -- ^ offset
    -> Integer -- ^ count
    -> m (f [(ByteString, Double)])
zrevrangebyscoreWithscoresLimit :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Double
-> Double
-> Integer
-> Integer
-> m (f [(ByteString, Double)])
zrevrangebyscoreWithscoresLimit ByteString
key Double
min Double
max Integer
offset Integer
count =
    [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZREVRANGEBYSCORE", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
min, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
max
                ,ByteString
"WITHSCORES",ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
offset, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Options for the 'sort' command.
data SortOpts = SortOpts
    { SortOpts -> Maybe ByteString
sortBy     :: Maybe ByteString
    , SortOpts -> (Integer, Integer)
sortLimit  :: (Integer,Integer)
    , SortOpts -> [ByteString]
sortGet    :: [ByteString]
    , SortOpts -> SortOrder
sortOrder  :: SortOrder
    , SortOpts -> Bool
sortAlpha  :: Bool
    } deriving (Int -> SortOpts -> ShowS
[SortOpts] -> ShowS
SortOpts -> String
(Int -> SortOpts -> ShowS)
-> (SortOpts -> String) -> ([SortOpts] -> ShowS) -> Show SortOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SortOpts -> ShowS
showsPrec :: Int -> SortOpts -> ShowS
$cshow :: SortOpts -> String
show :: SortOpts -> String
$cshowList :: [SortOpts] -> ShowS
showList :: [SortOpts] -> ShowS
Show, SortOpts -> SortOpts -> Bool
(SortOpts -> SortOpts -> Bool)
-> (SortOpts -> SortOpts -> Bool) -> Eq SortOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SortOpts -> SortOpts -> Bool
== :: SortOpts -> SortOpts -> Bool
$c/= :: SortOpts -> SortOpts -> Bool
/= :: SortOpts -> SortOpts -> Bool
Eq)

-- |Redis default 'SortOpts'. Equivalent to omitting all optional parameters.
--
-- @
-- SortOpts
--     { sortBy    = Nothing -- omit the BY option
--     , sortLimit = (0,-1)  -- return entire collection
--     , sortGet   = []      -- omit the GET option
--     , sortOrder = Asc     -- sort in ascending order
--     , sortAlpha = False   -- sort numerically, not lexicographically
--     }
-- @
--
defaultSortOpts :: SortOpts
defaultSortOpts :: SortOpts
defaultSortOpts = SortOpts
    { sortBy :: Maybe ByteString
sortBy    = Maybe ByteString
forall a. Maybe a
Nothing
    , sortLimit :: (Integer, Integer)
sortLimit = (Integer
0,-Integer
1)
    , sortGet :: [ByteString]
sortGet   = []
    , sortOrder :: SortOrder
sortOrder = SortOrder
Asc
    , sortAlpha :: Bool
sortAlpha = Bool
False
    }

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

-- |Sort the elements in a list, set or sorted set (<http://redis.io/commands/sort>). The Redis command @SORT@ is split up into 'sort', 'sortStore'. Since Redis 1.0.0
sortStore
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> ByteString -- ^ destination
    -> SortOpts
    -> m (f Integer)
sortStore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> SortOpts -> m (f Integer)
sortStore ByteString
key ByteString
dest = ByteString -> Maybe ByteString -> SortOpts -> m (f Integer)
forall a (m :: * -> *) (f :: * -> *).
(RedisResult a, RedisCtx m f) =>
ByteString -> Maybe ByteString -> SortOpts -> m (f a)
sortInternal ByteString
key (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
dest)

-- |Sort the elements in a list, set or sorted set (<http://redis.io/commands/sort>). The Redis command @SORT@ is split up into 'sort', 'sortStore'. Since Redis 1.0.0
sort
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> SortOpts
    -> m (f [ByteString])
sort :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> SortOpts -> m (f [ByteString])
sort ByteString
key = ByteString -> Maybe ByteString -> SortOpts -> m (f [ByteString])
forall a (m :: * -> *) (f :: * -> *).
(RedisResult a, RedisCtx m f) =>
ByteString -> Maybe ByteString -> SortOpts -> m (f a)
sortInternal ByteString
key Maybe ByteString
forall a. Maybe a
Nothing

sortInternal
    :: (RedisResult a, RedisCtx m f)
    => ByteString -- ^ key
    -> Maybe ByteString -- ^ destination
    -> SortOpts
    -> m (f a)
sortInternal :: forall a (m :: * -> *) (f :: * -> *).
(RedisResult a, RedisCtx m f) =>
ByteString -> Maybe ByteString -> SortOpts -> m (f a)
sortInternal ByteString
key Maybe ByteString
destination SortOpts{Bool
[ByteString]
Maybe ByteString
(Integer, Integer)
SortOrder
sortBy :: SortOpts -> Maybe ByteString
sortLimit :: SortOpts -> (Integer, Integer)
sortGet :: SortOpts -> [ByteString]
sortOrder :: SortOpts -> SortOrder
sortAlpha :: SortOpts -> Bool
sortBy :: Maybe ByteString
sortLimit :: (Integer, Integer)
sortGet :: [ByteString]
sortOrder :: SortOrder
sortAlpha :: Bool
..} = [ByteString] -> m (f a)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f a)) -> [ByteString] -> m (f a)
forall a b. (a -> b) -> a -> b
$
    [[ByteString]] -> [ByteString]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ByteString
"SORT", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key], [ByteString]
by, [ByteString]
limit, [ByteString]
get, [ByteString]
order, [ByteString]
alpha, [ByteString]
store]
  where
    by :: [ByteString]
by    = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
pattern -> [ByteString
"BY", ByteString
pattern]) Maybe ByteString
sortBy
    limit :: [ByteString]
limit = let (Integer
off,Integer
cnt) = (Integer, Integer)
sortLimit in [ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
off, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
cnt]
    get :: [ByteString]
get   = (ByteString -> [ByteString]) -> [ByteString] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\ByteString
pattern -> [ByteString
"GET", ByteString
pattern]) [ByteString]
sortGet
    order :: [ByteString]
order = case SortOrder
sortOrder of SortOrder
Desc -> [ByteString
"DESC"]; SortOrder
Asc -> [ByteString
"ASC"]
    alpha :: [ByteString]
alpha = [ByteString
"ALPHA" | Bool
sortAlpha]
    store :: [ByteString]
store = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
dest -> [ByteString
"STORE", ByteString
dest]) Maybe ByteString
destination


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

zunionstore
    :: (RedisCtx m f)
    => ByteString -- ^ destination
    -> [ByteString] -- ^ keys
    -> Aggregate
    -> m (f Integer)
zunionstore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> Aggregate -> m (f Integer)
zunionstore ByteString
dest [ByteString]
keys =
    ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
zstoreInternal ByteString
"ZUNIONSTORE" ByteString
dest [ByteString]
keys []

zunionstoreWeights
    :: (RedisCtx m f)
    => ByteString -- ^ destination
    -> [(ByteString,Double)] -- ^ weighted keys
    -> Aggregate
    -> m (f Integer)
zunionstoreWeights :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [(ByteString, Double)] -> Aggregate -> m (f Integer)
zunionstoreWeights ByteString
dest [(ByteString, Double)]
kws =
    let ([ByteString]
keys,[Double]
weights) = [(ByteString, Double)] -> ([ByteString], [Double])
forall a b. [(a, b)] -> ([a], [b])
unzip [(ByteString, Double)]
kws
    in ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
zstoreInternal ByteString
"ZUNIONSTORE" ByteString
dest [ByteString]
keys [Double]
weights

-- |Intersect multiple sorted sets and store the resulting sorted set in a new key (<http://redis.io/commands/zinterstore>). The Redis command @ZINTERSTORE@ is split up into 'zinterstore', 'zinterstoreWeights'. Since Redis 2.0.0
zinterstore
    :: (RedisCtx m f)
    => ByteString -- ^ destination
    -> NonEmpty ByteString -- ^ keys
    -> Aggregate
    -> m (f Integer)
zinterstore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> Aggregate -> m (f Integer)
zinterstore ByteString
dest (ByteString
key_:|[ByteString]
keys_) =
    ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
zstoreInternal ByteString
"ZINTERSTORE" ByteString
dest (ByteString
key_ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[ByteString]
keys_) []

-- |Intersect multiple sorted sets and store the resulting sorted set in a new key (<http://redis.io/commands/zinterstore>). The Redis command @ZINTERSTORE@ is split up into 'zinterstore', 'zinterstoreWeights'. Since Redis 2.0.0
zinterstoreWeights
    :: (RedisCtx m f)
    => ByteString -- ^ destination
    -> NonEmpty (ByteString,Double) -- ^ weighted keys
    -> Aggregate
    -> m (f Integer)
zinterstoreWeights :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty (ByteString, Double) -> Aggregate -> m (f Integer)
zinterstoreWeights ByteString
dest NonEmpty (ByteString, Double)
kws =
    let ([ByteString]
keys,[Double]
weights) = [(ByteString, Double)] -> ([ByteString], [Double])
forall a b. [(a, b)] -> ([a], [b])
unzip (NonEmpty (ByteString, Double) -> [(ByteString, Double)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (ByteString, Double)
kws)
    in ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
zstoreInternal ByteString
"ZINTERSTORE" ByteString
dest [ByteString]
keys [Double]
weights

zstoreInternal
    :: (RedisCtx m f)
    => ByteString -- ^ cmd
    -> ByteString -- ^ destination
    -> [ByteString] -- ^ keys
    -> [Double] -- ^ weights
    -> Aggregate
    -> m (f Integer)
zstoreInternal :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [ByteString]
-> [Double]
-> Aggregate
-> m (f Integer)
zstoreInternal ByteString
cmd ByteString
dest [ByteString]
keys [Double]
weights Aggregate
aggregate = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$
    [[ByteString]] -> [ByteString]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ [ByteString
cmd, ByteString
dest, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Integer -> ByteString) -> (Int -> Integer) -> Int -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> ByteString) -> Int -> ByteString
forall a b. (a -> b) -> a -> b
$ [ByteString] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ByteString]
keys ], [ByteString]
keys
           , if [Double] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Double]
weights then [] else ByteString
"WEIGHTS" ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: (Double -> ByteString) -> [Double] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode [Double]
weights
           , [ByteString
"AGGREGATE", ByteString
aggregate']
           ]
  where
    aggregate' :: ByteString
aggregate' = case Aggregate
aggregate of
        Aggregate
Sum -> ByteString
"SUM"
        Aggregate
Min -> ByteString
"MIN"
        Aggregate
Max -> ByteString
"MAX"

-- |Returns the difference between multiple sorted sets (<https://redis.io/commands/zdiff>).
--
-- /O(L + (N - K)\log(N))/ worst case where $L$ is the total number of elements in all the sorted sets, /N/ is the size of the first sorted set, and /K/ is the size of the result set.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 6.2.0
zdiff
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> m (f [ByteString])
zdiff :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> m (f [ByteString])
zdiff NonEmpty ByteString
keys = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [ByteString]))
-> [ByteString] -> m (f [ByteString])
forall a b. (a -> b) -> a -> b
$ ByteString -> NonEmpty ByteString -> [ByteString]
zAggregateKeysArgs ByteString
"ZDIFF" NonEmpty ByteString
keys

-- |Returns the difference between multiple sorted sets with scores (<https://redis.io/commands/zdiff>).
--
-- /O(L + (N - K)\log(N))/ worst case where $L$ is the total number of elements in all the sorted sets, /N/ is the size of the first sorted set, and /K/ is the size of the result set.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 6.2.0
zdiffWithscores
    :: (RedisCtx m f)
    => NonEmpty ByteString -- ^ Sorted set keys.
    -> m (f [(ByteString, Double)])
zdiffWithscores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> m (f [(ByteString, Double)])
zdiffWithscores NonEmpty ByteString
keys = [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [(ByteString, Double)]))
-> [ByteString] -> m (f [(ByteString, Double)])
forall a b. (a -> b) -> a -> b
$ ByteString -> NonEmpty ByteString -> [ByteString]
zAggregateKeysArgs ByteString
"ZDIFF" NonEmpty ByteString
keys [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"WITHSCORES"]

-- |Stores the difference of multiple sorted sets in a key (<https://redis.io/commands/zdiffstore>).
--
-- /O(L + (N - K)\log(N))/ worst case where $L$ is the total number of elements in all the sorted sets, /N/ is the size of the first sorted set, and /K/ is the size of the result set.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Keys that do not exist are considered to be empty sets.
--
-- If destination already exists, it is overwritten.
--
-- Since Redis 6.2.0
zdiffstore
    :: (RedisCtx m f)
    => ByteString -- ^ Destination key.
    -> NonEmpty ByteString -- ^ Sorted set keys.
    -> m (f Integer)
zdiffstore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> m (f Integer)
zdiffstore ByteString
destination NonEmpty ByteString
keys =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"ZDIFFSTORE", ByteString
destination] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString] -> [ByteString]
forall a. HasCallStack => [a] -> [a]
tail (ByteString -> NonEmpty ByteString -> [ByteString]
zAggregateKeysArgs ByteString
"ZDIFF" NonEmpty ByteString
keys)

-- |Returns the intersection of multiple sorted sets (<https://redis.io/commands/zinter>).
--
-- /O(NK) + O(M\log(M))/ worst case with /N/ being the smallest input sorted set, /K/ being the number of input sorted sets and /M/ being the number of elements in the resulting sorted set.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 6.2.0
zinter
    :: (RedisCtx m f)
    => NonEmpty ByteString -- ^ Sorted set keys.
    -> m (f [ByteString])
zinter :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> m (f [ByteString])
zinter NonEmpty ByteString
keys = NonEmpty ByteString -> ZAggregateOpts -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> ZAggregateOpts -> m (f [ByteString])
zinterOpts NonEmpty ByteString
keys ZAggregateOpts
defaultZAggregateOpts


data ZAggregateOpts = ZAggregateOpts
    { ZAggregateOpts -> [Double]
zAggregateWeights :: [Double] -- ^ WEIGHTS option, it is possible to specify a multiplication factor for each input sorted set. Each element's score is multiplied by its corresponding weight before aggregation. When WEIGHTS is not given, the multiplication factors default to 1.
    , ZAggregateOpts -> Aggregate
zAggregateAggregate :: Aggregate -- ^ AGGREGATE option, it is possible to specify how the results of the union are aggregated
    } deriving (Int -> ZAggregateOpts -> ShowS
[ZAggregateOpts] -> ShowS
ZAggregateOpts -> String
(Int -> ZAggregateOpts -> ShowS)
-> (ZAggregateOpts -> String)
-> ([ZAggregateOpts] -> ShowS)
-> Show ZAggregateOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ZAggregateOpts -> ShowS
showsPrec :: Int -> ZAggregateOpts -> ShowS
$cshow :: ZAggregateOpts -> String
show :: ZAggregateOpts -> String
$cshowList :: [ZAggregateOpts] -> ShowS
showList :: [ZAggregateOpts] -> ShowS
Show, ZAggregateOpts -> ZAggregateOpts -> Bool
(ZAggregateOpts -> ZAggregateOpts -> Bool)
-> (ZAggregateOpts -> ZAggregateOpts -> Bool) -> Eq ZAggregateOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ZAggregateOpts -> ZAggregateOpts -> Bool
== :: ZAggregateOpts -> ZAggregateOpts -> Bool
$c/= :: ZAggregateOpts -> ZAggregateOpts -> Bool
/= :: ZAggregateOpts -> ZAggregateOpts -> Bool
Eq)

defaultZAggregateOpts :: ZAggregateOpts
defaultZAggregateOpts :: ZAggregateOpts
defaultZAggregateOpts = ZAggregateOpts
    { zAggregateWeights :: [Double]
zAggregateWeights = []
    , zAggregateAggregate :: Aggregate
zAggregateAggregate = Aggregate
Sum
    }

-- |Returns the intersection of multiple sorted sets with scores (<https://redis.io/commands/zinter>).
--
-- /O(NK) + O(M\log(M))/ worst case with /N/ being the smallest input sorted set, /K/ being the number of input sorted sets and /M/ being the number of elements in the resulting sorted set.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 6.2.0
zinterWithscores
    :: (RedisCtx m f)
    => NonEmpty ByteString -- ^ Sorted set keys.
    -> m (f [(ByteString, Double)])
zinterWithscores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> m (f [(ByteString, Double)])
zinterWithscores NonEmpty ByteString
keys = NonEmpty ByteString
-> ZAggregateOpts -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ZAggregateOpts -> m (f [(ByteString, Double)])
zinterWithscoresOpts NonEmpty ByteString
keys ZAggregateOpts
defaultZAggregateOpts

-- |Returns the intersection of multiple sorted sets (<https://redis.io/commands/zinter>).
--
-- /O(NK) + O(M\log(M))/ worst case with /N/ being the smallest input sorted set, /K/ being the number of input sorted sets and /M/ being the number of elements in the resulting sorted set.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 6.2.0
zinterOpts
    :: (RedisCtx m f)
    => NonEmpty ByteString -- ^ Sorted set keys.
    -> ZAggregateOpts
    -> m (f [ByteString])
zinterOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> ZAggregateOpts -> m (f [ByteString])
zinterOpts NonEmpty ByteString
keys ZAggregateOpts
opts = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [ByteString]))
-> [ByteString] -> m (f [ByteString])
forall a b. (a -> b) -> a -> b
$ ByteString
-> NonEmpty ByteString -> ZAggregateOpts -> Bool -> [ByteString]
zAggregateInternalArgs ByteString
"ZINTER" NonEmpty ByteString
keys ZAggregateOpts
opts Bool
False

-- |Returns the intersection of multiple sorted sets with scores (<https://redis.io/commands/zinter>).
--
-- /O(NK) + O(M\log(M))/ worst case with /N/ being the smallest input sorted set, /K/ being the number of input sorted sets and /M/ being the number of elements in the resulting sorted set.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 6.2.0
zinterWithscoresOpts
    :: (RedisCtx m f)
    => NonEmpty ByteString -- ^ Sorted set keys.
    -> ZAggregateOpts
    -> m (f [(ByteString, Double)])
zinterWithscoresOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ZAggregateOpts -> m (f [(ByteString, Double)])
zinterWithscoresOpts NonEmpty ByteString
keys ZAggregateOpts
opts = [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [(ByteString, Double)]))
-> [ByteString] -> m (f [(ByteString, Double)])
forall a b. (a -> b) -> a -> b
$ ByteString
-> NonEmpty ByteString -> ZAggregateOpts -> Bool -> [ByteString]
zAggregateInternalArgs ByteString
"ZINTER" NonEmpty ByteString
keys ZAggregateOpts
opts Bool
True

-- |Returns the union of multiple sorted sets (<https://redis.io/commands/zunion>).
--
-- /O(N) + O(M\log(M))/ with /N/ being the sum of the sizes of the input sorted sets, and /M/ being the number of elements in the resulting sorted set.
--
-- Since Redis 6.2.0
zunion
    :: (RedisCtx m f)
    => NonEmpty ByteString -- ^ Sorted set keys.
    -> m (f [ByteString])
zunion :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> m (f [ByteString])
zunion NonEmpty ByteString
keys = NonEmpty ByteString -> ZAggregateOpts -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> ZAggregateOpts -> m (f [ByteString])
zunionOpts NonEmpty ByteString
keys ZAggregateOpts
defaultZAggregateOpts

-- |Returns the union of multiple sorted sets with scores (<https://redis.io/commands/zunion>).
--
-- /O(N) + O(M\log(M))/ with /N/ being the sum of the sizes of the input sorted sets, and /M/ being the number of elements in the resulting sorted set.
--
-- Since Redis 6.2.0
zunionWithscores
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> m (f [(ByteString, Double)])
zunionWithscores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> m (f [(ByteString, Double)])
zunionWithscores NonEmpty ByteString
keys = NonEmpty ByteString
-> ZAggregateOpts -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ZAggregateOpts -> m (f [(ByteString, Double)])
zunionWithscoresOpts NonEmpty ByteString
keys ZAggregateOpts
defaultZAggregateOpts

-- |Returns the union of multiple sorted sets (<https://redis.io/commands/zunion>).
--
-- /O(N) + O(M\log(M))/ with /N/ being the sum of the sizes of the input sorted sets, and /M/ being the number of elements in the resulting sorted set.
--
-- Since Redis 6.2.0
zunionOpts
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> ZAggregateOpts
    -> m (f [ByteString])
zunionOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> ZAggregateOpts -> m (f [ByteString])
zunionOpts NonEmpty ByteString
keys ZAggregateOpts
opts = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [ByteString]))
-> [ByteString] -> m (f [ByteString])
forall a b. (a -> b) -> a -> b
$ ByteString
-> NonEmpty ByteString -> ZAggregateOpts -> Bool -> [ByteString]
zAggregateInternalArgs ByteString
"ZUNION" NonEmpty ByteString
keys ZAggregateOpts
opts Bool
False

-- |Returns the union of multiple sorted sets with scores (<https://redis.io/commands/zunion>).
--
-- /O(N) + O(M\log(M))/ with /N/ being the sum of the sizes of the input sorted sets, and /M/ being the number of elements in the resulting sorted set.
--
-- Since Redis 6.2.0
zunionWithscoresOpts
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> ZAggregateOpts
    -> m (f [(ByteString, Double)])
zunionWithscoresOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ZAggregateOpts -> m (f [(ByteString, Double)])
zunionWithscoresOpts NonEmpty ByteString
keys ZAggregateOpts
opts = [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [(ByteString, Double)]))
-> [ByteString] -> m (f [(ByteString, Double)])
forall a b. (a -> b) -> a -> b
$ ByteString
-> NonEmpty ByteString -> ZAggregateOpts -> Bool -> [ByteString]
zAggregateInternalArgs ByteString
"ZUNION" NonEmpty ByteString
keys ZAggregateOpts
opts Bool
True

zAggregateKeysArgs :: ByteString -> NonEmpty ByteString -> [ByteString]
zAggregateKeysArgs :: ByteString -> NonEmpty ByteString -> [ByteString]
zAggregateKeysArgs ByteString
cmd NonEmpty ByteString
keys =
    [ByteString
cmd, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Integer -> ByteString) -> (Int -> Integer) -> Int -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> ByteString) -> Int -> ByteString
forall a b. (a -> b) -> a -> b
$ NonEmpty ByteString -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty ByteString
keys] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ByteString
keys

zAggregateInternalArgs :: ByteString -> NonEmpty ByteString -> ZAggregateOpts -> Bool -> [ByteString]
zAggregateInternalArgs :: ByteString
-> NonEmpty ByteString -> ZAggregateOpts -> Bool -> [ByteString]
zAggregateInternalArgs ByteString
cmd NonEmpty ByteString
keys ZAggregateOpts{[Double]
Aggregate
zAggregateWeights :: ZAggregateOpts -> [Double]
zAggregateAggregate :: ZAggregateOpts -> Aggregate
zAggregateWeights :: [Double]
zAggregateAggregate :: Aggregate
..} Bool
withScores =
    ByteString -> NonEmpty ByteString -> [ByteString]
zAggregateKeysArgs ByteString
cmd NonEmpty ByteString
keys [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
weightsArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
aggregateArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
withScoresArg
  where
    weightsArg :: [ByteString]
weightsArg = [ByteString
"WEIGHTS" | Bool -> Bool
not ([Double] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Double]
zAggregateWeights)] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (Double -> ByteString) -> [Double] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode [Double]
zAggregateWeights
    aggregateArg :: [ByteString]
aggregateArg = [ByteString
"AGGREGATE", Aggregate -> ByteString
forall {a}. IsString a => Aggregate -> a
aggregateValue Aggregate
zAggregateAggregate]
    withScoresArg :: [ByteString]
withScoresArg = [ByteString
"WITHSCORES" | Bool
withScores]
    aggregateValue :: Aggregate -> a
aggregateValue Aggregate
Sum = a
"SUM"
    aggregateValue Aggregate
Min = a
"MIN"
    aggregateValue Aggregate
Max = a
"MAX"

-- |Execute a Lua script server side (<http://redis.io/commands/eval>). Since Redis 2.6.0
eval
    :: (RedisCtx m f, RedisResult a)
    => ByteString -- ^ script
    -> [ByteString] -- ^ keys
    -> [ByteString] -- ^ args
    -> m (f a)
eval :: forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
ByteString -> [ByteString] -> [ByteString] -> m (f a)
eval ByteString
script [ByteString]
keys [ByteString]
args =
    [ByteString] -> m (f a)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f a)) -> [ByteString] -> m (f a)
forall a b. (a -> b) -> a -> b
$ [ByteString
"EVAL", ByteString
script, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
numkeys] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
keys [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
args
  where
    numkeys :: Integer
numkeys = Int -> Integer
forall a. Integral a => a -> Integer
toInteger ([ByteString] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ByteString]
keys)

-- | Works like 'eval', but sends the SHA1 hash of the script instead of the script itself.
-- Fails if the server does not recognise the hash, in which case, 'eval' should be used instead.
evalsha
    :: (RedisCtx m f, RedisResult a)
    => ByteString -- ^ base16-encoded sha1 hash of the script
    -> [ByteString] -- ^ keys
    -> [ByteString] -- ^ args
    -> m (f a)
evalsha :: forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
ByteString -> [ByteString] -> [ByteString] -> m (f a)
evalsha ByteString
script [ByteString]
keys [ByteString]
args =
    [ByteString] -> m (f a)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f a)) -> [ByteString] -> m (f a)
forall a b. (a -> b) -> a -> b
$ [ByteString
"EVALSHA", ByteString
script, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
numkeys] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
keys [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
args
  where
    numkeys :: Integer
numkeys = Int -> Integer
forall a. Integral a => a -> Integer
toInteger ([ByteString] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ByteString]
keys)

-- |Invokes a function (<https://redis.io/commands/fcall>).
--
-- Complexity depends on the function that is executed.
--
-- Since Redis 7.0.0
fcall
    :: (RedisCtx m f, RedisResult a)
    => ByteString
    -> [ByteString]
    -> [ByteString]
    -> m (f a)
fcall :: forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
ByteString -> [ByteString] -> [ByteString] -> m (f a)
fcall ByteString
functionName [ByteString]
keys [ByteString]
args =
    [ByteString] -> m (f a)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f a)) -> [ByteString] -> m (f a)
forall a b. (a -> b) -> a -> b
$ [ByteString
"FCALL", ByteString
functionName, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
numkeys] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
keys [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
args
  where
    numkeys :: Integer
numkeys = Int -> Integer
forall a. Integral a => a -> Integer
toInteger ([ByteString] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ByteString]
keys)

-- |Invokes a read-only function (<https://redis.io/commands/fcall_ro>).
--
-- Complexity depends on the function that is executed.
--
-- Since Redis 7.0.0
fcallReadonly
    :: (RedisCtx m f, RedisResult a)
    => ByteString
    -> [ByteString]
    -> [ByteString]
    -> m (f a)
fcallReadonly :: forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
ByteString -> [ByteString] -> [ByteString] -> m (f a)
fcallReadonly ByteString
functionName [ByteString]
keys [ByteString]
args =
    [ByteString] -> m (f a)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f a)) -> [ByteString] -> m (f a)
forall a b. (a -> b) -> a -> b
$ [ByteString
"FCALL_RO", ByteString
functionName, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
numkeys] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
keys [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
args
  where
    numkeys :: Integer
numkeys = Int -> Integer
forall a. Integral a => a -> Integer
toInteger ([ByteString] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ByteString]
keys)

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

defaultFunctionListOpts :: FunctionListOpts
defaultFunctionListOpts :: FunctionListOpts
defaultFunctionListOpts = FunctionListOpts
    { functionListLibraryName :: Maybe ByteString
functionListLibraryName = Maybe ByteString
forall a. Maybe a
Nothing
    , functionListWithCode :: Bool
functionListWithCode = Bool
False
    }

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

instance RedisArg FunctionRestorePolicy where
    encode :: FunctionRestorePolicy -> ByteString
encode FunctionRestorePolicy
FunctionRestoreAppend = ByteString
"APPEND"
    encode FunctionRestorePolicy
FunctionRestoreFlush = ByteString
"FLUSH"
    encode FunctionRestorePolicy
FunctionRestoreReplace = ByteString
"REPLACE"

-- |Deletes a library and its functions (<https://redis.io/commands/function-delete>).
--
-- /O(1)/
--
-- Since Redis 7.0.0
functionDelete
    :: (RedisCtx m f)
    => ByteString
    -> m (f Status)
functionDelete :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Status)
functionDelete ByteString
libraryName = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"DELETE", ByteString
libraryName]

-- |Dumps all libraries into a serialized binary payload (<https://redis.io/commands/function-dump>).
--
-- /O(N)/ where /N/ is the number of functions.
--
-- Since Redis 7.0.0
functionDump
    :: (RedisCtx m f)
    => m (f ByteString)
functionDump :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f ByteString)
functionDump = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"DUMP"]

-- |Deletes all libraries and functions (<https://redis.io/commands/function-flush>).
--
-- /O(N)/ where /N/ is the number of functions deleted.
--
-- Since Redis 7.0.0
functionFlush
    :: (RedisCtx m f)
    => m (f Status)
functionFlush :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Status)
functionFlush = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"FLUSH"]

-- |Deletes all libraries and functions (<https://redis.io/commands/function-flush>).
--
-- /O(N)/ where /N/ is the number of functions deleted.
--
-- Since Redis 7.0.0
functionFlushOpts
    :: (RedisCtx m f)
    => FlushOpts
    -> m (f Status)
functionFlushOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
FlushOpts -> m (f Status)
functionFlushOpts FlushOpts
opts = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"FLUSH", FlushOpts -> ByteString
forall a. RedisArg a => a -> ByteString
encode FlushOpts
opts]

-- |Returns helpful text about FUNCTION subcommands (<https://redis.io/commands/function-help>).
--
-- /O(1)/
--
-- Since Redis 7.0.0
functionHelp
    :: (RedisCtx m f)
    => m (f [ByteString])
functionHelp :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f [ByteString])
functionHelp = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"HELP"]

-- |Terminates a function during execution (<https://redis.io/commands/function-kill>).
--
-- /O(1)/
--
-- Since Redis 7.0.0
functionKill
    :: (RedisCtx m f)
    => m (f Status)
functionKill :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Status)
functionKill = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"KILL"]

-- |Returns information about all libraries (<https://redis.io/commands/function-list>).
--
-- /O(N)/ where /N/ is the number of functions.
--
-- Since Redis 7.0.0
functionList
    :: (RedisCtx m f)
    => m (f Reply)
functionList :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Reply)
functionList = FunctionListOpts -> m (f Reply)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
FunctionListOpts -> m (f Reply)
functionListOpts FunctionListOpts
defaultFunctionListOpts

-- |Returns information about all libraries (<https://redis.io/commands/function-list>).
--
-- /O(N)/ where /N/ is the number of functions.
--
-- Since Redis 7.0.0
functionListOpts
    :: (RedisCtx m f)
    => FunctionListOpts
    -> m (f Reply)
functionListOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
FunctionListOpts -> m (f Reply)
functionListOpts FunctionListOpts{Bool
Maybe ByteString
functionListLibraryName :: FunctionListOpts -> Maybe ByteString
functionListWithCode :: FunctionListOpts -> Bool
functionListLibraryName :: Maybe ByteString
functionListWithCode :: Bool
..} =
    [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
"FUNCTION", ByteString
"LIST"] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
libraryArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
withCodeArg
  where
    libraryArg :: [ByteString]
libraryArg = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
libraryName -> [ByteString
"LIBRARYNAME", ByteString
libraryName]) Maybe ByteString
functionListLibraryName
    withCodeArg :: [ByteString]
withCodeArg = [ByteString
"WITHCODE" | Bool
functionListWithCode]

-- |Creates a library (<https://redis.io/commands/function-load>).
--
-- /O(N)/ where /N/ is the number of bytes in the function's source code.
--
-- Since Redis 7.0.0
functionLoad
    :: (RedisCtx m f)
    => ByteString
    -> m (f ByteString)
functionLoad :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f ByteString)
functionLoad ByteString
libraryCode = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"LOAD", ByteString
libraryCode]

-- |Creates a library, replacing an existing one with the same name (<https://redis.io/commands/function-load>).
--
-- /O(N)/ where /N/ is the number of bytes in the function's source code.
--
-- Since Redis 7.0.0
functionLoadReplace
    :: (RedisCtx m f)
    => ByteString
    -> m (f ByteString)
functionLoadReplace :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f ByteString)
functionLoadReplace ByteString
libraryCode = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"LOAD", ByteString
"REPLACE", ByteString
libraryCode]

-- |Restores all libraries from a payload (<https://redis.io/commands/function-restore>).
--
-- /O(N)/ where /N/ is the number of functions restored.
--
-- Since Redis 7.0.0
functionRestore
    :: (RedisCtx m f)
    => ByteString
    -> Maybe FunctionRestorePolicy
    -> m (f Status)
functionRestore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Maybe FunctionRestorePolicy -> m (f Status)
functionRestore ByteString
payload Maybe FunctionRestorePolicy
restorePolicy =
    [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
"FUNCTION", ByteString
"RESTORE", ByteString
payload] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (FunctionRestorePolicy -> [ByteString])
-> Maybe FunctionRestorePolicy
-> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\FunctionRestorePolicy
policy -> [FunctionRestorePolicy -> ByteString
forall a. RedisArg a => a -> ByteString
encode FunctionRestorePolicy
policy]) Maybe FunctionRestorePolicy
restorePolicy

-- |Returns information about a function during execution (<https://redis.io/commands/function-stats>).
--
-- /O(1)/
--
-- Since Redis 7.0.0
functionStats
    :: (RedisCtx m f)
    => m (f Reply)
functionStats :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Reply)
functionStats = [ByteString] -> m (f Reply)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FUNCTION", ByteString
"STATS"]

bitcount
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> m (f Integer)
bitcount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
bitcount ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"BITCOUNT", ByteString
key]

bitcountRange
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ start
    -> Integer -- ^ end
    -> m (f Integer)
bitcountRange :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> Integer -> m (f Integer)
bitcountRange ByteString
key Integer
start Integer
end =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"BITCOUNT", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
end]

bitopAnd
    :: (RedisCtx m f)
    => ByteString -- ^ destkey
    -> [ByteString] -- ^ srckeys
    -> m (f Integer)
bitopAnd :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f Integer)
bitopAnd ByteString
dst [ByteString]
srcs = ByteString -> [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f Integer)
bitop ByteString
"AND" (ByteString
dstByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[ByteString]
srcs)

bitopOr
    :: (RedisCtx m f)
    => ByteString -- ^ destkey
    -> [ByteString] -- ^ srckeys
    -> m (f Integer)
bitopOr :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f Integer)
bitopOr ByteString
dst [ByteString]
srcs = ByteString -> [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f Integer)
bitop ByteString
"OR" (ByteString
dstByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[ByteString]
srcs)

bitopXor
    :: (RedisCtx m f)
    => ByteString -- ^ destkey
    -> [ByteString] -- ^ srckeys
    -> m (f Integer)
bitopXor :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f Integer)
bitopXor ByteString
dst [ByteString]
srcs = ByteString -> [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f Integer)
bitop ByteString
"XOR" (ByteString
dstByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[ByteString]
srcs)

bitopNot
    :: (RedisCtx m f)
    => ByteString -- ^ destkey
    -> ByteString -- ^ srckey
    -> m (f Integer)
bitopNot :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Integer)
bitopNot ByteString
dst ByteString
src = ByteString -> [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f Integer)
bitop ByteString
"NOT" [ByteString
dst, ByteString
src]

bitop
    :: (RedisCtx m f)
    => ByteString -- ^ operation
    -> [ByteString] -- ^ keys
    -> m (f Integer)
bitop :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f Integer)
bitop ByteString
op [ByteString]
ks = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ ByteString
"BITOP" ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
op ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
ks

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

instance RedisArg VAddQuantization where
    encode :: VAddQuantization -> ByteString
encode VAddQuantization
VAddNoQuant = ByteString
"NOQUANT"
    encode VAddQuantization
VAddQ8 = ByteString
"Q8"
    encode VAddQuantization
VAddBin = ByteString
"BIN"

data VAddOpts = VAddOpts
    { VAddOpts -> Maybe Integer
vAddReduceDim :: Maybe Integer
    , VAddOpts -> Bool
vAddCas :: Bool
    , VAddOpts -> Maybe VAddQuantization
vAddQuantization :: Maybe VAddQuantization
    , VAddOpts -> Maybe Integer
vAddBuildExplorationFactor :: Maybe Integer
    , VAddOpts -> Maybe ByteString
vAddAttributes :: Maybe ByteString
    , VAddOpts -> Maybe Integer
vAddNumLinks :: Maybe Integer
    } deriving (Int -> VAddOpts -> ShowS
[VAddOpts] -> ShowS
VAddOpts -> String
(Int -> VAddOpts -> ShowS)
-> (VAddOpts -> String) -> ([VAddOpts] -> ShowS) -> Show VAddOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VAddOpts -> ShowS
showsPrec :: Int -> VAddOpts -> ShowS
$cshow :: VAddOpts -> String
show :: VAddOpts -> String
$cshowList :: [VAddOpts] -> ShowS
showList :: [VAddOpts] -> ShowS
Show, VAddOpts -> VAddOpts -> Bool
(VAddOpts -> VAddOpts -> Bool)
-> (VAddOpts -> VAddOpts -> Bool) -> Eq VAddOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VAddOpts -> VAddOpts -> Bool
== :: VAddOpts -> VAddOpts -> Bool
$c/= :: VAddOpts -> VAddOpts -> Bool
/= :: VAddOpts -> VAddOpts -> Bool
Eq)

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

instance RedisArg VQuantization where
    encode :: VQuantization -> ByteString
encode VQuantization
VQuantizationFP32 = ByteString
"FP32"
    encode VQuantization
VQuantizationBin = ByteString
"BIN"
    encode VQuantization
VQuantizationQ8 = ByteString
"Q8"

instance RedisResult VQuantization where
    decode :: Reply -> Either Reply VQuantization
decode (SingleLine ByteString
"fp32") = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationFP32
    decode (SingleLine ByteString
"f32") = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationFP32
    decode (SingleLine ByteString
"bin") = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationBin
    decode (SingleLine ByteString
"q8") = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationQ8
    decode (SingleLine ByteString
"int8") = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationQ8
    decode (Bulk (Just ByteString
"fp32")) = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationFP32
    decode (Bulk (Just ByteString
"f32")) = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationFP32
    decode (Bulk (Just ByteString
"bin")) = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationBin
    decode (Bulk (Just ByteString
"q8")) = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationQ8
    decode (Bulk (Just ByteString
"int8")) = VQuantization -> Either Reply VQuantization
forall a b. b -> Either a b
Right VQuantization
VQuantizationQ8
    decode Reply
r = Reply -> Either Reply VQuantization
forall a b. a -> Either a b
Left Reply
r

data VEmbRawResponse = VEmbRawResponse
    { VEmbRawResponse -> VQuantization
vEmbRawQuantization :: VQuantization
    , VEmbRawResponse -> ByteString
vEmbRawData :: ByteString
    , VEmbRawResponse -> Double
vEmbRawNorm :: Double
    , VEmbRawResponse -> Maybe Double
vEmbRawRange :: Maybe Double
    } deriving (Int -> VEmbRawResponse -> ShowS
[VEmbRawResponse] -> ShowS
VEmbRawResponse -> String
(Int -> VEmbRawResponse -> ShowS)
-> (VEmbRawResponse -> String)
-> ([VEmbRawResponse] -> ShowS)
-> Show VEmbRawResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VEmbRawResponse -> ShowS
showsPrec :: Int -> VEmbRawResponse -> ShowS
$cshow :: VEmbRawResponse -> String
show :: VEmbRawResponse -> String
$cshowList :: [VEmbRawResponse] -> ShowS
showList :: [VEmbRawResponse] -> ShowS
Show, VEmbRawResponse -> VEmbRawResponse -> Bool
(VEmbRawResponse -> VEmbRawResponse -> Bool)
-> (VEmbRawResponse -> VEmbRawResponse -> Bool)
-> Eq VEmbRawResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VEmbRawResponse -> VEmbRawResponse -> Bool
== :: VEmbRawResponse -> VEmbRawResponse -> Bool
$c/= :: VEmbRawResponse -> VEmbRawResponse -> Bool
/= :: VEmbRawResponse -> VEmbRawResponse -> Bool
Eq)

instance RedisResult VEmbRawResponse where
    decode :: Reply -> Either Reply VEmbRawResponse
decode (MultiBulk (Just [Reply
quantizationReply, Reply
rawDataReply, Reply
normReply])) =
        VQuantization
-> ByteString -> Double -> Maybe Double -> VEmbRawResponse
VEmbRawResponse
            (VQuantization
 -> ByteString -> Double -> Maybe Double -> VEmbRawResponse)
-> Either Reply VQuantization
-> Either
     Reply (ByteString -> Double -> Maybe Double -> VEmbRawResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply VQuantization
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
quantizationReply
            Either
  Reply (ByteString -> Double -> Maybe Double -> VEmbRawResponse)
-> Either Reply ByteString
-> Either Reply (Double -> Maybe Double -> VEmbRawResponse)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
rawDataReply
            Either Reply (Double -> Maybe Double -> VEmbRawResponse)
-> Either Reply Double
-> Either Reply (Maybe Double -> VEmbRawResponse)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
normReply
            Either Reply (Maybe Double -> VEmbRawResponse)
-> Either Reply (Maybe Double) -> Either Reply VEmbRawResponse
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Double -> Either Reply (Maybe Double)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Double
forall a. Maybe a
Nothing
    decode (MultiBulk (Just [Reply
quantizationReply, Reply
rawDataReply, Reply
normReply, Reply
rangeReply])) =
        VQuantization
-> ByteString -> Double -> Maybe Double -> VEmbRawResponse
VEmbRawResponse
            (VQuantization
 -> ByteString -> Double -> Maybe Double -> VEmbRawResponse)
-> Either Reply VQuantization
-> Either
     Reply (ByteString -> Double -> Maybe Double -> VEmbRawResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply VQuantization
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
quantizationReply
            Either
  Reply (ByteString -> Double -> Maybe Double -> VEmbRawResponse)
-> Either Reply ByteString
-> Either Reply (Double -> Maybe Double -> VEmbRawResponse)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
rawDataReply
            Either Reply (Double -> Maybe Double -> VEmbRawResponse)
-> Either Reply Double
-> Either Reply (Maybe Double -> VEmbRawResponse)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
normReply
            Either Reply (Maybe Double -> VEmbRawResponse)
-> Either Reply (Maybe Double) -> Either Reply VEmbRawResponse
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Double -> Maybe Double
forall a. a -> Maybe a
Just (Double -> Maybe Double)
-> Either Reply Double -> Either Reply (Maybe Double)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
rangeReply)
    decode Reply
r = Reply -> Either Reply VEmbRawResponse
forall a b. a -> Either a b
Left Reply
r

data VInfoResponse = VInfoResponse
    { VInfoResponse -> Maybe ByteString
vInfoQuantization :: Maybe ByteString
    , VInfoResponse -> Maybe Integer
vInfoVectorDim :: Maybe Integer
    , VInfoResponse -> Maybe Integer
vInfoSize :: Maybe Integer
    , VInfoResponse -> Maybe Integer
vInfoMaxLevel :: Maybe Integer
    , VInfoResponse -> Maybe Integer
vInfoUid :: Maybe Integer
    , VInfoResponse -> Maybe Integer
vInfoHnswMaxNodeUid :: Maybe Integer
    } deriving (Int -> VInfoResponse -> ShowS
[VInfoResponse] -> ShowS
VInfoResponse -> String
(Int -> VInfoResponse -> ShowS)
-> (VInfoResponse -> String)
-> ([VInfoResponse] -> ShowS)
-> Show VInfoResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VInfoResponse -> ShowS
showsPrec :: Int -> VInfoResponse -> ShowS
$cshow :: VInfoResponse -> String
show :: VInfoResponse -> String
$cshowList :: [VInfoResponse] -> ShowS
showList :: [VInfoResponse] -> ShowS
Show, VInfoResponse -> VInfoResponse -> Bool
(VInfoResponse -> VInfoResponse -> Bool)
-> (VInfoResponse -> VInfoResponse -> Bool) -> Eq VInfoResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VInfoResponse -> VInfoResponse -> Bool
== :: VInfoResponse -> VInfoResponse -> Bool
$c/= :: VInfoResponse -> VInfoResponse -> Bool
/= :: VInfoResponse -> VInfoResponse -> Bool
Eq)

instance RedisResult VInfoResponse where
    decode :: Reply -> Either Reply VInfoResponse
decode r :: Reply
r@(MultiBulk (Just [Reply]
replies)) =
        [Reply] -> Either Reply [(ByteString, Reply)]
forall {a}. RedisResult a => [Reply] -> Either Reply [(a, Reply)]
parsePairs [Reply]
replies Either Reply [(ByteString, Reply)]
-> ([(ByteString, Reply)] -> Either Reply VInfoResponse)
-> Either Reply VInfoResponse
forall a b.
Either Reply a -> (a -> Either Reply b) -> Either Reply b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [(ByteString, Reply)] -> Either Reply VInfoResponse
forall {a}. [(ByteString, Reply)] -> Either a VInfoResponse
buildInfo
      where
        parsePairs :: [Reply] -> Either Reply [(a, Reply)]
parsePairs [] = [(a, Reply)] -> Either Reply [(a, Reply)]
forall a b. b -> Either a b
Right []
        parsePairs (Reply
keyReply:Reply
valueReply:[Reply]
rest) =
            (:) ((a, Reply) -> [(a, Reply)] -> [(a, Reply)])
-> Either Reply (a, Reply)
-> Either Reply ([(a, Reply)] -> [(a, Reply)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (a -> Reply -> (a, Reply))
-> Either Reply a -> Either Reply (Reply -> (a, Reply))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
keyReply Either Reply (Reply -> (a, Reply))
-> Either Reply Reply -> Either Reply (a, Reply)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Reply
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Reply
valueReply) Either Reply ([(a, Reply)] -> [(a, Reply)])
-> Either Reply [(a, Reply)] -> Either Reply [(a, Reply)]
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Reply] -> Either Reply [(a, Reply)]
parsePairs [Reply]
rest
        parsePairs [Reply]
_ = Reply -> Either Reply [(a, Reply)]
forall a b. a -> Either a b
Left Reply
r

        buildInfo :: [(ByteString, Reply)] -> Either a VInfoResponse
buildInfo [(ByteString, Reply)]
pairs = VInfoResponse -> Either a VInfoResponse
forall a b. b -> Either a b
Right VInfoResponse
            { vInfoQuantization :: Maybe ByteString
vInfoQuantization = ByteString -> [(ByteString, Reply)] -> Maybe ByteString
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
lookupDecoded ByteString
"quant-type" [(ByteString, Reply)]
pairs
            , vInfoVectorDim :: Maybe Integer
vInfoVectorDim = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
lookupDecoded ByteString
"vector-dim" [(ByteString, Reply)]
pairs
            , vInfoSize :: Maybe Integer
vInfoSize = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
lookupDecoded ByteString
"size" [(ByteString, Reply)]
pairs
            , vInfoMaxLevel :: Maybe Integer
vInfoMaxLevel = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
lookupDecoded ByteString
"max-level" [(ByteString, Reply)]
pairs
            , vInfoUid :: Maybe Integer
vInfoUid = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
lookupDecoded ByteString
"vset-uid" [(ByteString, Reply)]
pairs
            , vInfoHnswMaxNodeUid :: Maybe Integer
vInfoHnswMaxNodeUid = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
lookupDecoded ByteString
"hnsw-max-node-uid" [(ByteString, Reply)]
pairs
            }

        lookupDecoded :: RedisResult a => ByteString -> [(ByteString, Reply)] -> Maybe a
        lookupDecoded :: forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
lookupDecoded ByteString
key [(ByteString, Reply)]
pairs = ByteString -> [(ByteString, Reply)] -> Maybe Reply
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
key [(ByteString, Reply)]
pairs Maybe Reply -> (Reply -> Maybe a) -> Maybe a
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Reply -> Maybe a) -> (a -> Maybe a) -> Either Reply a -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe a -> Reply -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing) a -> Maybe a
forall a. a -> Maybe a
Just (Either Reply a -> Maybe a)
-> (Reply -> Either Reply a) -> Reply -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode
    decode Reply
r = Reply -> Either Reply VInfoResponse
forall a b. a -> Either a b
Left Reply
r

newtype VLinksResponse = VLinksResponse
    { VLinksResponse -> [[ByteString]]
vLinksLayers :: [[ByteString]]
    } deriving (Int -> VLinksResponse -> ShowS
[VLinksResponse] -> ShowS
VLinksResponse -> String
(Int -> VLinksResponse -> ShowS)
-> (VLinksResponse -> String)
-> ([VLinksResponse] -> ShowS)
-> Show VLinksResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VLinksResponse -> ShowS
showsPrec :: Int -> VLinksResponse -> ShowS
$cshow :: VLinksResponse -> String
show :: VLinksResponse -> String
$cshowList :: [VLinksResponse] -> ShowS
showList :: [VLinksResponse] -> ShowS
Show, VLinksResponse -> VLinksResponse -> Bool
(VLinksResponse -> VLinksResponse -> Bool)
-> (VLinksResponse -> VLinksResponse -> Bool) -> Eq VLinksResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VLinksResponse -> VLinksResponse -> Bool
== :: VLinksResponse -> VLinksResponse -> Bool
$c/= :: VLinksResponse -> VLinksResponse -> Bool
/= :: VLinksResponse -> VLinksResponse -> Bool
Eq)

instance RedisResult VLinksResponse where
    decode :: Reply -> Either Reply VLinksResponse
decode (MultiBulk (Just [Reply]
layers)) = [[ByteString]] -> VLinksResponse
VLinksResponse ([[ByteString]] -> VLinksResponse)
-> Either Reply [[ByteString]] -> Either Reply VLinksResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Reply -> Either Reply [ByteString])
-> [Reply] -> Either Reply [[ByteString]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply [ByteString]
forall a. RedisResult a => Reply -> Either Reply a
decode [Reply]
layers
    decode Reply
r = Reply -> Either Reply VLinksResponse
forall a b. a -> Either a b
Left Reply
r

newtype VLinksWithScoresResponse = VLinksWithScoresResponse
    { VLinksWithScoresResponse -> [[(ByteString, Double)]]
vLinksWithScoresLayers :: [[(ByteString, Double)]]
    } deriving (Int -> VLinksWithScoresResponse -> ShowS
[VLinksWithScoresResponse] -> ShowS
VLinksWithScoresResponse -> String
(Int -> VLinksWithScoresResponse -> ShowS)
-> (VLinksWithScoresResponse -> String)
-> ([VLinksWithScoresResponse] -> ShowS)
-> Show VLinksWithScoresResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VLinksWithScoresResponse -> ShowS
showsPrec :: Int -> VLinksWithScoresResponse -> ShowS
$cshow :: VLinksWithScoresResponse -> String
show :: VLinksWithScoresResponse -> String
$cshowList :: [VLinksWithScoresResponse] -> ShowS
showList :: [VLinksWithScoresResponse] -> ShowS
Show, VLinksWithScoresResponse -> VLinksWithScoresResponse -> Bool
(VLinksWithScoresResponse -> VLinksWithScoresResponse -> Bool)
-> (VLinksWithScoresResponse -> VLinksWithScoresResponse -> Bool)
-> Eq VLinksWithScoresResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VLinksWithScoresResponse -> VLinksWithScoresResponse -> Bool
== :: VLinksWithScoresResponse -> VLinksWithScoresResponse -> Bool
$c/= :: VLinksWithScoresResponse -> VLinksWithScoresResponse -> Bool
/= :: VLinksWithScoresResponse -> VLinksWithScoresResponse -> Bool
Eq)

instance RedisResult VLinksWithScoresResponse where
    decode :: Reply -> Either Reply VLinksWithScoresResponse
decode r :: Reply
r@(MultiBulk (Just [Reply]
layers)) =
        [[(ByteString, Double)]] -> VLinksWithScoresResponse
VLinksWithScoresResponse ([[(ByteString, Double)]] -> VLinksWithScoresResponse)
-> Either Reply [[(ByteString, Double)]]
-> Either Reply VLinksWithScoresResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Reply -> Either Reply [(ByteString, Double)])
-> [Reply] -> Either Reply [[(ByteString, Double)]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply [(ByteString, Double)]
forall {a} {a}.
(RedisResult a, RedisResult a) =>
Reply -> Either Reply [(a, a)]
decodeLayer [Reply]
layers
      where
        decodeLayer :: Reply -> Either Reply [(a, a)]
decodeLayer (MultiBulk (Just [Reply]
entries)) = [Reply] -> Either Reply [(a, a)]
forall {a} {a}.
(RedisResult a, RedisResult a) =>
[Reply] -> Either Reply [(a, a)]
pairs [Reply]
entries
        decodeLayer Reply
badReply = Reply -> Either Reply [(a, a)]
forall a b. a -> Either a b
Left Reply
badReply

        pairs :: [Reply] -> Either Reply [(a, a)]
pairs [] = [(a, a)] -> Either Reply [(a, a)]
forall a b. b -> Either a b
Right []
        pairs (Reply
nameReply:Reply
scoreReply:[Reply]
rest) =
            (:) ((a, a) -> [(a, a)] -> [(a, a)])
-> Either Reply (a, a) -> Either Reply ([(a, a)] -> [(a, a)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (a -> a -> (a, a)) -> Either Reply a -> Either Reply (a -> (a, a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
nameReply Either Reply (a -> (a, a)) -> Either Reply a -> Either Reply (a, a)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
scoreReply) Either Reply ([(a, a)] -> [(a, a)])
-> Either Reply [(a, a)] -> Either Reply [(a, a)]
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Reply] -> Either Reply [(a, a)]
pairs [Reply]
rest
        pairs [Reply]
_ = Reply -> Either Reply [(a, a)]
forall a b. a -> Either a b
Left Reply
r
    decode Reply
r = Reply -> Either Reply VLinksWithScoresResponse
forall a b. a -> Either a b
Left Reply
r

data VSimQuery
    = VSimByElement ByteString
    | VSimByFp32 ByteString
    | VSimByValues (NonEmpty Double)
    deriving (Int -> VSimQuery -> ShowS
[VSimQuery] -> ShowS
VSimQuery -> String
(Int -> VSimQuery -> ShowS)
-> (VSimQuery -> String)
-> ([VSimQuery] -> ShowS)
-> Show VSimQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VSimQuery -> ShowS
showsPrec :: Int -> VSimQuery -> ShowS
$cshow :: VSimQuery -> String
show :: VSimQuery -> String
$cshowList :: [VSimQuery] -> ShowS
showList :: [VSimQuery] -> ShowS
Show, VSimQuery -> VSimQuery -> Bool
(VSimQuery -> VSimQuery -> Bool)
-> (VSimQuery -> VSimQuery -> Bool) -> Eq VSimQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VSimQuery -> VSimQuery -> Bool
== :: VSimQuery -> VSimQuery -> Bool
$c/= :: VSimQuery -> VSimQuery -> Bool
/= :: VSimQuery -> VSimQuery -> Bool
Eq)

data VSimOpts = VSimOpts
    { VSimOpts -> Maybe Integer
vSimCount :: Maybe Integer
    , VSimOpts -> Maybe Double
vSimEpsilon :: Maybe Double
    , VSimOpts -> Maybe Integer
vSimEf :: Maybe Integer
    , VSimOpts -> Maybe ByteString
vSimFilter :: Maybe ByteString
    , VSimOpts -> Maybe Integer
vSimFilterEf :: Maybe Integer
    , VSimOpts -> Bool
vSimTruth :: Bool
    , VSimOpts -> Bool
vSimNoThread :: Bool
    } deriving (Int -> VSimOpts -> ShowS
[VSimOpts] -> ShowS
VSimOpts -> String
(Int -> VSimOpts -> ShowS)
-> (VSimOpts -> String) -> ([VSimOpts] -> ShowS) -> Show VSimOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VSimOpts -> ShowS
showsPrec :: Int -> VSimOpts -> ShowS
$cshow :: VSimOpts -> String
show :: VSimOpts -> String
$cshowList :: [VSimOpts] -> ShowS
showList :: [VSimOpts] -> ShowS
Show, VSimOpts -> VSimOpts -> Bool
(VSimOpts -> VSimOpts -> Bool)
-> (VSimOpts -> VSimOpts -> Bool) -> Eq VSimOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VSimOpts -> VSimOpts -> Bool
== :: VSimOpts -> VSimOpts -> Bool
$c/= :: VSimOpts -> VSimOpts -> Bool
/= :: VSimOpts -> VSimOpts -> Bool
Eq)

defaultVSimOpts :: VSimOpts
defaultVSimOpts :: VSimOpts
defaultVSimOpts = VSimOpts
    { vSimCount :: Maybe Integer
vSimCount = Maybe Integer
forall a. Maybe a
Nothing
    , vSimEpsilon :: Maybe Double
vSimEpsilon = Maybe Double
forall a. Maybe a
Nothing
    , vSimEf :: Maybe Integer
vSimEf = Maybe Integer
forall a. Maybe a
Nothing
    , vSimFilter :: Maybe ByteString
vSimFilter = Maybe ByteString
forall a. Maybe a
Nothing
    , vSimFilterEf :: Maybe Integer
vSimFilterEf = Maybe Integer
forall a. Maybe a
Nothing
    , vSimTruth :: Bool
vSimTruth = Bool
False
    , vSimNoThread :: Bool
vSimNoThread = Bool
False
    }

data VSimWithAttribsResult = VSimWithAttribsResult
    { VSimWithAttribsResult -> ByteString
vSimResultElement :: ByteString
    , VSimWithAttribsResult -> Double
vSimResultScore :: Double
    , VSimWithAttribsResult -> Maybe ByteString
vSimResultAttributes :: Maybe ByteString
    } deriving (Int -> VSimWithAttribsResult -> ShowS
[VSimWithAttribsResult] -> ShowS
VSimWithAttribsResult -> String
(Int -> VSimWithAttribsResult -> ShowS)
-> (VSimWithAttribsResult -> String)
-> ([VSimWithAttribsResult] -> ShowS)
-> Show VSimWithAttribsResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VSimWithAttribsResult -> ShowS
showsPrec :: Int -> VSimWithAttribsResult -> ShowS
$cshow :: VSimWithAttribsResult -> String
show :: VSimWithAttribsResult -> String
$cshowList :: [VSimWithAttribsResult] -> ShowS
showList :: [VSimWithAttribsResult] -> ShowS
Show, VSimWithAttribsResult -> VSimWithAttribsResult -> Bool
(VSimWithAttribsResult -> VSimWithAttribsResult -> Bool)
-> (VSimWithAttribsResult -> VSimWithAttribsResult -> Bool)
-> Eq VSimWithAttribsResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VSimWithAttribsResult -> VSimWithAttribsResult -> Bool
== :: VSimWithAttribsResult -> VSimWithAttribsResult -> Bool
$c/= :: VSimWithAttribsResult -> VSimWithAttribsResult -> Bool
/= :: VSimWithAttribsResult -> VSimWithAttribsResult -> Bool
Eq)

instance RedisResult VSimWithAttribsResult where
    decode :: Reply -> Either Reply VSimWithAttribsResult
decode (MultiBulk (Just [Reply
elementReply, Reply
scoreReply, Bulk Maybe ByteString
Nothing])) =
        ByteString -> Double -> Maybe ByteString -> VSimWithAttribsResult
VSimWithAttribsResult
            (ByteString -> Double -> Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply ByteString
-> Either
     Reply (Double -> Maybe ByteString -> VSimWithAttribsResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
elementReply
            Either Reply (Double -> Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply Double
-> Either Reply (Maybe ByteString -> VSimWithAttribsResult)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
scoreReply
            Either Reply (Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply (Maybe ByteString)
-> Either Reply VSimWithAttribsResult
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe ByteString -> Either Reply (Maybe ByteString)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe ByteString
forall a. Maybe a
Nothing
    decode (MultiBulk (Just [Reply
elementReply, Reply
scoreReply, Reply
attributesReply])) =
        ByteString -> Double -> Maybe ByteString -> VSimWithAttribsResult
VSimWithAttribsResult
            (ByteString -> Double -> Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply ByteString
-> Either
     Reply (Double -> Maybe ByteString -> VSimWithAttribsResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
elementReply
            Either Reply (Double -> Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply Double
-> Either Reply (Maybe ByteString -> VSimWithAttribsResult)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
scoreReply
            Either Reply (Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply (Maybe ByteString)
-> Either Reply VSimWithAttribsResult
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString)
-> Either Reply ByteString -> Either Reply (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
attributesReply)
    decode Reply
r = Reply -> Either Reply VSimWithAttribsResult
forall a b. a -> Either a b
Left Reply
r

newtype VSimWithAttribsResponse = VSimWithAttribsResponse
    { VSimWithAttribsResponse -> [VSimWithAttribsResult]
vSimWithAttribsResults :: [VSimWithAttribsResult]
    } deriving (Int -> VSimWithAttribsResponse -> ShowS
[VSimWithAttribsResponse] -> ShowS
VSimWithAttribsResponse -> String
(Int -> VSimWithAttribsResponse -> ShowS)
-> (VSimWithAttribsResponse -> String)
-> ([VSimWithAttribsResponse] -> ShowS)
-> Show VSimWithAttribsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VSimWithAttribsResponse -> ShowS
showsPrec :: Int -> VSimWithAttribsResponse -> ShowS
$cshow :: VSimWithAttribsResponse -> String
show :: VSimWithAttribsResponse -> String
$cshowList :: [VSimWithAttribsResponse] -> ShowS
showList :: [VSimWithAttribsResponse] -> ShowS
Show, VSimWithAttribsResponse -> VSimWithAttribsResponse -> Bool
(VSimWithAttribsResponse -> VSimWithAttribsResponse -> Bool)
-> (VSimWithAttribsResponse -> VSimWithAttribsResponse -> Bool)
-> Eq VSimWithAttribsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VSimWithAttribsResponse -> VSimWithAttribsResponse -> Bool
== :: VSimWithAttribsResponse -> VSimWithAttribsResponse -> Bool
$c/= :: VSimWithAttribsResponse -> VSimWithAttribsResponse -> Bool
/= :: VSimWithAttribsResponse -> VSimWithAttribsResponse -> Bool
Eq)

instance RedisResult VSimWithAttribsResponse where
    decode :: Reply -> Either Reply VSimWithAttribsResponse
decode r :: Reply
r@(MultiBulk (Just [Reply]
replies)) =
        [VSimWithAttribsResult] -> VSimWithAttribsResponse
VSimWithAttribsResponse ([VSimWithAttribsResult] -> VSimWithAttribsResponse)
-> Either Reply [VSimWithAttribsResult]
-> Either Reply VSimWithAttribsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Reply] -> Either Reply [VSimWithAttribsResult]
triples [Reply]
replies
      where
        triples :: [Reply] -> Either Reply [VSimWithAttribsResult]
triples [] = [VSimWithAttribsResult] -> Either Reply [VSimWithAttribsResult]
forall a b. b -> Either a b
Right []
        triples (Reply
elementReply:Reply
scoreReply:Bulk Maybe ByteString
Nothing:[Reply]
rest) = do
            result <- ByteString -> Double -> Maybe ByteString -> VSimWithAttribsResult
VSimWithAttribsResult
                (ByteString -> Double -> Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply ByteString
-> Either
     Reply (Double -> Maybe ByteString -> VSimWithAttribsResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
elementReply
                Either Reply (Double -> Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply Double
-> Either Reply (Maybe ByteString -> VSimWithAttribsResult)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
scoreReply
                Either Reply (Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply (Maybe ByteString)
-> Either Reply VSimWithAttribsResult
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe ByteString -> Either Reply (Maybe ByteString)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe ByteString
forall a. Maybe a
Nothing
            (result :) <$> triples rest
        triples (Reply
elementReply:Reply
scoreReply:Reply
attributesReply:[Reply]
rest) = do
            result <- ByteString -> Double -> Maybe ByteString -> VSimWithAttribsResult
VSimWithAttribsResult
                (ByteString -> Double -> Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply ByteString
-> Either
     Reply (Double -> Maybe ByteString -> VSimWithAttribsResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
elementReply
                Either Reply (Double -> Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply Double
-> Either Reply (Maybe ByteString -> VSimWithAttribsResult)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
scoreReply
                Either Reply (Maybe ByteString -> VSimWithAttribsResult)
-> Either Reply (Maybe ByteString)
-> Either Reply VSimWithAttribsResult
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString)
-> Either Reply ByteString -> Either Reply (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
attributesReply)
            (result :) <$> triples rest
        triples [Reply]
_ = Reply -> Either Reply [VSimWithAttribsResult]
forall a b. a -> Either a b
Left Reply
r
    decode Reply
r = Reply -> Either Reply VSimWithAttribsResponse
forall a b. a -> Either a b
Left Reply
r

-- |Redis default 'VAddOpts'. Equivalent to omitting all optional parameters.
defaultVAddOpts :: VAddOpts
defaultVAddOpts :: VAddOpts
defaultVAddOpts = VAddOpts
    { vAddReduceDim :: Maybe Integer
vAddReduceDim = Maybe Integer
forall a. Maybe a
Nothing
    , vAddCas :: Bool
vAddCas = Bool
False
    , vAddQuantization :: Maybe VAddQuantization
vAddQuantization = Maybe VAddQuantization
forall a. Maybe a
Nothing
    , vAddBuildExplorationFactor :: Maybe Integer
vAddBuildExplorationFactor = Maybe Integer
forall a. Maybe a
Nothing
    , vAddAttributes :: Maybe ByteString
vAddAttributes = Maybe ByteString
forall a. Maybe a
Nothing
    , vAddNumLinks :: Maybe Integer
vAddNumLinks = Maybe Integer
forall a. Maybe a
Nothing
    }

-- |Adds a new element to a vector set, or updates its vector if it already exists (<https://redis.io/commands/vadd>).
--
-- /O(log(N))/ for each element added, where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.0.0
vadd
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that will hold the vector set data.
    -> NonEmpty Double
    {- ^ The vector values as floating point numbers.

       This uses the `VALUES` argument form and automatically supplies the number of vector elements.
     -}
    -> ByteString -- ^ The name of the element that is being added to the vector set.
    -> m (f Bool)
vadd :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty Double -> ByteString -> m (f Bool)
vadd ByteString
key NonEmpty Double
vector ByteString
element = ByteString
-> NonEmpty Double -> ByteString -> VAddOpts -> m (f Bool)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty Double -> ByteString -> VAddOpts -> m (f Bool)
vaddOpts ByteString
key NonEmpty Double
vector ByteString
element VAddOpts
defaultVAddOpts

-- |Adds a new element to a vector set, or updates its vector if it already exists (<https://redis.io/commands/vadd>).
--
-- /O(log(N))/ for each element added, where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.0.0
vaddOpts
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that will hold the vector set data.
    -> NonEmpty Double -- ^ The vector values as floating point numbers.
    -> ByteString -- ^ The name of the element that is being added to the vector set.
    -> VAddOpts
    {- ^ Additional parameters.

       `REDUCE dim` reduces the dimensionality of the vector using random projection.
       `CAS` performs the slow neighbor candidate collection in the background.
       `NOQUANT`, `Q8`, and `BIN` control quantization and are mutually exclusive.
       `EF` sets the build exploration factor.
       `SETATTR` associates attributes with the entry.
       `M` sets the maximum number of graph links per node.
     -}
    -> m (f Bool)
vaddOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty Double -> ByteString -> VAddOpts -> m (f Bool)
vaddOpts ByteString
key NonEmpty Double
vector ByteString
element VAddOpts{Bool
Maybe Integer
Maybe ByteString
Maybe VAddQuantization
vAddReduceDim :: VAddOpts -> Maybe Integer
vAddCas :: VAddOpts -> Bool
vAddQuantization :: VAddOpts -> Maybe VAddQuantization
vAddBuildExplorationFactor :: VAddOpts -> Maybe Integer
vAddAttributes :: VAddOpts -> Maybe ByteString
vAddNumLinks :: VAddOpts -> Maybe Integer
vAddReduceDim :: Maybe Integer
vAddCas :: Bool
vAddQuantization :: Maybe VAddQuantization
vAddBuildExplorationFactor :: Maybe Integer
vAddAttributes :: Maybe ByteString
vAddNumLinks :: Maybe Integer
..} =
    [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Bool)) -> [ByteString] -> m (f Bool)
forall a b. (a -> b) -> a -> b
$
        [ByteString
"VADD", ByteString
key]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
reduceArg
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"VALUES", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty Double -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty Double
vector)]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (Double -> ByteString) -> [Double] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode (NonEmpty Double -> [Double]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty Double
vector)
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
element]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
casArg
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
quantizationArg
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
efArg
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
attributesArg
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
numLinksArg
  where
    reduceArg :: [ByteString]
reduceArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
dim -> [ByteString
"REDUCE", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
dim]) Maybe Integer
vAddReduceDim
    casArg :: [ByteString]
casArg = [ByteString
"CAS" | Bool
vAddCas]
    quantizationArg :: [ByteString]
quantizationArg = [ByteString]
-> (VAddQuantization -> [ByteString])
-> Maybe VAddQuantization
-> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\VAddQuantization
quantization -> [VAddQuantization -> ByteString
forall a. RedisArg a => a -> ByteString
encode VAddQuantization
quantization]) Maybe VAddQuantization
vAddQuantization
    efArg :: [ByteString]
efArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
ef -> [ByteString
"EF", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
ef]) Maybe Integer
vAddBuildExplorationFactor
    attributesArg :: [ByteString]
attributesArg = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
attributes -> [ByteString
"SETATTR", ByteString
attributes]) Maybe ByteString
vAddAttributes
    numLinksArg :: [ByteString]
numLinksArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
numLinks -> [ByteString
"M", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
numLinks]) Maybe Integer
vAddNumLinks

-- |Return the number of elements in the specified vector set (<https://redis.io/commands/vcard>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vcard
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> m (f Integer)
vcard :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
vcard ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VCARD", ByteString
key]

-- |Return the number of dimensions of the vectors in the specified vector set (<https://redis.io/commands/vdim>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vdim
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> m (f Integer)
vdim :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
vdim ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VDIM", ByteString
key]

-- |Return the approximate vector associated with a given element in the vector set (<https://redis.io/commands/vemb>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vemb
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> ByteString -- ^ The name of the element whose vector you want to retrieve.
    -> m (f [Double])
vemb :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f [Double])
vemb ByteString
key ByteString
element = [ByteString] -> m (f [Double])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VEMB", ByteString
key, ByteString
element]

-- |Return the raw internal representation of the vector associated with a given element in the vector set (<https://redis.io/commands/vemb>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vembRaw
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> ByteString -- ^ The name of the element whose vector you want to retrieve.
    -> m (f (Maybe VEmbRawResponse))
vembRaw :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f (Maybe VEmbRawResponse))
vembRaw ByteString
key ByteString
element = [ByteString] -> m (f (Maybe VEmbRawResponse))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VEMB", ByteString
key, ByteString
element, ByteString
"RAW"]

-- |Retrieve the JSON attributes of an element in a vector set (<https://redis.io/commands/vgetattr>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vgetattr
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> ByteString -- ^ The name of the element whose attributes you want to retrieve.
    -> m (f (Maybe ByteString))
vgetattr :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f (Maybe ByteString))
vgetattr ByteString
key ByteString
element = [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VGETATTR", ByteString
key, ByteString
element]

-- |Return metadata and internal details about a vector set (<https://redis.io/commands/vinfo>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vinfo
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> m (f (Maybe VInfoResponse))
vinfo :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe VInfoResponse))
vinfo ByteString
key = [ByteString] -> m (f (Maybe VInfoResponse))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VINFO", ByteString
key]

-- |Check if an element exists in a vector set (<https://redis.io/commands/vismember>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vismember
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> ByteString -- ^ The name of the element to check.
    -> m (f Bool)
vismember :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Bool)
vismember ByteString
key ByteString
element = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VISMEMBER", ByteString
key, ByteString
element]

-- |Return the neighbors of a specified element in a vector set (<https://redis.io/commands/vlinks>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vlinks
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> ByteString -- ^ The name of the element whose HNSW neighbors you want to inspect.
    -> m (f (Maybe VLinksResponse))
vlinks :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f (Maybe VLinksResponse))
vlinks ByteString
key ByteString
element = [ByteString] -> m (f (Maybe VLinksResponse))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VLINKS", ByteString
key, ByteString
element]

-- |Return the neighbors of a specified element in a vector set together with their similarity scores (<https://redis.io/commands/vlinks>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vlinksWithScores
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> ByteString -- ^ The name of the element whose HNSW neighbors you want to inspect.
    -> m (f (Maybe VLinksWithScoresResponse))
vlinksWithScores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f (Maybe VLinksWithScoresResponse))
vlinksWithScores ByteString
key ByteString
element = [ByteString] -> m (f (Maybe VLinksWithScoresResponse))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VLINKS", ByteString
key, ByteString
element, ByteString
"WITHSCORES"]

-- |Return one random element from a vector set (<https://redis.io/commands/vrandmember>).
--
-- /O(N)/ where /N/ is the absolute value of the count argument.
--
-- Since Redis 8.0.0
vrandmember
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> m (f (Maybe ByteString))
vrandmember :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
vrandmember ByteString
key = [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VRANDMEMBER", ByteString
key]

-- |Return one or multiple random elements from a vector set (<https://redis.io/commands/vrandmember>).
--
-- /O(N)/ where /N/ is the absolute value of the count argument.
--
-- Since Redis 8.0.0
vrandmemberCount
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> Integer
    {- ^ The number of elements to return.

       Positive values return distinct elements; negative values allow duplicates.
     -}
    -> m (f [ByteString])
vrandmemberCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f [ByteString])
vrandmemberCount ByteString
key Integer
count = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VRANDMEMBER", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Returns elements in a lexicographical range (<https://redis.io/commands/vrange>).
--
-- /O(log(K)+M)/ where /K/ is the number of elements in the start prefix, and /M/ is the number of elements returned. In practical terms, the command is just /O(M)/.
--
-- Since Redis 8.4.0
vrange
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the vector set key from which to retrieve elements.
    -> ByteString
    {- ^ The starting point of the lexicographical range.

       Use a value prefixed with `[` for an inclusive bound, a value prefixed with `(` for an exclusive bound, or `-` for the minimum element.
     -}
    -> ByteString
    {- ^ The ending point of the lexicographical range.

       Use a value prefixed with `[` for an inclusive bound, a value prefixed with `(` for an exclusive bound, or `+` for the maximum element.
     -}
    -> m (f [ByteString])
vrange :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f [ByteString])
vrange ByteString
key ByteString
start ByteString
end = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VRANGE", ByteString
key, ByteString
start, ByteString
end]

-- |Returns elements in a lexicographical range (<https://redis.io/commands/vrange>).
--
-- /O(log(K)+M)/ where /K/ is the number of elements in the start prefix, and /M/ is the number of elements returned. In practical terms, the command is just /O(M)/.
--
-- Since Redis 8.4.0
vrangeCount
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the vector set key from which to retrieve elements.
    -> ByteString -- ^ The starting point of the lexicographical range.
    -> ByteString -- ^ The ending point of the lexicographical range.
    -> Integer
    {- ^ The maximum number of elements to return.

       If `count` is negative, the command returns all elements in the specified range.
     -}
    -> m (f [ByteString])
vrangeCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> Integer -> m (f [ByteString])
vrangeCount ByteString
key ByteString
start ByteString
end Integer
count =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VRANGE", ByteString
key, ByteString
start, ByteString
end, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Remove an element from a vector set (<https://redis.io/commands/vrem>).
--
-- /O(log(N))/ for each element removed, where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.0.0
vrem
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> ByteString -- ^ The name of the element to remove from the vector set.
    -> m (f Bool)
vrem :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Bool)
vrem ByteString
key ByteString
element = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VREM", ByteString
key, ByteString
element]

-- |Associate or remove the JSON attributes of an element in a vector set (<https://redis.io/commands/vsetattr>).
--
-- /O(1)/
--
-- Since Redis 8.0.0
vsetattr
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set.
    -> ByteString -- ^ The name of the element in the vector set.
    -> ByteString
    {- ^ The attributes as a JSON object string.

       Use the empty string to remove existing attributes.
     -}
    -> m (f Bool)
vsetattr :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Bool)
vsetattr ByteString
key ByteString
element ByteString
attributes = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"VSETATTR", ByteString
key, ByteString
element, ByteString
attributes]

-- |Return elements similar to a given vector or element (<https://redis.io/commands/vsim>).
--
-- /O(log(N))/ where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.0.0
vsim
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set data.
    -> VSimQuery
    {- ^ Query vector source.

       Use `VSimByElement` to refer to an existing element, `VSimByFp32` for binary float format, or `VSimByValues` for a list of float values.
     -}
    -> m (f [ByteString])
vsim :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> VSimQuery -> m (f [ByteString])
vsim ByteString
key VSimQuery
query = ByteString -> VSimQuery -> VSimOpts -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> VSimQuery -> VSimOpts -> m (f [ByteString])
vsimOpts ByteString
key VSimQuery
query VSimOpts
defaultVSimOpts

-- |Return elements similar to a given vector or element (<https://redis.io/commands/vsim>).
--
-- /O(log(N))/ where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.0.0
vsimOpts
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set data.
    -> VSimQuery -- ^ Query vector source.
    -> VSimOpts
    {- ^ Additional search options.

       `COUNT` limits the number of returned results.
       `EPSILON` filters out elements that are too far from the query vector.
       `EF` controls the exploration factor.
       `FILTER` applies a filtering expression and `FILTER-EF` limits filtering effort.
       `TRUTH` forces an exact linear scan.
       `NOTHREAD` executes the search in the main thread.
     -}
    -> m (f [ByteString])
vsimOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> VSimQuery -> VSimOpts -> m (f [ByteString])
vsimOpts ByteString
key VSimQuery
query VSimOpts
opts =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [ByteString]))
-> [ByteString] -> m (f [ByteString])
forall a b. (a -> b) -> a -> b
$ [ByteString
"VSIM", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ VSimQuery -> [ByteString]
vSimQueryArgs VSimQuery
query [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ VSimOpts -> [ByteString]
vSimOptsArgs VSimOpts
opts

-- |Return elements similar to a given vector or element together with their similarity scores (<https://redis.io/commands/vsim>).
--
-- /O(log(N))/ where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.0.0
vsimWithScores
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set data.
    -> VSimQuery -- ^ Query vector source.
    -> m (f [(ByteString, Double)])
vsimWithScores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> VSimQuery -> m (f [(ByteString, Double)])
vsimWithScores ByteString
key VSimQuery
query = ByteString -> VSimQuery -> VSimOpts -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> VSimQuery -> VSimOpts -> m (f [(ByteString, Double)])
vsimWithScoresOpts ByteString
key VSimQuery
query VSimOpts
defaultVSimOpts

-- |Return elements similar to a given vector or element together with their similarity scores (<https://redis.io/commands/vsim>).
--
-- /O(log(N))/ where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.0.0
vsimWithScoresOpts
    :: (RedisCtx m f)
    => ByteString
    -> VSimQuery
    -> VSimOpts
    -> m (f [(ByteString, Double)])
vsimWithScoresOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> VSimQuery -> VSimOpts -> m (f [(ByteString, Double)])
vsimWithScoresOpts ByteString
key VSimQuery
query VSimOpts
opts =
    [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [(ByteString, Double)]))
-> [ByteString] -> m (f [(ByteString, Double)])
forall a b. (a -> b) -> a -> b
$ [ByteString
"VSIM", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ VSimQuery -> [ByteString]
vSimQueryArgs VSimQuery
query [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"WITHSCORES"] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ VSimOpts -> [ByteString]
vSimOptsArgs VSimOpts
opts

-- |Return elements similar to a given vector or element together with their similarity scores and JSON attributes (<https://redis.io/commands/vsim>).
--
-- /O(log(N))/ where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.2.0
vsimWithScoresWithAttribs
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key that holds the vector set data.
    -> VSimQuery -- ^ Query vector source.
    -> m (f VSimWithAttribsResponse)
vsimWithScoresWithAttribs :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> VSimQuery -> m (f VSimWithAttribsResponse)
vsimWithScoresWithAttribs ByteString
key VSimQuery
query =
    ByteString
-> VSimQuery -> VSimOpts -> m (f VSimWithAttribsResponse)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> VSimQuery -> VSimOpts -> m (f VSimWithAttribsResponse)
vsimWithScoresWithAttribsOpts ByteString
key VSimQuery
query VSimOpts
defaultVSimOpts

-- |Return elements similar to a given vector or element together with their similarity scores and JSON attributes (<https://redis.io/commands/vsim>).
--
-- /O(log(N))/ where /N/ is the number of elements in the vector set.
--
-- Since Redis 8.2.0
vsimWithScoresWithAttribsOpts
    :: (RedisCtx m f)
    => ByteString
    -> VSimQuery
    -> VSimOpts
    -> m (f VSimWithAttribsResponse)
vsimWithScoresWithAttribsOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> VSimQuery -> VSimOpts -> m (f VSimWithAttribsResponse)
vsimWithScoresWithAttribsOpts ByteString
key VSimQuery
query VSimOpts
opts =
    [ByteString] -> m (f VSimWithAttribsResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f VSimWithAttribsResponse))
-> [ByteString] -> m (f VSimWithAttribsResponse)
forall a b. (a -> b) -> a -> b
$ [ByteString
"VSIM", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ VSimQuery -> [ByteString]
vSimQueryArgs VSimQuery
query [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"WITHSCORES", ByteString
"WITHATTRIBS"] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ VSimOpts -> [ByteString]
vSimOptsArgs VSimOpts
opts

vSimQueryArgs :: VSimQuery -> [ByteString]
vSimQueryArgs :: VSimQuery -> [ByteString]
vSimQueryArgs VSimQuery
query =
    case VSimQuery
query of
        VSimByElement ByteString
element -> [ByteString
"ELE", ByteString
element]
        VSimByFp32 ByteString
rawVector -> [ByteString
"FP32", ByteString
rawVector]
        VSimByValues NonEmpty Double
values ->
            [ByteString
"VALUES", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty Double -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty Double
values)] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (Double -> ByteString) -> [Double] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode (NonEmpty Double -> [Double]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty Double
values)

vSimOptsArgs :: VSimOpts -> [ByteString]
vSimOptsArgs :: VSimOpts -> [ByteString]
vSimOptsArgs VSimOpts{Bool
Maybe Double
Maybe Integer
Maybe ByteString
vSimCount :: VSimOpts -> Maybe Integer
vSimEpsilon :: VSimOpts -> Maybe Double
vSimEf :: VSimOpts -> Maybe Integer
vSimFilter :: VSimOpts -> Maybe ByteString
vSimFilterEf :: VSimOpts -> Maybe Integer
vSimTruth :: VSimOpts -> Bool
vSimNoThread :: VSimOpts -> Bool
vSimCount :: Maybe Integer
vSimEpsilon :: Maybe Double
vSimEf :: Maybe Integer
vSimFilter :: Maybe ByteString
vSimFilterEf :: Maybe Integer
vSimTruth :: Bool
vSimNoThread :: Bool
..} =
    [ByteString]
countArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
epsilonArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
efArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
filterArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
filterEfArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
truthArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
noThreadArg
  where
    countArg :: [ByteString]
countArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
count -> [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]) Maybe Integer
vSimCount
    epsilonArg :: [ByteString]
epsilonArg = [ByteString]
-> (Double -> [ByteString]) -> Maybe Double -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Double
epsilon -> [ByteString
"EPSILON", Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
epsilon]) Maybe Double
vSimEpsilon
    efArg :: [ByteString]
efArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
ef -> [ByteString
"EF", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
ef]) Maybe Integer
vSimEf
    filterArg :: [ByteString]
filterArg = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
expression -> [ByteString
"FILTER", ByteString
expression]) Maybe ByteString
vSimFilter
    filterEfArg :: [ByteString]
filterEfArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
filterEf -> [ByteString
"FILTER-EF", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
filterEf]) Maybe Integer
vSimFilterEf
    truthArg :: [ByteString]
truthArg = [ByteString
"TRUTH" | Bool
vSimTruth]
    noThreadArg :: [ByteString]
noThreadArg = [ByteString
"NOTHREAD" | Bool
vSimNoThread]

-- |Atomically transfer a key from a Redis instance to another one (<http://redis.io/commands/migrate>). The Redis command @MIGRATE@ is split up into 'migrate', 'migrateMultiple'. Since Redis 2.6.0
migrate
    :: (RedisCtx m f)
    => ByteString -- ^ host
    -> ByteString -- ^ port
    -> ByteString -- ^ key
    -> Integer -- ^ destinationDb
    -> Integer -- ^ timeout
    -> m (f Status)
migrate :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> Integer -> Integer -> m (f Status)
migrate ByteString
host ByteString
port ByteString
key Integer
destinationDb Integer
timeout =
  [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"MIGRATE", ByteString
host, ByteString
port, ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
destinationDb, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
timeout]

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

-- |Options for the 'migrate' command.
data MigrateOpts = MigrateOpts
    { MigrateOpts -> Bool
migrateCopy    :: Bool
    , MigrateOpts -> Bool
migrateReplace :: Bool
    , MigrateOpts -> Maybe MigrateAuth
migrateAuth :: Maybe MigrateAuth
    } deriving (Int -> MigrateOpts -> ShowS
[MigrateOpts] -> ShowS
MigrateOpts -> String
(Int -> MigrateOpts -> ShowS)
-> (MigrateOpts -> String)
-> ([MigrateOpts] -> ShowS)
-> Show MigrateOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MigrateOpts -> ShowS
showsPrec :: Int -> MigrateOpts -> ShowS
$cshow :: MigrateOpts -> String
show :: MigrateOpts -> String
$cshowList :: [MigrateOpts] -> ShowS
showList :: [MigrateOpts] -> ShowS
Show, MigrateOpts -> MigrateOpts -> Bool
(MigrateOpts -> MigrateOpts -> Bool)
-> (MigrateOpts -> MigrateOpts -> Bool) -> Eq MigrateOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MigrateOpts -> MigrateOpts -> Bool
== :: MigrateOpts -> MigrateOpts -> Bool
$c/= :: MigrateOpts -> MigrateOpts -> Bool
/= :: MigrateOpts -> MigrateOpts -> Bool
Eq)

-- |Redis default 'MigrateOpts'. Equivalent to omitting all optional parameters.
--
-- @
-- MigrateOpts
--     { migrateCopy    = False -- remove the key from the local instance
--     , migrateReplace = False -- don't replace existing key on the remote instance
--     , migrateAuth = Nothing
--     }
-- @
--
defaultMigrateOpts :: MigrateOpts
defaultMigrateOpts :: MigrateOpts
defaultMigrateOpts = MigrateOpts
    { migrateCopy :: Bool
migrateCopy    = Bool
False
    , migrateReplace :: Bool
migrateReplace = Bool
False
    , migrateAuth :: Maybe MigrateAuth
migrateAuth = Maybe MigrateAuth
forall a. Maybe a
Nothing
    }

-- |Atomically transfer a key from a Redis instance to another one (<http://redis.io/commands/migrate>). The Redis command @MIGRATE@ is split up into 'migrate', 'migrateMultiple'. Since Redis 2.6.0
migrateMultiple
    :: (RedisCtx m f)
    => ByteString   -- ^ host
    -> ByteString   -- ^ port
    -> Integer      -- ^ destinationDb
    -> Integer      -- ^ timeout
    -> MigrateOpts
    -> [ByteString] -- ^ keys
    -> m (f Status)
migrateMultiple :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> Integer
-> Integer
-> MigrateOpts
-> [ByteString]
-> m (f Status)
migrateMultiple ByteString
host ByteString
port Integer
destinationDb Integer
timeout MigrateOpts{Bool
Maybe MigrateAuth
migrateCopy :: MigrateOpts -> Bool
migrateReplace :: MigrateOpts -> Bool
migrateAuth :: MigrateOpts -> Maybe MigrateAuth
migrateCopy :: Bool
migrateReplace :: Bool
migrateAuth :: Maybe MigrateAuth
..} [ByteString]
keys =
    [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]] -> [ByteString]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ByteString
"MIGRATE", ByteString
host, ByteString
port, ByteString
empty, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
destinationDb, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
timeout],
            [ByteString]
auth_, [ByteString]
copyArg, [ByteString]
replace, [ByteString]
keys]
  where
    copyArg :: [ByteString]
copyArg = [ByteString
"COPY" | Bool
migrateCopy]
    replace :: [ByteString]
replace = [ByteString
"REPLACE" | Bool
migrateReplace]
    auth_ :: [ByteString]
auth_ = case Maybe MigrateAuth
migrateAuth of
     Maybe MigrateAuth
Nothing -> []
     Just (MigrateAuth ByteString
pass)  -> [ByteString
"AUTH", ByteString
pass]
     Just (MigrateAuth2 ByteString
user ByteString
pass)  -> [ByteString
"AUTH2", ByteString
user, ByteString
pass]


-- |Create a key using the provided serialized value, previously obtained using DUMP (<http://redis.io/commands/restore>). The Redis command @RESTORE@ is split up into 'restore', 'restoreReplace'. Since Redis 2.6.0
restore
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ timeToLive
    -> ByteString -- ^ serializedValue
    -> m (f Status)
restore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> ByteString -> m (f Status)
restore ByteString
key Integer
timeToLive ByteString
serializedValue =
  [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"RESTORE", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
timeToLive, ByteString
serializedValue]

data RestoreOpts = RestoreOpts
  { RestoreOpts -> Bool
restoreOptsReplace :: Bool
  , RestoreOpts -> Bool
restoreOptsAbsTTL :: Bool
  , RestoreOpts -> Maybe Integer
restoreOptsIdle  :: Maybe Integer
  , RestoreOpts -> Maybe Integer
restoreOptsFreq :: Maybe Integer
  }

-- |Create a key using the provided serialized value, previously obtained using DUMP (<http://redis.io/commands/restore>). The Redis command @RESTORE@ is split up into 'restore', 'restoreReplace'. Since Redis 2.6.0
restoreOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ timeToLive
    -> ByteString -- ^ serializedValue
    -> RestoreOpts -- ^ restore options
    -> m (f Status)
restoreOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> ByteString -> RestoreOpts -> m (f Status)
restoreOpts ByteString
key Integer
timeToLive ByteString
serializedValue RestoreOpts{Bool
Maybe Integer
restoreOptsReplace :: RestoreOpts -> Bool
restoreOptsAbsTTL :: RestoreOpts -> Bool
restoreOptsIdle :: RestoreOpts -> Maybe Integer
restoreOptsFreq :: RestoreOpts -> Maybe Integer
restoreOptsReplace :: Bool
restoreOptsAbsTTL :: Bool
restoreOptsIdle :: Maybe Integer
restoreOptsFreq :: Maybe Integer
..} =
  [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest (ByteString
"RESTORE"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
keyByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
timeToLiveByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
serializedValueByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[ByteString]
rest) where
  rest :: [ByteString]
rest =  [ByteString]
replace [ByteString] -> [ByteString] -> [ByteString]
forall a. Semigroup a => a -> a -> a
<> [ByteString]
absttl [ByteString] -> [ByteString] -> [ByteString]
forall a. Semigroup a => a -> a -> a
<> [ByteString]
idle [ByteString] -> [ByteString] -> [ByteString]
forall a. Semigroup a => a -> a -> a
<> [ByteString]
freq
  replace :: [ByteString]
replace = [ByteString
"REPLACE" | Bool
restoreOptsReplace]
  absttl :: [ByteString]
absttl  = [ByteString
"ABSTTL" | Bool
restoreOptsAbsTTL]
  idle :: [ByteString]
idle    = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
i -> [ByteString
"IDLE", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
i]) Maybe Integer
restoreOptsIdle
  freq :: [ByteString]
freq    = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
f -> [ByteString
"FREQ", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
f]) Maybe Integer
restoreOptsFreq

-- |Create a key using the provided serialized value, previously obtained using DUMP (<http://redis.io/commands/restore>). The Redis command @RESTORE@ is split up into 'restore', 'restoreReplace'. Since Redis 2.6.0

restoreReplace
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ timeToLive
    -> ByteString -- ^ serializedValue
    -> m (f Status)
restoreReplace :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> ByteString -> m (f Status)
restoreReplace ByteString
key Integer
timeToLive ByteString
serializedValue =
  [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"RESTORE", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
timeToLive, ByteString
serializedValue, ByteString
"REPLACE"]

-- | Options for the 'copy' command.
data CopyOpts = CopyOpts
  { CopyOpts -> Maybe Integer
copyDestinationDb :: Maybe Integer -- ^ Destination database number.
  , CopyOpts -> Bool
copyReplace :: Bool -- ^ Replace the destination key if it already exists.
  } deriving (Int -> CopyOpts -> ShowS
[CopyOpts] -> ShowS
CopyOpts -> String
(Int -> CopyOpts -> ShowS)
-> (CopyOpts -> String) -> ([CopyOpts] -> ShowS) -> Show CopyOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CopyOpts -> ShowS
showsPrec :: Int -> CopyOpts -> ShowS
$cshow :: CopyOpts -> String
show :: CopyOpts -> String
$cshowList :: [CopyOpts] -> ShowS
showList :: [CopyOpts] -> ShowS
Show, CopyOpts -> CopyOpts -> Bool
(CopyOpts -> CopyOpts -> Bool)
-> (CopyOpts -> CopyOpts -> Bool) -> Eq CopyOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CopyOpts -> CopyOpts -> Bool
== :: CopyOpts -> CopyOpts -> Bool
$c/= :: CopyOpts -> CopyOpts -> Bool
/= :: CopyOpts -> CopyOpts -> Bool
Eq)

-- | Redis default 'CopyOpts'. Equivalent to omitting all optional parameters.
defaultCopyOpts :: CopyOpts
defaultCopyOpts :: CopyOpts
defaultCopyOpts = CopyOpts
  { copyDestinationDb :: Maybe Integer
copyDestinationDb = Maybe Integer
forall a. Maybe a
Nothing
  , copyReplace :: Bool
copyReplace = Bool
False
  }

-- |Copies the value of a key to a new key (<https://redis.io/commands/copy>).
--
-- /O(N)/ worst case for collections, where @N@ is the number of nested items. /O(1)/ for string values.
--
-- Since Redis 6.2.0
copy
    :: (RedisCtx m f)
    => ByteString -- ^ Source key
    -> ByteString -- ^ Destination key
    -> m (f Bool)
copy :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Bool)
copy ByteString
source ByteString
destination = ByteString -> ByteString -> CopyOpts -> m (f Bool)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> CopyOpts -> m (f Bool)
copyOpts ByteString
source ByteString
destination CopyOpts
defaultCopyOpts

-- |Copies the value of a key to a new key (<https://redis.io/commands/copy>).
--
-- /O(N)/ worst case for collections, where /N/ is the number of nested items. /O(1)/ for string values.
--
-- Since Redis 6.2.0
copyOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Source key
    -> ByteString -- ^ Destination key
    -> CopyOpts -- ^ Copy options
    -> m (f Bool)
copyOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> CopyOpts -> m (f Bool)
copyOpts ByteString
source ByteString
destination CopyOpts{Bool
Maybe Integer
copyDestinationDb :: CopyOpts -> Maybe Integer
copyReplace :: CopyOpts -> Bool
copyDestinationDb :: Maybe Integer
copyReplace :: Bool
..} =
    [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Bool)) -> [ByteString] -> m (f Bool)
forall a b. (a -> b) -> a -> b
$ [ByteString
"COPY", ByteString
source, ByteString
destination] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
dbArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
replaceArg
  where
    dbArg :: [ByteString]
dbArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
destinationDb -> [ByteString
"DB", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
destinationDb]) Maybe Integer
copyDestinationDb
    replaceArg :: [ByteString]
replaceArg = [ByteString
"REPLACE" | Bool
copyReplace]

-- |Returns the expiration time of a key as a Unix timestamp (<https://redis.io/commands/expiretime>).
--
-- Returns @-2@ if the key does not exist; @-1@ if the key exists but has no associated expiration.
--
-- /O(1)/. Since Redis 7.0.0
expiretime
    :: (RedisCtx m f)
    => ByteString
    -> m (f Integer)
expiretime :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
expiretime ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"EXPIRETIME", ByteString
key]

-- |Returns the expiration time of a key as a Unix timestamp in milliseconds (<https://redis.io/commands/pexpiretime>).
--
-- Returns @-2@ if the key does not exist; @-1@ if the key exists but has no associated expiration.
--
-- /O(1)/. Since Redis 7.0.0
pexpiretime
    :: (RedisCtx m f)
    => ByteString
    -> m (f Integer)
pexpiretime :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
pexpiretime ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"PEXPIRETIME", ByteString
key]


set
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> ByteString -- ^ value
    -> m (f Status)
set :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Status)
set ByteString
key ByteString
value = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SET", ByteString
key, ByteString
value]


data Condition =
  Nx | -- ^ Only set the key if it does not already exist.
  Xx   -- ^ Only set the key if it already exists.
   deriving (Int -> Condition -> ShowS
[Condition] -> ShowS
Condition -> String
(Int -> Condition -> ShowS)
-> (Condition -> String)
-> ([Condition] -> ShowS)
-> Show Condition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Condition -> ShowS
showsPrec :: Int -> Condition -> ShowS
$cshow :: Condition -> String
show :: Condition -> String
$cshowList :: [Condition] -> ShowS
showList :: [Condition] -> ShowS
Show, Condition -> Condition -> Bool
(Condition -> Condition -> Bool)
-> (Condition -> Condition -> Bool) -> Eq Condition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Condition -> Condition -> Bool
== :: Condition -> Condition -> Bool
$c/= :: Condition -> Condition -> Bool
/= :: Condition -> Condition -> Bool
Eq)


instance RedisArg Condition where
  encode :: Condition -> ByteString
encode Condition
Nx = ByteString
"NX"
  encode Condition
Xx = ByteString
"XX"


data SetOpts = SetOpts
  { SetOpts -> Maybe Integer
setSeconds           :: Maybe Integer -- ^ Set the specified expire time, in seconds.
  , SetOpts -> Maybe Integer
setMilliseconds      :: Maybe Integer -- ^ Set the specified expire time, in milliseconds.
  , SetOpts -> Maybe Integer
setUnixSeconds       :: Maybe Integer
  {- ^ Set the specified Unix time at which the key will expire, in seconds.

  Since Redis 6.2
  -}
  , SetOpts -> Maybe Integer
setUnixMilliseconds  :: Maybe Integer
  {- ^ Set the specified Unix time at which the key will expire, in milliseconds.
  -}
  , SetOpts -> Maybe Condition
setCondition         :: Maybe Condition -- ^ Set the key on condition
  , SetOpts -> Bool
setKeepTTL           :: Bool
  {- ^ Retain the time to live associated with the key.

  Since Redis 6.0
  -}
  } deriving (Int -> SetOpts -> ShowS
[SetOpts] -> ShowS
SetOpts -> String
(Int -> SetOpts -> ShowS)
-> (SetOpts -> String) -> ([SetOpts] -> ShowS) -> Show SetOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetOpts -> ShowS
showsPrec :: Int -> SetOpts -> ShowS
$cshow :: SetOpts -> String
show :: SetOpts -> String
$cshowList :: [SetOpts] -> ShowS
showList :: [SetOpts] -> ShowS
Show, SetOpts -> SetOpts -> Bool
(SetOpts -> SetOpts -> Bool)
-> (SetOpts -> SetOpts -> Bool) -> Eq SetOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetOpts -> SetOpts -> Bool
== :: SetOpts -> SetOpts -> Bool
$c/= :: SetOpts -> SetOpts -> Bool
/= :: SetOpts -> SetOpts -> Bool
Eq)

-- |Redis default 'SetOpts'. Equivalent to omitting all optional parameters.
defaultSetOpts :: SetOpts
defaultSetOpts :: SetOpts
defaultSetOpts = SetOpts
  { setSeconds :: Maybe Integer
setSeconds = Maybe Integer
forall a. Maybe a
Nothing
  , setMilliseconds :: Maybe Integer
setMilliseconds = Maybe Integer
forall a. Maybe a
Nothing
  , setUnixSeconds :: Maybe Integer
setUnixSeconds = Maybe Integer
forall a. Maybe a
Nothing
  , setUnixMilliseconds :: Maybe Integer
setUnixMilliseconds = Maybe Integer
forall a. Maybe a
Nothing
  , setCondition :: Maybe Condition
setCondition = Maybe Condition
forall a. Maybe a
Nothing
  , setKeepTTL :: Bool
setKeepTTL = Bool
False
  }

internalSetOptsToArgs :: SetOpts -> [ByteString]
internalSetOptsToArgs :: SetOpts -> [ByteString]
internalSetOptsToArgs SetOpts{Bool
Maybe Integer
Maybe Condition
setSeconds :: SetOpts -> Maybe Integer
setMilliseconds :: SetOpts -> Maybe Integer
setUnixSeconds :: SetOpts -> Maybe Integer
setUnixMilliseconds :: SetOpts -> Maybe Integer
setCondition :: SetOpts -> Maybe Condition
setKeepTTL :: SetOpts -> Bool
setSeconds :: Maybe Integer
setMilliseconds :: Maybe Integer
setUnixSeconds :: Maybe Integer
setUnixMilliseconds :: Maybe Integer
setCondition :: Maybe Condition
setKeepTTL :: Bool
..} = [[ByteString]] -> [ByteString]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ByteString]
ex, [ByteString]
px, [ByteString]
exat, [ByteString]
pxat, [ByteString]
keepttl, [ByteString]
condition]
  where
    ex :: [ByteString]
ex   = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
s -> [ByteString
"EX",   Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
s]) Maybe Integer
setSeconds
    px :: [ByteString]
px   = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
s -> [ByteString
"PX",   Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
s]) Maybe Integer
setMilliseconds
    exat :: [ByteString]
exat = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
s -> [ByteString
"EXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
s]) Maybe Integer
setUnixSeconds
    pxat :: [ByteString]
pxat = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
s -> [ByteString
"PXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
s]) Maybe Integer
setUnixMilliseconds
    keepttl :: [ByteString]
keepttl = [ByteString
"KEEPTTL" | Bool
setKeepTTL]
    condition :: [ByteString]
condition = (Condition -> ByteString) -> [Condition] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map Condition -> ByteString
forall a. RedisArg a => a -> ByteString
encode ([Condition] -> [ByteString]) -> [Condition] -> [ByteString]
forall a b. (a -> b) -> a -> b
$ Maybe Condition -> [Condition]
forall a. Maybe a -> [a]
maybeToList Maybe Condition
setCondition

setOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> ByteString -- ^ value
    -> SetOpts
    -> m (f Status)
setOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> SetOpts -> m (f Status)
setOpts ByteString
key ByteString
value SetOpts
opts = [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
"SET", ByteString
key, ByteString
value] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ SetOpts -> [ByteString]
internalSetOptsToArgs SetOpts
opts

setGet
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> ByteString -- ^ value
    -> m (f ByteString)
setGet :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f ByteString)
setGet ByteString
key ByteString
value = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SET", ByteString
key, ByteString
value, ByteString
"GET"]

setGetOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> ByteString -- ^ value
    -> SetOpts
    -> m (f ByteString)
setGetOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> SetOpts -> m (f ByteString)
setGetOpts ByteString
key ByteString
value SetOpts
opts = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f ByteString))
-> [ByteString] -> m (f ByteString)
forall a b. (a -> b) -> a -> b
$ [ByteString
"SET", ByteString
key, ByteString
value, ByteString
"GET"] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ SetOpts -> [ByteString]
internalSetOptsToArgs SetOpts
opts

-- |Atomically sets multiple string keys with an optional shared expiration in a single operation (<https://redis.io/commands/msetex>).
--
-- /O(N)/ where /N/ is the number of keys to set.
--
-- Since Redis 8.4.0
msetex
    :: (RedisCtx m f)
    => NonEmpty (ByteString, ByteString) -- ^ A series of key/value pairs.
    -> m (f Bool)
msetex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty (ByteString, ByteString) -> m (f Bool)
msetex NonEmpty (ByteString, ByteString)
keyValues = NonEmpty (ByteString, ByteString) -> SetOpts -> m (f Bool)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty (ByteString, ByteString) -> SetOpts -> m (f Bool)
msetexOpts NonEmpty (ByteString, ByteString)
keyValues SetOpts
defaultSetOpts

-- |Atomically sets multiple string keys with an optional shared expiration in a single operation (<https://redis.io/commands/msetex>).
--
-- /O(N)/ where /N/ is the number of keys to set.
--
-- Since Redis 8.4.0
msetexOpts
    :: (RedisCtx m f)
    => NonEmpty (ByteString, ByteString) -- ^ A series of key/value pairs.
    -> SetOpts
    {- ^ Shared condition and expiration flags.

       The `MSETEX` command supports a set of options that modify its behavior:
       `NX` sets the keys and their expiration time only if none of the specified keys exist.
       `XX` sets the keys and their expiration time only if all of the specified keys already exist.
       `EX`/`PX`/`EXAT`/`PXAT` set the shared expiration for the specified keys.
       `KEEPTTL` retains the time to live associated with the keys.
     -}
    -> m (f Bool)
msetexOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty (ByteString, ByteString) -> SetOpts -> m (f Bool)
msetexOpts NonEmpty (ByteString, ByteString)
keyValues SetOpts
opts =
    [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Bool)) -> [ByteString] -> m (f Bool)
forall a b. (a -> b) -> a -> b
$
        [ByteString
"MSETEX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty (ByteString, ByteString) -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty (ByteString, ByteString)
keyValues)]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ((ByteString, ByteString) -> [ByteString])
-> [(ByteString, ByteString)] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(ByteString
key, ByteString
value) -> [ByteString
key, ByteString
value]) (NonEmpty (ByteString, ByteString) -> [(ByteString, ByteString)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (ByteString, ByteString)
keyValues)
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ SetOpts -> [ByteString]
internalSetOptsToArgs SetOpts
opts

data GetExOpts = GetExOpts
  { GetExOpts -> Maybe Integer
getExSeconds :: Maybe Integer
  , GetExOpts -> Maybe Integer
getExMilliseconds :: Maybe Integer
  , GetExOpts -> Maybe Integer
getExUnixSeconds :: Maybe Integer
  , GetExOpts -> Maybe Integer
getExUnixMilliseconds :: Maybe Integer
  , GetExOpts -> Bool
getExPersist :: Bool
  } deriving (Int -> GetExOpts -> ShowS
[GetExOpts] -> ShowS
GetExOpts -> String
(Int -> GetExOpts -> ShowS)
-> (GetExOpts -> String)
-> ([GetExOpts] -> ShowS)
-> Show GetExOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetExOpts -> ShowS
showsPrec :: Int -> GetExOpts -> ShowS
$cshow :: GetExOpts -> String
show :: GetExOpts -> String
$cshowList :: [GetExOpts] -> ShowS
showList :: [GetExOpts] -> ShowS
Show, GetExOpts -> GetExOpts -> Bool
(GetExOpts -> GetExOpts -> Bool)
-> (GetExOpts -> GetExOpts -> Bool) -> Eq GetExOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetExOpts -> GetExOpts -> Bool
== :: GetExOpts -> GetExOpts -> Bool
$c/= :: GetExOpts -> GetExOpts -> Bool
/= :: GetExOpts -> GetExOpts -> Bool
Eq)

defaultGetExOpts :: GetExOpts
defaultGetExOpts :: GetExOpts
defaultGetExOpts = GetExOpts
  { getExSeconds :: Maybe Integer
getExSeconds = Maybe Integer
forall a. Maybe a
Nothing
  , getExMilliseconds :: Maybe Integer
getExMilliseconds = Maybe Integer
forall a. Maybe a
Nothing
  , getExUnixSeconds :: Maybe Integer
getExUnixSeconds = Maybe Integer
forall a. Maybe a
Nothing
  , getExUnixMilliseconds :: Maybe Integer
getExUnixMilliseconds = Maybe Integer
forall a. Maybe a
Nothing
  , getExPersist :: Bool
getExPersist = Bool
False
  }

-- |Returns the string value of a key after deleting the key (<https://redis.io/commands/getdel>).
--
-- /O(1)/
--
-- Since Redis 6.2.0
getdel
    :: (RedisCtx m f)
    => ByteString
    -> m (f (Maybe ByteString))
getdel :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
getdel ByteString
key = [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"GETDEL", ByteString
key]

data DelexCondition
    = DelexIfEq ByteString
    | DelexIfNe ByteString
    | DelexIfDigestEq ByteString
    | DelexIfDigestNe ByteString
    deriving (Int -> DelexCondition -> ShowS
[DelexCondition] -> ShowS
DelexCondition -> String
(Int -> DelexCondition -> ShowS)
-> (DelexCondition -> String)
-> ([DelexCondition] -> ShowS)
-> Show DelexCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DelexCondition -> ShowS
showsPrec :: Int -> DelexCondition -> ShowS
$cshow :: DelexCondition -> String
show :: DelexCondition -> String
$cshowList :: [DelexCondition] -> ShowS
showList :: [DelexCondition] -> ShowS
Show, DelexCondition -> DelexCondition -> Bool
(DelexCondition -> DelexCondition -> Bool)
-> (DelexCondition -> DelexCondition -> Bool) -> Eq DelexCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DelexCondition -> DelexCondition -> Bool
== :: DelexCondition -> DelexCondition -> Bool
$c/= :: DelexCondition -> DelexCondition -> Bool
/= :: DelexCondition -> DelexCondition -> Bool
Eq)

delexConditionToArgs :: DelexCondition -> [ByteString]
delexConditionToArgs :: DelexCondition -> [ByteString]
delexConditionToArgs DelexCondition
condition =
    case DelexCondition
condition of
        DelexIfEq ByteString
value -> [ByteString
"IFEQ", ByteString
value]
        DelexIfNe ByteString
value -> [ByteString
"IFNE", ByteString
value]
        DelexIfDigestEq ByteString
digestValue -> [ByteString
"IFDEQ", ByteString
digestValue]
        DelexIfDigestNe ByteString
digestValue -> [ByteString
"IFDNE", ByteString
digestValue]

-- |Conditionally removes the specified key based on value or hash digest comparison (<https://redis.io/commands/delex>).
--
-- /O(1)/ for /IFEQ/ and /IFNE/. /O(N)/ for /IFDEQ/ and /IFDNE/, where /N/ is the length of the string value.
--
-- Since Redis 8.4.0
delex
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the string.
    -> m (f Bool)
delex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Bool)
delex ByteString
key = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"DELEX", ByteString
key]

-- |Conditionally removes the specified key based on value or hash digest comparison (<https://redis.io/commands/delex>).
--
-- /O(1)/ for /IFEQ/ and /IFNE/. /O(N)/ for /IFDEQ/ and /IFDNE/, where /N/ is the length of the string value.
--
-- Since Redis 8.4.0
delexWhen
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the string.
    -> DelexCondition
    {- ^ Condition to enforce.

       The `DELEX` command supports a set of options that modify its behavior.
       Only one option can be specified:
       `IFEQ` removes the key if the value is equal to the specified value.
       `IFNE` removes the key if the value is not equal to the specified value.
       `IFDEQ` removes the key if its hash digest is equal to the specified hash digest.
       `IFDNE` removes the key if its hash digest is not equal to the specified hash digest.
     -}
    -> m (f Bool)
delexWhen :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> DelexCondition -> m (f Bool)
delexWhen ByteString
key DelexCondition
condition =
    [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Bool)) -> [ByteString] -> m (f Bool)
forall a b. (a -> b) -> a -> b
$ [ByteString
"DELEX", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ DelexCondition -> [ByteString]
delexConditionToArgs DelexCondition
condition

-- |Returns the hash digest of a string value (<https://redis.io/commands/digest>).
--
-- /O(N)/ where /N/ is the length of the string value.
--
-- Since Redis 8.4.0
digest
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the string.
    -> m (f (Maybe ByteString))
digest :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
digest ByteString
key = [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"DIGEST", ByteString
key]

-- |Returns the string value of a key after setting its expiration time (<https://redis.io/commands/getex>).
--
-- /O(1)/
--
-- Since Redis 6.2.0
getex
    :: (RedisCtx m f)
    => ByteString
    -> m (f (Maybe ByteString))
getex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
getex ByteString
key = ByteString -> GetExOpts -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> GetExOpts -> m (f (Maybe ByteString))
getexOpts ByteString
key GetExOpts
defaultGetExOpts

-- |Returns the string value of a key after setting its expiration time (<https://redis.io/commands/getex>).
--
-- /O(1)/
--
-- Since Redis 6.2.0
getexOpts
    :: (RedisCtx m f)
    => ByteString
    -> GetExOpts
    -> m (f (Maybe ByteString))
getexOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> GetExOpts -> m (f (Maybe ByteString))
getexOpts ByteString
key GetExOpts{Bool
Maybe Integer
getExSeconds :: GetExOpts -> Maybe Integer
getExMilliseconds :: GetExOpts -> Maybe Integer
getExUnixSeconds :: GetExOpts -> Maybe Integer
getExUnixMilliseconds :: GetExOpts -> Maybe Integer
getExPersist :: GetExOpts -> Bool
getExSeconds :: Maybe Integer
getExMilliseconds :: Maybe Integer
getExUnixSeconds :: Maybe Integer
getExUnixMilliseconds :: Maybe Integer
getExPersist :: Bool
..} =
    [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
"GETEX", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
exArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
pxArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
exatArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
pxatArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
persistArg
  where
    exArg :: [ByteString]
exArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
seconds -> [ByteString
"EX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds]) Maybe Integer
getExSeconds
    pxArg :: [ByteString]
pxArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
milliseconds -> [ByteString
"PX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds]) Maybe Integer
getExMilliseconds
    exatArg :: [ByteString]
exatArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
seconds -> [ByteString
"EXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds]) Maybe Integer
getExUnixSeconds
    pxatArg :: [ByteString]
pxatArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
milliseconds -> [ByteString
"PXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds]) Maybe Integer
getExUnixMilliseconds
    persistArg :: [ByteString]
persistArg = [ByteString
"PERSIST" | Bool
getExPersist]

data HGetExOpts = HGetExOpts
  { HGetExOpts -> Maybe Integer
hGetExSeconds :: Maybe Integer
  , HGetExOpts -> Maybe Integer
hGetExMilliseconds :: Maybe Integer
  , HGetExOpts -> Maybe Integer
hGetExUnixSeconds :: Maybe Integer
  , HGetExOpts -> Maybe Integer
hGetExUnixMilliseconds :: Maybe Integer
  , HGetExOpts -> Bool
hGetExPersist :: Bool
  } deriving (Int -> HGetExOpts -> ShowS
[HGetExOpts] -> ShowS
HGetExOpts -> String
(Int -> HGetExOpts -> ShowS)
-> (HGetExOpts -> String)
-> ([HGetExOpts] -> ShowS)
-> Show HGetExOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HGetExOpts -> ShowS
showsPrec :: Int -> HGetExOpts -> ShowS
$cshow :: HGetExOpts -> String
show :: HGetExOpts -> String
$cshowList :: [HGetExOpts] -> ShowS
showList :: [HGetExOpts] -> ShowS
Show, HGetExOpts -> HGetExOpts -> Bool
(HGetExOpts -> HGetExOpts -> Bool)
-> (HGetExOpts -> HGetExOpts -> Bool) -> Eq HGetExOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HGetExOpts -> HGetExOpts -> Bool
== :: HGetExOpts -> HGetExOpts -> Bool
$c/= :: HGetExOpts -> HGetExOpts -> Bool
/= :: HGetExOpts -> HGetExOpts -> Bool
Eq)

defaultHGetExOpts :: HGetExOpts
defaultHGetExOpts :: HGetExOpts
defaultHGetExOpts = HGetExOpts
  { hGetExSeconds :: Maybe Integer
hGetExSeconds = Maybe Integer
forall a. Maybe a
Nothing
  , hGetExMilliseconds :: Maybe Integer
hGetExMilliseconds = Maybe Integer
forall a. Maybe a
Nothing
  , hGetExUnixSeconds :: Maybe Integer
hGetExUnixSeconds = Maybe Integer
forall a. Maybe a
Nothing
  , hGetExUnixMilliseconds :: Maybe Integer
hGetExUnixMilliseconds = Maybe Integer
forall a. Maybe a
Nothing
  , hGetExPersist :: Bool
hGetExPersist = Bool
False
  }

-- |Returns the values associated with the specified fields in a hash and optionally updates the key expiration (<https://redis.io/commands/hgetex>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 8.0.0
hgetex
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty ByteString
    -> m (f [Maybe ByteString])
hgetex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> m (f [Maybe ByteString])
hgetex ByteString
key NonEmpty ByteString
fields = ByteString
-> NonEmpty ByteString -> HGetExOpts -> m (f [Maybe ByteString])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty ByteString -> HGetExOpts -> m (f [Maybe ByteString])
hgetexOpts ByteString
key NonEmpty ByteString
fields HGetExOpts
defaultHGetExOpts

-- |Returns the values associated with the specified fields in a hash and optionally updates the key expiration (<https://redis.io/commands/hgetex>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 8.0.0
hgetexOpts
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty ByteString
    -> HGetExOpts
    -> m (f [Maybe ByteString])
hgetexOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty ByteString -> HGetExOpts -> m (f [Maybe ByteString])
hgetexOpts ByteString
key NonEmpty ByteString
fields HGetExOpts{Bool
Maybe Integer
hGetExSeconds :: HGetExOpts -> Maybe Integer
hGetExMilliseconds :: HGetExOpts -> Maybe Integer
hGetExUnixSeconds :: HGetExOpts -> Maybe Integer
hGetExUnixMilliseconds :: HGetExOpts -> Maybe Integer
hGetExPersist :: HGetExOpts -> Bool
hGetExSeconds :: Maybe Integer
hGetExMilliseconds :: Maybe Integer
hGetExUnixSeconds :: Maybe Integer
hGetExUnixMilliseconds :: Maybe Integer
hGetExPersist :: Bool
..} =
    [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
"HGETEX", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
exArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
pxArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
exatArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
pxatArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
persistArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields
  where
    exArg :: [ByteString]
exArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
seconds -> [ByteString
"EX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds]) Maybe Integer
hGetExSeconds
    pxArg :: [ByteString]
pxArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
milliseconds -> [ByteString
"PX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds]) Maybe Integer
hGetExMilliseconds
    exatArg :: [ByteString]
exatArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
seconds -> [ByteString
"EXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds]) Maybe Integer
hGetExUnixSeconds
    pxatArg :: [ByteString]
pxatArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
milliseconds -> [ByteString
"PXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds]) Maybe Integer
hGetExUnixMilliseconds
    persistArg :: [ByteString]
persistArg = [ByteString
"PERSIST" | Bool
hGetExPersist]

-- |Returns the values associated with the specified fields in a hash and deletes those fields (<https://redis.io/commands/hgetdel>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 8.0.0
hgetdel
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty ByteString
    -> m (f [Maybe ByteString])
hgetdel :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> m (f [Maybe ByteString])
hgetdel ByteString
key NonEmpty ByteString
fields =
    [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
"HGETDEL", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

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

instance RedisArg HSetExCondition where
    encode :: HSetExCondition -> ByteString
encode HSetExCondition
HSetExFnx = ByteString
"FNX"
    encode HSetExCondition
HSetExFxx = ByteString
"FXX"

data HSetExOpts = HSetExOpts
  { HSetExOpts -> Maybe Integer
hSetExSeconds :: Maybe Integer
  , HSetExOpts -> Maybe Integer
hSetExMilliseconds :: Maybe Integer
  , HSetExOpts -> Maybe Integer
hSetExUnixSeconds :: Maybe Integer
  , HSetExOpts -> Maybe Integer
hSetExUnixMilliseconds :: Maybe Integer
  , HSetExOpts -> Maybe HSetExCondition
hSetExCondition :: Maybe HSetExCondition
  , HSetExOpts -> Bool
hSetExKeepTTL :: Bool
  } deriving (Int -> HSetExOpts -> ShowS
[HSetExOpts] -> ShowS
HSetExOpts -> String
(Int -> HSetExOpts -> ShowS)
-> (HSetExOpts -> String)
-> ([HSetExOpts] -> ShowS)
-> Show HSetExOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HSetExOpts -> ShowS
showsPrec :: Int -> HSetExOpts -> ShowS
$cshow :: HSetExOpts -> String
show :: HSetExOpts -> String
$cshowList :: [HSetExOpts] -> ShowS
showList :: [HSetExOpts] -> ShowS
Show, HSetExOpts -> HSetExOpts -> Bool
(HSetExOpts -> HSetExOpts -> Bool)
-> (HSetExOpts -> HSetExOpts -> Bool) -> Eq HSetExOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HSetExOpts -> HSetExOpts -> Bool
== :: HSetExOpts -> HSetExOpts -> Bool
$c/= :: HSetExOpts -> HSetExOpts -> Bool
/= :: HSetExOpts -> HSetExOpts -> Bool
Eq)

defaultHSetExOpts :: HSetExOpts
defaultHSetExOpts :: HSetExOpts
defaultHSetExOpts = HSetExOpts
  { hSetExSeconds :: Maybe Integer
hSetExSeconds = Maybe Integer
forall a. Maybe a
Nothing
  , hSetExMilliseconds :: Maybe Integer
hSetExMilliseconds = Maybe Integer
forall a. Maybe a
Nothing
  , hSetExUnixSeconds :: Maybe Integer
hSetExUnixSeconds = Maybe Integer
forall a. Maybe a
Nothing
  , hSetExUnixMilliseconds :: Maybe Integer
hSetExUnixMilliseconds = Maybe Integer
forall a. Maybe a
Nothing
  , hSetExCondition :: Maybe HSetExCondition
hSetExCondition = Maybe HSetExCondition
forall a. Maybe a
Nothing
  , hSetExKeepTTL :: Bool
hSetExKeepTTL = Bool
False
  }

-- |Sets fields in a hash and optionally updates the key expiration (<https://redis.io/commands/hsetex>).
--
-- /O(N)/ where /N/ is the number of fields set.
--
-- Since Redis 8.0.0
hsetex
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty (ByteString, ByteString)
    -> m (f Bool)
hsetex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty (ByteString, ByteString) -> m (f Bool)
hsetex ByteString
key NonEmpty (ByteString, ByteString)
fieldValues = ByteString
-> NonEmpty (ByteString, ByteString) -> HSetExOpts -> m (f Bool)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty (ByteString, ByteString) -> HSetExOpts -> m (f Bool)
hsetexOpts ByteString
key NonEmpty (ByteString, ByteString)
fieldValues HSetExOpts
defaultHSetExOpts

-- |Sets fields in a hash and optionally updates the key expiration (<https://redis.io/commands/hsetex>).
--
-- /O(N)/ where /N/ is the number of fields set.
--
-- Since Redis 8.0.0
hsetexOpts
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty (ByteString, ByteString)
    -> HSetExOpts
    -> m (f Bool)
hsetexOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty (ByteString, ByteString) -> HSetExOpts -> m (f Bool)
hsetexOpts ByteString
key NonEmpty (ByteString, ByteString)
fieldValues HSetExOpts{Bool
Maybe Integer
Maybe HSetExCondition
hSetExSeconds :: HSetExOpts -> Maybe Integer
hSetExMilliseconds :: HSetExOpts -> Maybe Integer
hSetExUnixSeconds :: HSetExOpts -> Maybe Integer
hSetExUnixMilliseconds :: HSetExOpts -> Maybe Integer
hSetExCondition :: HSetExOpts -> Maybe HSetExCondition
hSetExKeepTTL :: HSetExOpts -> Bool
hSetExSeconds :: Maybe Integer
hSetExMilliseconds :: Maybe Integer
hSetExUnixSeconds :: Maybe Integer
hSetExUnixMilliseconds :: Maybe Integer
hSetExCondition :: Maybe HSetExCondition
hSetExKeepTTL :: Bool
..} =
    [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Bool)) -> [ByteString] -> m (f Bool)
forall a b. (a -> b) -> a -> b
$ [ByteString
"HSETEX", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
conditionArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
exArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
pxArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
exatArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
pxatArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
keepTTLArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"FIELDS", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty (ByteString, ByteString) -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty (ByteString, ByteString)
fieldValues)] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ((ByteString, ByteString) -> [ByteString])
-> [(ByteString, ByteString)] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(ByteString
field, ByteString
value) -> [ByteString
field, ByteString
value]) (NonEmpty (ByteString, ByteString) -> [(ByteString, ByteString)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (ByteString, ByteString)
fieldValues)
  where
    conditionArg :: [ByteString]
conditionArg = [ByteString]
-> (HSetExCondition -> [ByteString])
-> Maybe HSetExCondition
-> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\HSetExCondition
condition -> [HSetExCondition -> ByteString
forall a. RedisArg a => a -> ByteString
encode HSetExCondition
condition]) Maybe HSetExCondition
hSetExCondition
    exArg :: [ByteString]
exArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
seconds -> [ByteString
"EX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds]) Maybe Integer
hSetExSeconds
    pxArg :: [ByteString]
pxArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
milliseconds -> [ByteString
"PX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds]) Maybe Integer
hSetExMilliseconds
    exatArg :: [ByteString]
exatArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
seconds -> [ByteString
"EXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds]) Maybe Integer
hSetExUnixSeconds
    pxatArg :: [ByteString]
pxatArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
milliseconds -> [ByteString
"PXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds]) Maybe Integer
hSetExUnixMilliseconds
    keepTTLArg :: [ByteString]
keepTTLArg = [ByteString
"KEEPTTL" | Bool
hSetExKeepTTL]

data HashFieldExpirationStatus
    = HashFieldExpirationNoSuchField
    | HashFieldExpirationConditionNotMet
    | HashFieldExpirationSet
    | HashFieldExpirationDeleted
    deriving (Int -> HashFieldExpirationStatus -> ShowS
[HashFieldExpirationStatus] -> ShowS
HashFieldExpirationStatus -> String
(Int -> HashFieldExpirationStatus -> ShowS)
-> (HashFieldExpirationStatus -> String)
-> ([HashFieldExpirationStatus] -> ShowS)
-> Show HashFieldExpirationStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HashFieldExpirationStatus -> ShowS
showsPrec :: Int -> HashFieldExpirationStatus -> ShowS
$cshow :: HashFieldExpirationStatus -> String
show :: HashFieldExpirationStatus -> String
$cshowList :: [HashFieldExpirationStatus] -> ShowS
showList :: [HashFieldExpirationStatus] -> ShowS
Show, HashFieldExpirationStatus -> HashFieldExpirationStatus -> Bool
(HashFieldExpirationStatus -> HashFieldExpirationStatus -> Bool)
-> (HashFieldExpirationStatus -> HashFieldExpirationStatus -> Bool)
-> Eq HashFieldExpirationStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HashFieldExpirationStatus -> HashFieldExpirationStatus -> Bool
== :: HashFieldExpirationStatus -> HashFieldExpirationStatus -> Bool
$c/= :: HashFieldExpirationStatus -> HashFieldExpirationStatus -> Bool
/= :: HashFieldExpirationStatus -> HashFieldExpirationStatus -> Bool
Eq)

instance RedisResult HashFieldExpirationStatus where
    decode :: Reply -> Either Reply HashFieldExpirationStatus
decode Reply
r = do
        value <- Reply -> Either Reply Integer
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
r :: Either Reply Integer
        case value of
            -2 -> HashFieldExpirationStatus -> Either Reply HashFieldExpirationStatus
forall a b. b -> Either a b
Right HashFieldExpirationStatus
HashFieldExpirationNoSuchField
            Integer
0 -> HashFieldExpirationStatus -> Either Reply HashFieldExpirationStatus
forall a b. b -> Either a b
Right HashFieldExpirationStatus
HashFieldExpirationConditionNotMet
            Integer
1 -> HashFieldExpirationStatus -> Either Reply HashFieldExpirationStatus
forall a b. b -> Either a b
Right HashFieldExpirationStatus
HashFieldExpirationSet
            Integer
2 -> HashFieldExpirationStatus -> Either Reply HashFieldExpirationStatus
forall a b. b -> Either a b
Right HashFieldExpirationStatus
HashFieldExpirationDeleted
            Integer
_ -> Reply -> Either Reply HashFieldExpirationStatus
forall a b. a -> Either a b
Left Reply
r

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

instance RedisResult HashFieldExpirationInfo where
    decode :: Reply -> Either Reply HashFieldExpirationInfo
decode Reply
r = do
        value <- Reply -> Either Reply Integer
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
r :: Either Reply Integer
        case value of
            -2 -> HashFieldExpirationInfo -> Either Reply HashFieldExpirationInfo
forall a b. b -> Either a b
Right HashFieldExpirationInfo
HashFieldExpirationInfoNoSuchField
            -1 -> HashFieldExpirationInfo -> Either Reply HashFieldExpirationInfo
forall a b. b -> Either a b
Right HashFieldExpirationInfo
HashFieldExpirationInfoNoExpiration
            Integer
n -> HashFieldExpirationInfo -> Either Reply HashFieldExpirationInfo
forall a b. b -> Either a b
Right (Integer -> HashFieldExpirationInfo
HashFieldExpirationInfo Integer
n)

hashFieldExpirationOptsToArgs :: ExpireOpts -> [ByteString]
hashFieldExpirationOptsToArgs :: ExpireOpts -> [ByteString]
hashFieldExpirationOptsToArgs ExpireOpts
opts =
    [ExpireOpts -> ByteString
forall a. RedisArg a => a -> ByteString
encode ExpireOpts
opts]

hashFieldArgs :: NonEmpty ByteString -> [ByteString]
hashFieldArgs :: NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields =
    [ByteString
"FIELDS", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty ByteString -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty ByteString
fields)] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ByteString
fields

-- |Sets expiration for hash fields using relative time to expire in seconds (<https://redis.io/commands/hexpire>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Set an expiration (TTL or time to live) on one or more fields of a given hash key. You must specify at least one field. Field(s) will automatically be deleted from the hash key when their TTLs expire.
--
-- Field expirations will only be cleared by commands that delete or overwrite the contents of the hash fields, including HDEL and HSET commands. This means that all the operations that conceptually alter the value stored at a hash key's field without replacing it with a new one will leave the TTL untouched.
--
-- You can clear the TTL using the 'hpersist' command, which turns the hash field back into a persistent field.
--
-- Note that calling 'hexpire'/'hpexpire' with a zero TTL or 'hexpireat'/'hpexpireat' with a time in the past will result in the hash field being deleted.
--
-- Since Redis 7.4.0
hexpire
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> Integer -- ^ Seconds until expiration.
    -> NonEmpty ByteString -- ^ List of fields to set expiration for.
    -> m (f [HashFieldExpirationStatus])
hexpire :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> NonEmpty ByteString
-> m (f [HashFieldExpirationStatus])
hexpire ByteString
key Integer
seconds NonEmpty ByteString
fields =
    [ByteString] -> m (f [HashFieldExpirationStatus])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationStatus]))
-> [ByteString] -> m (f [HashFieldExpirationStatus])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HEXPIRE", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Sets expiration for hash fields using relative time to expire in seconds (<https://redis.io/commands/hexpire>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hexpireOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> Integer -- ^ Seconds until expiration.
    -> NonEmpty ByteString -- ^ List of fields to set expiration for.
    -> ExpireOpts -- ^ Expiration options.
    -> m (f [HashFieldExpirationStatus])
hexpireOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> NonEmpty ByteString
-> ExpireOpts
-> m (f [HashFieldExpirationStatus])
hexpireOpts ByteString
key Integer
seconds NonEmpty ByteString
fields ExpireOpts
opts =
    [ByteString] -> m (f [HashFieldExpirationStatus])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationStatus]))
-> [ByteString] -> m (f [HashFieldExpirationStatus])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HEXPIRE", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ExpireOpts -> [ByteString]
hashFieldExpirationOptsToArgs ExpireOpts
opts [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Sets expiration for hash fields using relative time to expire in milliseconds (<https://redis.io/commands/hpexpire>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hpexpire
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> Integer -- ^ Milliseconds until expiration.
    -> NonEmpty ByteString -- ^ List of fields to set expiration for.
    -> m (f [HashFieldExpirationStatus])
hpexpire :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> NonEmpty ByteString
-> m (f [HashFieldExpirationStatus])
hpexpire ByteString
key Integer
milliseconds NonEmpty ByteString
fields =
    [ByteString] -> m (f [HashFieldExpirationStatus])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationStatus]))
-> [ByteString] -> m (f [HashFieldExpirationStatus])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HPEXPIRE", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Sets expiration for hash fields using relative time to expire in milliseconds (<https://redis.io/commands/hpexpire>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hpexpireOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> Integer -- ^ Milliseconds until expiration.
    -> NonEmpty ByteString -- ^ List of fields to set expiration for.
    -> ExpireOpts -- ^ Expiration options.
    -> m (f [HashFieldExpirationStatus])
hpexpireOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> NonEmpty ByteString
-> ExpireOpts
-> m (f [HashFieldExpirationStatus])
hpexpireOpts ByteString
key Integer
milliseconds NonEmpty ByteString
fields ExpireOpts
opts =
    [ByteString] -> m (f [HashFieldExpirationStatus])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationStatus]))
-> [ByteString] -> m (f [HashFieldExpirationStatus])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HPEXPIRE", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ExpireOpts -> [ByteString]
hashFieldExpirationOptsToArgs ExpireOpts
opts [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Sets expiration for hash fields using an absolute Unix timestamp in seconds (<https://redis.io/commands/hexpireat>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hexpireat
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> Integer -- ^ Absolute Unix timestamp in seconds at which the hash fields will expire.
    -> NonEmpty ByteString -- ^ List of fields to set expiration for.
    -> m (f [HashFieldExpirationStatus])
hexpireat :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> NonEmpty ByteString
-> m (f [HashFieldExpirationStatus])
hexpireat ByteString
key Integer
unixTimeSeconds NonEmpty ByteString
fields =
    [ByteString] -> m (f [HashFieldExpirationStatus])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationStatus]))
-> [ByteString] -> m (f [HashFieldExpirationStatus])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HEXPIREAT", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
unixTimeSeconds] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Sets expiration for hash fields using an absolute Unix timestamp in seconds (<https://redis.io/commands/hexpireat>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hexpireatOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> Integer -- ^ Absolute Unix timestamp in seconds at which the hash fields will expire.
    -> NonEmpty ByteString -- ^ List of fields to set expiration for.
    -> ExpireOpts -- ^ Expiration options.
    -> m (f [HashFieldExpirationStatus])
hexpireatOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> NonEmpty ByteString
-> ExpireOpts
-> m (f [HashFieldExpirationStatus])
hexpireatOpts ByteString
key Integer
unixTimeSeconds NonEmpty ByteString
fields ExpireOpts
opts =
    [ByteString] -> m (f [HashFieldExpirationStatus])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationStatus]))
-> [ByteString] -> m (f [HashFieldExpirationStatus])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HEXPIREAT", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
unixTimeSeconds] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ExpireOpts -> [ByteString]
hashFieldExpirationOptsToArgs ExpireOpts
opts [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Sets expiration for hash fields using an absolute Unix timestamp in milliseconds (<https://redis.io/commands/hpexpireat>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hpexpireat
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> Integer -- ^ Absolute Unix timestamp in milliseconds at which the hash fields will expire.
    -> NonEmpty ByteString -- ^ List of fields to set expiration for.
    -> m (f [HashFieldExpirationStatus])
hpexpireat :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> NonEmpty ByteString
-> m (f [HashFieldExpirationStatus])
hpexpireat ByteString
key Integer
unixTimeMilliseconds NonEmpty ByteString
fields =
    [ByteString] -> m (f [HashFieldExpirationStatus])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationStatus]))
-> [ByteString] -> m (f [HashFieldExpirationStatus])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HPEXPIREAT", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
unixTimeMilliseconds] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Sets expiration for hash fields using an absolute Unix timestamp in milliseconds (<https://redis.io/commands/hpexpireat>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hpexpireatOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> Integer -- ^ Absolute Unix timestamp in milliseconds at which the hash fields will expire.
    -> NonEmpty ByteString -- ^ List of fields to set expiration for.
    -> ExpireOpts -- ^ Expiration options.
    -> m (f [HashFieldExpirationStatus])
hpexpireatOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> NonEmpty ByteString
-> ExpireOpts
-> m (f [HashFieldExpirationStatus])
hpexpireatOpts ByteString
key Integer
unixTimeMilliseconds NonEmpty ByteString
fields ExpireOpts
opts =
    [ByteString] -> m (f [HashFieldExpirationStatus])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationStatus]))
-> [ByteString] -> m (f [HashFieldExpirationStatus])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HPEXPIREAT", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
unixTimeMilliseconds] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ExpireOpts -> [ByteString]
hashFieldExpirationOptsToArgs ExpireOpts
opts [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Returns the TTL in seconds of hash fields (<https://redis.io/commands/httl>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
httl
    :: (RedisCtx m f)
    => ByteString -- ^ Key of the hash.
    -> NonEmpty ByteString -- ^ List of fields to get TTL for.
    -> m (f [HashFieldExpirationInfo])
httl :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty ByteString -> m (f [HashFieldExpirationInfo])
httl ByteString
key NonEmpty ByteString
fields =
    [ByteString] -> m (f [HashFieldExpirationInfo])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationInfo]))
-> [ByteString] -> m (f [HashFieldExpirationInfo])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HTTL", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Returns the TTL in milliseconds of hash fields (<https://redis.io/commands/hpttl>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hpttl
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty ByteString
    -> m (f [HashFieldExpirationInfo])
hpttl :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty ByteString -> m (f [HashFieldExpirationInfo])
hpttl ByteString
key NonEmpty ByteString
fields =
    [ByteString] -> m (f [HashFieldExpirationInfo])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationInfo]))
-> [ByteString] -> m (f [HashFieldExpirationInfo])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HPTTL", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Returns the expiration time of hash fields as a Unix timestamp in seconds (<https://redis.io/commands/hexpiretime>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hexpiretime
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty ByteString
    -> m (f [HashFieldExpirationInfo])
hexpiretime :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty ByteString -> m (f [HashFieldExpirationInfo])
hexpiretime ByteString
key NonEmpty ByteString
fields =
    [ByteString] -> m (f [HashFieldExpirationInfo])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationInfo]))
-> [ByteString] -> m (f [HashFieldExpirationInfo])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HEXPIRETIME", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields

-- |Returns the expiration time of hash fields as a Unix timestamp in milliseconds (<https://redis.io/commands/hpexpiretime>).
--
-- /O(N)/ where /N/ is the number of specified fields.
--
-- Since Redis 7.4.0
hpexpiretime
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty ByteString
    -> m (f [HashFieldExpirationInfo])
hpexpiretime :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty ByteString -> m (f [HashFieldExpirationInfo])
hpexpiretime ByteString
key NonEmpty ByteString
fields =
    [ByteString] -> m (f [HashFieldExpirationInfo])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [HashFieldExpirationInfo]))
-> [ByteString] -> m (f [HashFieldExpirationInfo])
forall a b. (a -> b) -> a -> b
$ [ByteString
"HPEXPIRETIME", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
hashFieldArgs NonEmpty ByteString
fields


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


instance RedisArg DebugMode where
  encode :: DebugMode -> ByteString
encode DebugMode
Yes = ByteString
"YES"
  encode DebugMode
Sync = ByteString
"SYNC"
  encode DebugMode
No = ByteString
"NO"

-- |Set the debug mode for executed scripts (<http://redis.io/commands/script-debug>). Since Redis 3.2.0
scriptDebug
    :: (RedisCtx m f)
    => DebugMode
    -> m (f Bool)
scriptDebug :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
DebugMode -> m (f Bool)
scriptDebug DebugMode
mode =
    [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SCRIPT DEBUG", DebugMode -> ByteString
forall a. RedisArg a => a -> ByteString
encode DebugMode
mode]

-- |Add one or more members to a sorted set, or update its score if it already exists (<http://redis.io/commands/zadd>). The Redis command @ZADD@ is split up into 'zadd', 'zaddOpts'. Since Redis 1.2.0
zadd
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> [(Double,ByteString)] -- ^ scoreMember
    -> m (f Integer)
zadd :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [(Double, ByteString)] -> m (f Integer)
zadd ByteString
key [(Double, ByteString)]
scoreMembers =
  ByteString -> [(Double, ByteString)] -> ZaddOpts -> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [(Double, ByteString)] -> ZaddOpts -> m (f Integer)
zaddOpts ByteString
key [(Double, ByteString)]
scoreMembers ZaddOpts
defaultZaddOpts


data SizeCondition =
    CGT | -- ^  Only update existing elements if the new score is greater than the current score. This flag doesn't prevent adding new elements.
    CLT   -- ^  Only update existing elements if the new score is less than the current score. This flag doesn't prevent adding new elements.
    deriving (Int -> SizeCondition -> ShowS
[SizeCondition] -> ShowS
SizeCondition -> String
(Int -> SizeCondition -> ShowS)
-> (SizeCondition -> String)
-> ([SizeCondition] -> ShowS)
-> Show SizeCondition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SizeCondition -> ShowS
showsPrec :: Int -> SizeCondition -> ShowS
$cshow :: SizeCondition -> String
show :: SizeCondition -> String
$cshowList :: [SizeCondition] -> ShowS
showList :: [SizeCondition] -> ShowS
Show, SizeCondition -> SizeCondition -> Bool
(SizeCondition -> SizeCondition -> Bool)
-> (SizeCondition -> SizeCondition -> Bool) -> Eq SizeCondition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SizeCondition -> SizeCondition -> Bool
== :: SizeCondition -> SizeCondition -> Bool
$c/= :: SizeCondition -> SizeCondition -> Bool
/= :: SizeCondition -> SizeCondition -> Bool
Eq)

instance RedisArg SizeCondition where
  encode :: SizeCondition -> ByteString
encode SizeCondition
CGT = ByteString
"GT"
  encode SizeCondition
CLT = ByteString
"LT"

-- |Add one or more members to a sorted set, or update its score if it already exists (<http://redis.io/commands/zadd>). The Redis command @ZADD@ is split up into 'zadd', 'zaddOpts'. Since Redis 1.2.0
data ZaddOpts = ZaddOpts
  { ZaddOpts -> Maybe Condition
zaddCondition :: Maybe Condition -- ^ Add on condition
  , ZaddOpts -> Maybe SizeCondition
zaddSizeCondition :: Maybe SizeCondition
  {- ^ Only update existing elements on condition

  Since Redis 6.2
  -}
  , ZaddOpts -> Bool
zaddChange    :: Bool -- ^ Modify the return value from the number of new elements added, to the total number of elements changed
  , ZaddOpts -> Bool
zaddIncrement :: Bool -- ^ When this option is specified ZADD acts like ZINCRBY. Only one score-element pair can be specified in this mode.
  } deriving (Int -> ZaddOpts -> ShowS
[ZaddOpts] -> ShowS
ZaddOpts -> String
(Int -> ZaddOpts -> ShowS)
-> (ZaddOpts -> String) -> ([ZaddOpts] -> ShowS) -> Show ZaddOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ZaddOpts -> ShowS
showsPrec :: Int -> ZaddOpts -> ShowS
$cshow :: ZaddOpts -> String
show :: ZaddOpts -> String
$cshowList :: [ZaddOpts] -> ShowS
showList :: [ZaddOpts] -> ShowS
Show, ZaddOpts -> ZaddOpts -> Bool
(ZaddOpts -> ZaddOpts -> Bool)
-> (ZaddOpts -> ZaddOpts -> Bool) -> Eq ZaddOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ZaddOpts -> ZaddOpts -> Bool
== :: ZaddOpts -> ZaddOpts -> Bool
$c/= :: ZaddOpts -> ZaddOpts -> Bool
/= :: ZaddOpts -> ZaddOpts -> Bool
Eq)


-- |Redis default 'ZaddOpts'. Equivalent to omitting all optional parameters.
--
-- @
-- ZaddOpts
--   { zaddCondition = Nothing -- omit NX and XX options
--   , zaddChange    = False   -- don't modify the return value from the number of new elements added, to the total number of elements changed
--   , zaddIncrement = False   -- don't add like ZINCRBY
--   , zaddSizeCondition = Nothing -- omit GT and LT options
--   }
-- @
--
defaultZaddOpts :: ZaddOpts
defaultZaddOpts :: ZaddOpts
defaultZaddOpts = ZaddOpts
  { zaddCondition :: Maybe Condition
zaddCondition = Maybe Condition
forall a. Maybe a
Nothing
  , zaddChange :: Bool
zaddChange    = Bool
False
  , zaddIncrement :: Bool
zaddIncrement = Bool
False
  , zaddSizeCondition :: Maybe SizeCondition
zaddSizeCondition = Maybe SizeCondition
forall a. Maybe a
Nothing
  }


zaddOpts
    :: (RedisCtx m f)
    => ByteString            -- ^ key
    -> [(Double,ByteString)] -- ^ scoreMember
    -> ZaddOpts              -- ^ options
    -> m (f Integer)
zaddOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [(Double, ByteString)] -> ZaddOpts -> m (f Integer)
zaddOpts ByteString
key [(Double, ByteString)]
scoreMembers ZaddOpts{Bool
Maybe SizeCondition
Maybe Condition
zaddCondition :: ZaddOpts -> Maybe Condition
zaddSizeCondition :: ZaddOpts -> Maybe SizeCondition
zaddChange :: ZaddOpts -> Bool
zaddIncrement :: ZaddOpts -> Bool
zaddCondition :: Maybe Condition
zaddSizeCondition :: Maybe SizeCondition
zaddChange :: Bool
zaddIncrement :: Bool
..} =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [[ByteString]] -> [ByteString]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ByteString
"ZADD", ByteString
key], [ByteString]
condition, [ByteString]
sizeCondition, [ByteString]
change, [ByteString]
increment, [ByteString]
scores]
  where
    scores :: [ByteString]
scores = ((Double, ByteString) -> [ByteString])
-> [(Double, ByteString)] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(Double
x,ByteString
y) -> [Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
x,ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
y]) [(Double, ByteString)]
scoreMembers
    condition :: [ByteString]
condition = (Condition -> ByteString) -> [Condition] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map Condition -> ByteString
forall a. RedisArg a => a -> ByteString
encode ([Condition] -> [ByteString]) -> [Condition] -> [ByteString]
forall a b. (a -> b) -> a -> b
$ Maybe Condition -> [Condition]
forall a. Maybe a -> [a]
maybeToList Maybe Condition
zaddCondition
    sizeCondition :: [ByteString]
sizeCondition = (SizeCondition -> ByteString) -> [SizeCondition] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map SizeCondition -> ByteString
forall a. RedisArg a => a -> ByteString
encode ([SizeCondition] -> [ByteString])
-> [SizeCondition] -> [ByteString]
forall a b. (a -> b) -> a -> b
$ Maybe SizeCondition -> [SizeCondition]
forall a. Maybe a -> [a]
maybeToList Maybe SizeCondition
zaddSizeCondition
    change :: [ByteString]
change = [ByteString
"CH" | Bool
zaddChange]
    increment :: [ByteString]
increment = [ByteString
"INCR" | Bool
zaddIncrement]


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


instance RedisArg ReplyMode where
  encode :: ReplyMode -> ByteString
encode ReplyMode
On = ByteString
"ON"
  encode ReplyMode
Off = ByteString
"OFF"
  encode ReplyMode
Skip = ByteString
"SKIP"

-- |Instruct the server whether to reply to commands (<http://redis.io/commands/client-reply>). Since Redis 3.2
clientReply
    :: (RedisCtx m f)
    => ReplyMode
    -> m (f Bool)
clientReply :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ReplyMode -> m (f Bool)
clientReply ReplyMode
mode =
    [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLIENT REPLY", ReplyMode -> ByteString
forall a. RedisArg a => a -> ByteString
encode ReplyMode
mode]

-- |Resumes processing commands from paused clients (<https://redis.io/commands/client-unpause>).
--
-- /O(N)/ where /N/ is the number of paused clients.
--
-- Since Redis 6.2.0
clientUnpause
    :: (RedisCtx m f)
    => m (f Status)
clientUnpause :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Status)
clientUnpause = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLIENT", ByteString
"UNPAUSE"]

-- | The CLIENT NO-TOUCH command controls whether commands sent by the client will alter the LRU/LFU of the keys they access (<https://redis.io/commands/client-notouch>).
--
-- When turned on, the current client will not change LFU/LRU stats, unless it sends the TOUCH command.
--
-- When turned off, the client touches LFU/LRU stats just as a normal client.
--
-- /O(1)/
--
-- Since Redis 7.2.0
clientNoTouch
    :: (RedisCtx m f)
    => Bool
    -> m (f Status)
clientNoTouch :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Bool -> m (f Status)
clientNoTouch Bool
flag = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLIENT NO-TOUCH", ByteString
encodedFlag] where
    encodedFlag :: ByteString
encodedFlag = if Bool
flag then ByteString
"ON" else ByteString
"OFF"

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

-- | The CLIENT SETINFO command assigns various info attributes to the current connection which are displayed in the output of CLIENT LIST and CLIENT INFO (<https://redis.io/commands/client-setinfo>).
--
-- /O(1)/
--
-- Since Redis 7.2.0
clientSetinfo
  :: (RedisCtx m f)
  => ClientSetInfoOpts
  -> m (f Status)
clientSetinfo :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ClientSetInfoOpts -> m (f Status)
clientSetinfo ClientSetInfoOpts
info_ = [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
"CLIENT"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
"SETINFO"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
clientSetInfoArg
  where
    clientSetInfoArg :: [ByteString]
clientSetInfoArg = case ClientSetInfoOpts
info_ of
      ClientSetInfoLibName ByteString
s -> [ByteString
"LIB-NAME", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
s]
      ClientSetInfoLibVer ByteString
s -> [ByteString
"LIB-VER", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
s]

-- |Get one or multiple random members from a set (<http://redis.io/commands/srandmember>). The Redis command @SRANDMEMBER@ is split up into 'srandmember', 'srandmemberN'. Since Redis 1.0.0
srandmember
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> m (f (Maybe ByteString))
srandmember :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
srandmember ByteString
key = [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SRANDMEMBER", ByteString
key]


-- |Get one or multiple random members from a set (<http://redis.io/commands/srandmember>). The Redis command @SRANDMEMBER@ is split up into 'srandmember', 'srandmemberN'. Since Redis 1.0.0
srandmemberN
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ count
    -> m (f [ByteString])
srandmemberN :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f [ByteString])
srandmemberN ByteString
key Integer
count = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SRANDMEMBER", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Remove and return one or multiple random members from a set (<http://redis.io/commands/spop>). The Redis command @SPOP@ is split up into 'spop', 'spopN'. Since Redis 1.0.0
spop
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> m (f (Maybe ByteString))
spop :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
spop ByteString
key = [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SPOP", ByteString
key]

-- |Remove and return one or multiple random members from a set (<http://redis.io/commands/spop>). The Redis command @SPOP@ is split up into 'spop', 'spopN'. Since Redis 1.0.0
spopN
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ count
    -> m (f [ByteString])
spopN :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f [ByteString])
spopN ByteString
key Integer
count = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SPOP", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Determines whether multiple members belong to a set (<https://redis.io/commands/smismember>).
--
-- /O(N)/ where /N/ is the number of elements being checked for membership.
--
-- Since Redis 6.2.0
smismember
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty ByteString
    -> m (f [Bool])
smismember :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> m (f [Bool])
smismember ByteString
key (ByteString
member:|[ByteString]
members) = [ByteString] -> m (f [Bool])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest (ByteString
"SMISMEMBER" ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
key ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
member ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
members)

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

defaultSintercardOpts :: SintercardOpts
defaultSintercardOpts :: SintercardOpts
defaultSintercardOpts = SintercardOpts
    { sintercardLimit :: Maybe Integer
sintercardLimit = Maybe Integer
forall a. Maybe a
Nothing
    }

-- |Returns the cardinality of the intersection of multiple sets (<https://redis.io/commands/sintercard>).
--
-- /O(N*M)/ worst case where /N/ is the cardinality of the smallest set and /M/ is the number of sets.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 7.0.0
sintercard
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> m (f Integer)
sintercard :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> m (f Integer)
sintercard NonEmpty ByteString
keys = NonEmpty ByteString -> SintercardOpts -> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> SintercardOpts -> m (f Integer)
sintercardOpts NonEmpty ByteString
keys SintercardOpts
defaultSintercardOpts

-- |Returns the cardinality of the intersection of multiple sets (<https://redis.io/commands/sintercard>).
--
-- /O(N*M)/ worst case where /N/ is the cardinality of the smallest set and /M/ is the number of sets.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 7.0.0
sintercardOpts
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> SintercardOpts
    -> m (f Integer)
sintercardOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> SintercardOpts -> m (f Integer)
sintercardOpts NonEmpty ByteString
keys SintercardOpts{Maybe Integer
sintercardLimit :: SintercardOpts -> Maybe Integer
sintercardLimit :: Maybe Integer
..} =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"SINTERCARD", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty ByteString -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty ByteString
keys)] [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]
limitArg
  where
    limitArg :: [ByteString]
limitArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
limit -> [ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
limit]) Maybe Integer
sintercardLimit

info
    :: (RedisCtx m f)
    => m (f ByteString)
info :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f ByteString)
info = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"INFO"]


infoSection
    :: (RedisCtx m f)
    => ByteString -- ^ section
    -> m (f ByteString)
infoSection :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f ByteString)
infoSection ByteString
section = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"INFO", ByteString
section]

-- |Determine if a key exists (<http://redis.io/commands/exists>). Since Redis 1.0.0
exists
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> m (f Bool)
exists :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Bool)
exists ByteString
key = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"EXISTS", ByteString
key]

newtype Cursor = Cursor ByteString deriving (Int -> Cursor -> ShowS
[Cursor] -> ShowS
Cursor -> String
(Int -> Cursor -> ShowS)
-> (Cursor -> String) -> ([Cursor] -> ShowS) -> Show Cursor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Cursor -> ShowS
showsPrec :: Int -> Cursor -> ShowS
$cshow :: Cursor -> String
show :: Cursor -> String
$cshowList :: [Cursor] -> ShowS
showList :: [Cursor] -> ShowS
Show, Cursor -> Cursor -> Bool
(Cursor -> Cursor -> Bool)
-> (Cursor -> Cursor -> Bool) -> Eq Cursor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Cursor -> Cursor -> Bool
== :: Cursor -> Cursor -> Bool
$c/= :: Cursor -> Cursor -> Bool
/= :: Cursor -> Cursor -> Bool
Eq)


instance RedisArg Cursor where
  encode :: Cursor -> ByteString
encode (Cursor ByteString
c) = ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
c


instance RedisResult Cursor where
  decode :: Reply -> Either Reply Cursor
decode (Bulk (Just ByteString
s)) = Cursor -> Either Reply Cursor
forall a b. b -> Either a b
Right (Cursor -> Either Reply Cursor) -> Cursor -> Either Reply Cursor
forall a b. (a -> b) -> a -> b
$ ByteString -> Cursor
Cursor ByteString
s
  decode Reply
r               = Reply -> Either Reply Cursor
forall a b. a -> Either a b
Left Reply
r


cursor0 :: Cursor
cursor0 :: Cursor
cursor0 = ByteString -> Cursor
Cursor ByteString
"0"

-- |Incrementally iterate the keys space (<http://redis.io/commands/scan>). The Redis command @SCAN@ is split up into 'scan', 'scanOpts'. Since Redis 2.8.0
scan
    :: (RedisCtx m f)
    => Cursor
    -> m (f (Cursor, [ByteString])) -- ^ next cursor and values
scan :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Cursor -> m (f (Cursor, [ByteString]))
scan Cursor
cursor = Cursor
-> ScanOpts -> Maybe ByteString -> m (f (Cursor, [ByteString]))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Cursor
-> ScanOpts -> Maybe ByteString -> m (f (Cursor, [ByteString]))
scanOpts Cursor
cursor ScanOpts
defaultScanOpts Maybe ByteString
forall a. Maybe a
Nothing


data ScanOpts = ScanOpts
  { ScanOpts -> Maybe ByteString
scanMatch :: Maybe ByteString
  , ScanOpts -> Maybe Integer
scanCount :: Maybe Integer
  } deriving (Int -> ScanOpts -> ShowS
[ScanOpts] -> ShowS
ScanOpts -> String
(Int -> ScanOpts -> ShowS)
-> (ScanOpts -> String) -> ([ScanOpts] -> ShowS) -> Show ScanOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScanOpts -> ShowS
showsPrec :: Int -> ScanOpts -> ShowS
$cshow :: ScanOpts -> String
show :: ScanOpts -> String
$cshowList :: [ScanOpts] -> ShowS
showList :: [ScanOpts] -> ShowS
Show, ScanOpts -> ScanOpts -> Bool
(ScanOpts -> ScanOpts -> Bool)
-> (ScanOpts -> ScanOpts -> Bool) -> Eq ScanOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScanOpts -> ScanOpts -> Bool
== :: ScanOpts -> ScanOpts -> Bool
$c/= :: ScanOpts -> ScanOpts -> Bool
/= :: ScanOpts -> ScanOpts -> Bool
Eq)


-- |Redis default 'ScanOpts'. Equivalent to omitting all optional parameters.
--
-- @
-- ScanOpts
--     { scanMatch = Nothing -- don't match any pattern
--     , scanCount = Nothing -- don't set any requirements on number elements returned (works like value @COUNT 10@)
--     }
-- @
--
defaultScanOpts :: ScanOpts
defaultScanOpts :: ScanOpts
defaultScanOpts = ScanOpts
  { scanMatch :: Maybe ByteString
scanMatch = Maybe ByteString
forall a. Maybe a
Nothing
  , scanCount :: Maybe Integer
scanCount = Maybe Integer
forall a. Maybe a
Nothing
  }

-- | Incrementally iterate the keys space (<http://redis.io/commands/scan>). The Redis command @SCAN@ is split up into 'scan', 'scanOpts'. Since Redis 2.8.0
scanOpts
    :: (RedisCtx m f)
    => Cursor
    -> ScanOpts
    -> Maybe ByteString -- ^ types of the object to  scan
    -> m (f (Cursor, [ByteString])) -- ^ next cursor and values
scanOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Cursor
-> ScanOpts -> Maybe ByteString -> m (f (Cursor, [ByteString]))
scanOpts Cursor
cursor ScanOpts
opts Maybe ByteString
mtype_  = [ByteString] -> m (f (Cursor, [ByteString]))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Cursor, [ByteString])))
-> [ByteString] -> m (f (Cursor, [ByteString]))
forall a b. (a -> b) -> a -> b
$ [ByteString] -> ScanOpts -> [ByteString]
addScanOpts [ByteString
"SCAN", Cursor -> ByteString
forall a. RedisArg a => a -> ByteString
encode Cursor
cursor] ScanOpts
opts
    [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ByteString
type_  -> [ByteString
"TYPE", ByteString
type_]) Maybe ByteString
mtype_


addScanOpts
    :: [ByteString] -- ^ main part of scan command
    -> ScanOpts
    -> [ByteString]
addScanOpts :: [ByteString] -> ScanOpts -> [ByteString]
addScanOpts [ByteString]
cmd ScanOpts{Maybe Integer
Maybe ByteString
scanMatch :: ScanOpts -> Maybe ByteString
scanCount :: ScanOpts -> Maybe Integer
scanMatch :: Maybe ByteString
scanCount :: Maybe Integer
..} =
    [[ByteString]] -> [ByteString]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ByteString]
cmd, [ByteString]
match, [ByteString]
count]
  where
    prepend :: a -> a -> [a]
prepend a
x a
y = [a
x, a
y]
    match :: [ByteString]
match       = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (ByteString -> ByteString -> [ByteString]
forall {a}. a -> a -> [a]
prepend ByteString
"MATCH") Maybe ByteString
scanMatch
    count :: [ByteString]
count       = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] ((ByteString -> ByteString -> [ByteString]
forall {a}. a -> a -> [a]
prepend ByteString
"COUNT")(ByteString -> [ByteString])
-> (Integer -> ByteString) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode) Maybe Integer
scanCount

-- |Incrementally iterate Set elements (<http://redis.io/commands/sscan>). The Redis command @SSCAN@ is split up into 'sscan', 'sscanOpts'. Since Redis 2.8.0
sscan
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Cursor
    -> m (f (Cursor, [ByteString])) -- ^ next cursor and values
sscan :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Cursor -> m (f (Cursor, [ByteString]))
sscan ByteString
key Cursor
cursor = ByteString -> Cursor -> ScanOpts -> m (f (Cursor, [ByteString]))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Cursor -> ScanOpts -> m (f (Cursor, [ByteString]))
sscanOpts ByteString
key Cursor
cursor ScanOpts
defaultScanOpts

-- |Incrementally iterate Set elements (<http://redis.io/commands/sscan>). The Redis command @SSCAN@ is split up into 'sscan', 'sscanOpts'. Since Redis 2.8.0
sscanOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Cursor
    -> ScanOpts
    -> m (f (Cursor, [ByteString])) -- ^ next cursor and values
sscanOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Cursor -> ScanOpts -> m (f (Cursor, [ByteString]))
sscanOpts ByteString
key Cursor
cursor ScanOpts
opts = [ByteString] -> m (f (Cursor, [ByteString]))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Cursor, [ByteString])))
-> [ByteString] -> m (f (Cursor, [ByteString]))
forall a b. (a -> b) -> a -> b
$ [ByteString] -> ScanOpts -> [ByteString]
addScanOpts [ByteString
"SSCAN", ByteString
key, Cursor -> ByteString
forall a. RedisArg a => a -> ByteString
encode Cursor
cursor] ScanOpts
opts

-- |Incrementally iterate hash fields and associated values (<http://redis.io/commands/hscan>). The Redis command @HSCAN@ is split up into 'hscan', 'hscanOpts'. Since Redis 2.8.0
hscan
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Cursor
    -> m (f (Cursor, [(ByteString, ByteString)])) -- ^ next cursor and values
hscan :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Cursor -> m (f (Cursor, [(ByteString, ByteString)]))
hscan ByteString
key Cursor
cursor = ByteString
-> Cursor -> ScanOpts -> m (f (Cursor, [(ByteString, ByteString)]))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Cursor -> ScanOpts -> m (f (Cursor, [(ByteString, ByteString)]))
hscanOpts ByteString
key Cursor
cursor ScanOpts
defaultScanOpts

-- |Incrementally iterate hash fields and associated values (<http://redis.io/commands/hscan>). The Redis command @HSCAN@ is split up into 'hscan', 'hscanOpts'. Since Redis 2.8.0
hscanOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Cursor
    -> ScanOpts
    -> m (f (Cursor, [(ByteString, ByteString)])) -- ^ next cursor and values
hscanOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Cursor -> ScanOpts -> m (f (Cursor, [(ByteString, ByteString)]))
hscanOpts ByteString
key Cursor
cursor ScanOpts
opts = [ByteString] -> m (f (Cursor, [(ByteString, ByteString)]))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Cursor, [(ByteString, ByteString)])))
-> [ByteString] -> m (f (Cursor, [(ByteString, ByteString)]))
forall a b. (a -> b) -> a -> b
$ [ByteString] -> ScanOpts -> [ByteString]
addScanOpts [ByteString
"HSCAN", ByteString
key, Cursor -> ByteString
forall a. RedisArg a => a -> ByteString
encode Cursor
cursor] ScanOpts
opts

-- |Returns a random field from a hash (<https://redis.io/commands/hrandfield>).
--
-- /O(1)/
--
-- Since Redis 6.2.0
hrandfield
    :: (RedisCtx m f)
    => ByteString
    -> m (f (Maybe ByteString))
hrandfield :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
hrandfield ByteString
key = [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"HRANDFIELD", ByteString
key]

-- |Returns one or more random fields from a hash (<https://redis.io/commands/hrandfield>).
--
-- /O(N)/ where /N/ is the number of fields returned.
--
-- If the provided count argument is positive, return an array of distinct fields. The array's length is either count or the hash's number of fields (HLEN), whichever is lower.
--
-- If called with a negative count, the behavior changes and the command is allowed to return the same field multiple times. In this case, the number of returned fields is the absolute value of the specified count.
--
-- Since Redis 6.2.0
hrandfieldCount
    :: (RedisCtx m f)
    => ByteString
    -> Integer
    -> m (f [ByteString])
hrandfieldCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f [ByteString])
hrandfieldCount ByteString
key Integer
count = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"HRANDFIELD", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Returns one or more random fields and their values from a hash (<https://redis.io/commands/hrandfield>).
--
-- /O(N)/ where /N/ is the number of fields returned.
--
-- If the provided count argument is positive, return an array of distinct fields. The array's length is either count or the hash's number of fields (HLEN), whichever is lower.
--
-- If called with a negative count, the behavior changes and the command is allowed to return the same field multiple times. In this case, the number of returned fields is the absolute value of the specified count.
--
-- Since Redis 6.2.0
hrandfieldCountWithValues
    :: (RedisCtx m f)
    => ByteString
    -> Integer
    -> m (f [(ByteString, ByteString)])
hrandfieldCountWithValues :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f [(ByteString, ByteString)])
hrandfieldCountWithValues ByteString
key Integer
count =
    [ByteString] -> m (f [(ByteString, ByteString)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"HRANDFIELD", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count, ByteString
"WITHVALUES"]


zscan
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Cursor
    -> m (f (Cursor, [(ByteString, Double)])) -- ^ next cursor and values
zscan :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Cursor -> m (f (Cursor, [(ByteString, Double)]))
zscan ByteString
key Cursor
cursor = ByteString
-> Cursor -> ScanOpts -> m (f (Cursor, [(ByteString, Double)]))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Cursor -> ScanOpts -> m (f (Cursor, [(ByteString, Double)]))
zscanOpts ByteString
key Cursor
cursor ScanOpts
defaultScanOpts


zscanOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Cursor
    -> ScanOpts
    -> m (f (Cursor, [(ByteString, Double)])) -- ^ next cursor and values
zscanOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Cursor -> ScanOpts -> m (f (Cursor, [(ByteString, Double)]))
zscanOpts ByteString
key Cursor
cursor ScanOpts
opts = [ByteString] -> m (f (Cursor, [(ByteString, Double)]))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Cursor, [(ByteString, Double)])))
-> [ByteString] -> m (f (Cursor, [(ByteString, Double)]))
forall a b. (a -> b) -> a -> b
$ [ByteString] -> ScanOpts -> [ByteString]
addScanOpts [ByteString
"ZSCAN", ByteString
key, Cursor -> ByteString
forall a. RedisArg a => a -> ByteString
encode Cursor
cursor] ScanOpts
opts

data RangeLex a = Incl a | Excl a | Minr | Maxr deriving (Int -> RangeLex a -> ShowS
[RangeLex a] -> ShowS
RangeLex a -> String
(Int -> RangeLex a -> ShowS)
-> (RangeLex a -> String)
-> ([RangeLex a] -> ShowS)
-> Show (RangeLex a)
forall a. Show a => Int -> RangeLex a -> ShowS
forall a. Show a => [RangeLex a] -> ShowS
forall a. Show a => RangeLex a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> RangeLex a -> ShowS
showsPrec :: Int -> RangeLex a -> ShowS
$cshow :: forall a. Show a => RangeLex a -> String
show :: RangeLex a -> String
$cshowList :: forall a. Show a => [RangeLex a] -> ShowS
showList :: [RangeLex a] -> ShowS
Show, RangeLex a -> RangeLex a -> Bool
(RangeLex a -> RangeLex a -> Bool)
-> (RangeLex a -> RangeLex a -> Bool) -> Eq (RangeLex a)
forall a. Eq a => RangeLex a -> RangeLex a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => RangeLex a -> RangeLex a -> Bool
== :: RangeLex a -> RangeLex a -> Bool
$c/= :: forall a. Eq a => RangeLex a -> RangeLex a -> Bool
/= :: RangeLex a -> RangeLex a -> Bool
Eq)

instance RedisArg a => RedisArg (RangeLex a) where
  encode :: RangeLex a -> ByteString
encode (Incl a
bs) = ByteString
"[" ByteString -> ByteString -> ByteString
`append` a -> ByteString
forall a. RedisArg a => a -> ByteString
encode a
bs
  encode (Excl a
bs) = ByteString
"(" ByteString -> ByteString -> ByteString
`append` a -> ByteString
forall a. RedisArg a => a -> ByteString
encode a
bs
  encode RangeLex a
Minr      = ByteString
"-"
  encode RangeLex a
Maxr      = ByteString
"+"

-- |Return a range of members in a sorted set, by lexicographical range (<http://redis.io/commands/zrangebylex>). Since Redis 2.8.9
zrangebylex::(RedisCtx m f) =>
    ByteString             -- ^ key
    -> RangeLex ByteString -- ^ min
    -> RangeLex ByteString -- ^ max
    -> m (f [ByteString])
zrangebylex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> RangeLex ByteString -> RangeLex ByteString -> m (f [ByteString])
zrangebylex ByteString
key RangeLex ByteString
min RangeLex ByteString
max =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANGEBYLEX", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, RangeLex ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode RangeLex ByteString
min, RangeLex ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode RangeLex ByteString
max]

zrangebylexLimit
    ::(RedisCtx m f)
    => ByteString -- ^ key
    -> RangeLex ByteString -- ^ min
    -> RangeLex ByteString -- ^ max
    -> Integer             -- ^ offset
    -> Integer             -- ^ count
    -> m (f [ByteString])
zrangebylexLimit :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> RangeLex ByteString
-> RangeLex ByteString
-> Integer
-> Integer
-> m (f [ByteString])
zrangebylexLimit ByteString
key RangeLex ByteString
min RangeLex ByteString
max Integer
offset Integer
count  =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANGEBYLEX", ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode ByteString
key, RangeLex ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode RangeLex ByteString
min, RangeLex ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode RangeLex ByteString
max,
                 ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
offset, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

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

instance RedisArg ZPopMinMax where
    encode :: ZPopMinMax -> ByteString
encode ZPopMinMax
ZPopMin = ByteString
"MIN"
    encode ZPopMinMax
ZPopMax = ByteString
"MAX"

data ZPopResponse = ZPopResponse
    { ZPopResponse -> Maybe ByteString
zPopResponseKey :: Maybe ByteString
    , ZPopResponse -> [(ByteString, Double)]
zPopResponseValues :: [(ByteString, Double)]
    } deriving (Int -> ZPopResponse -> ShowS
[ZPopResponse] -> ShowS
ZPopResponse -> String
(Int -> ZPopResponse -> ShowS)
-> (ZPopResponse -> String)
-> ([ZPopResponse] -> ShowS)
-> Show ZPopResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ZPopResponse -> ShowS
showsPrec :: Int -> ZPopResponse -> ShowS
$cshow :: ZPopResponse -> String
show :: ZPopResponse -> String
$cshowList :: [ZPopResponse] -> ShowS
showList :: [ZPopResponse] -> ShowS
Show, ZPopResponse -> ZPopResponse -> Bool
(ZPopResponse -> ZPopResponse -> Bool)
-> (ZPopResponse -> ZPopResponse -> Bool) -> Eq ZPopResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ZPopResponse -> ZPopResponse -> Bool
== :: ZPopResponse -> ZPopResponse -> Bool
$c/= :: ZPopResponse -> ZPopResponse -> Bool
/= :: ZPopResponse -> ZPopResponse -> Bool
Eq)

instance RedisResult ZPopResponse where
    decode :: Reply -> Either Reply ZPopResponse
decode (MultiBulk (Just [Bulk (Just ByteString
key), MultiBulk (Just [Reply]
values)])) =
        Maybe ByteString -> [(ByteString, Double)] -> ZPopResponse
ZPopResponse (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
key) ([(ByteString, Double)] -> ZPopResponse)
-> Either Reply [(ByteString, Double)] -> Either Reply ZPopResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Reply -> Either Reply (ByteString, Double))
-> [Reply] -> Either Reply [(ByteString, Double)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply (ByteString, Double)
forall a. RedisResult a => Reply -> Either Reply a
decode [Reply]
values
    decode Reply
r = Reply -> Either Reply ZPopResponse
forall a b. a -> Either a b
Left Reply
r

-- |Removes and returns member-score pairs from the first non-empty sorted set from a list of keys (<https://redis.io/commands/zmpop>).
--
-- /O(K) + O(M\log(N))/ where /K/ is the number of provided keys, /N/ is the number of elements in the sorted set, and /M/ is the number of elements popped.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 7.0.0
zmpop
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> ZPopMinMax
    -> m (f (Maybe ZPopResponse))
zmpop :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString -> ZPopMinMax -> m (f (Maybe ZPopResponse))
zmpop NonEmpty ByteString
keys ZPopMinMax
where_ = NonEmpty ByteString
-> ZPopMinMax -> Integer -> m (f (Maybe ZPopResponse))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ZPopMinMax -> Integer -> m (f (Maybe ZPopResponse))
zmpopCount NonEmpty ByteString
keys ZPopMinMax
where_ Integer
1

-- |Removes and returns member-score pairs from the first non-empty sorted set from a list of keys (<https://redis.io/commands/zmpop>).
--
-- /O(K) + O(M\log(N))/ where /K/ is the number of provided keys, /N/ is the number of elements in the sorted set, and /M/ is the number of elements popped.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 7.0.0
zmpopCount
    :: (RedisCtx m f)
    => NonEmpty ByteString
    -> ZPopMinMax
    -> Integer
    -> m (f (Maybe ZPopResponse))
zmpopCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty ByteString
-> ZPopMinMax -> Integer -> m (f (Maybe ZPopResponse))
zmpopCount NonEmpty ByteString
keys ZPopMinMax
where_ Integer
count =
    [ByteString] -> m (f (Maybe ZPopResponse))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe ZPopResponse)))
-> [ByteString] -> m (f (Maybe ZPopResponse))
forall a b. (a -> b) -> a -> b
$ [ByteString
"ZMPOP", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty ByteString -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty ByteString
keys)] [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]
++ [ZPopMinMax -> ByteString
forall a. RedisArg a => a -> ByteString
encode ZPopMinMax
where_, ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Removes and returns member-score pairs from the first non-empty sorted set from a list of keys, or blocks until one is available (<https://redis.io/commands/bzmpop>).
--
-- /O(K) + O(M\log(N))/ where /K/ is the number of provided keys, /N/ is the number of elements in the sorted set, and /M/ is the number of elements popped.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 7.0.0
bzmpop
    :: (RedisCtx m f)
    => Double
    -> NonEmpty ByteString
    -> ZPopMinMax
    -> m (f (Maybe ZPopResponse))
bzmpop :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Double
-> NonEmpty ByteString -> ZPopMinMax -> m (f (Maybe ZPopResponse))
bzmpop Double
timeout NonEmpty ByteString
keys ZPopMinMax
where_ = Double
-> NonEmpty ByteString
-> ZPopMinMax
-> Integer
-> m (f (Maybe ZPopResponse))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Double
-> NonEmpty ByteString
-> ZPopMinMax
-> Integer
-> m (f (Maybe ZPopResponse))
bzmpopCount Double
timeout NonEmpty ByteString
keys ZPopMinMax
where_ Integer
1

-- |Removes and returns member-score pairs from the first non-empty sorted set from a list of keys, or blocks until one is available (<https://redis.io/commands/bzmpop>).
--
-- /O(K) + O(M\log(N))/ where /K/ is the number of provided keys, /N/ is the number of elements in the sorted set, and /M/ is the number of elements popped.
--
-- In clustered environment, commands must operate on keys within the same hash slot.
--
-- Since Redis 7.0.0
bzmpopCount
    :: (RedisCtx m f)
    => Double
    -> NonEmpty ByteString
    -> ZPopMinMax
    -> Integer
    -> m (f (Maybe ZPopResponse))
bzmpopCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Double
-> NonEmpty ByteString
-> ZPopMinMax
-> Integer
-> m (f (Maybe ZPopResponse))
bzmpopCount Double
timeout NonEmpty ByteString
keys ZPopMinMax
where_ Integer
count =
    [ByteString] -> m (f (Maybe ZPopResponse))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe ZPopResponse)))
-> [ByteString] -> m (f (Maybe ZPopResponse))
forall a b. (a -> b) -> a -> b
$ [ByteString
"BZMPOP", Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
timeout, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty ByteString -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty ByteString
keys)] [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]
++ [ZPopMinMax -> ByteString
forall a. RedisArg a => a -> ByteString
encode ZPopMinMax
where_, ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Returns the score of one or more members in a sorted set (<https://redis.io/commands/zmscore>).
--
-- /O(N)/ where /N/ is the number of members being requested.
--
-- Since Redis 6.2.0
zmscore
    :: (RedisCtx m f)
    => ByteString
    -> NonEmpty ByteString
    -> m (f [Maybe Double])
zmscore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> m (f [Maybe Double])
zmscore ByteString
key (ByteString
member:|[ByteString]
members) = [ByteString] -> m (f [Maybe Double])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest (ByteString
"ZMSCORE" ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
key ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
member ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
members)

-- |Returns a random member from a sorted set (<https://redis.io/commands/zrandmember>).
--
-- /O(1)/ without the optional count argument.
--
-- Since Redis 6.2.0
zrandmember
    :: (RedisCtx m f)
    => ByteString
    -> m (f (Maybe ByteString))
zrandmember :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe ByteString))
zrandmember ByteString
key = [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANDMEMBER", ByteString
key]

-- |Returns one or more random members from a sorted set (<https://redis.io/commands/zrandmember>).
--
-- /O(N)/ where /N/ is the number of members returned.
--
-- Since Redis 6.2.0
zrandmemberN
    :: (RedisCtx m f)
    => ByteString
    -> Integer
    -> m (f [ByteString])
zrandmemberN :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f [ByteString])
zrandmemberN ByteString
key Integer
count = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANDMEMBER", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]

-- |Returns one or more random members and their scores from a sorted set (<https://redis.io/commands/zrandmember>).
--
-- /O(N)/ where /N/ is the number of members returned.
--
-- Since Redis 6.2.0
zrandmemberWithscores
    :: (RedisCtx m f)
    => ByteString
    -> Integer
    -> m (f [(ByteString, Double)])
zrandmemberWithscores :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f [(ByteString, Double)])
zrandmemberWithscores ByteString
key Integer
count =
    [ByteString] -> m (f [(ByteString, Double)])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ZRANDMEMBER", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count, ByteString
"WITHSCORES"]

data ZRangeStoreRange
    = ZRangeStoreByIndex Integer Integer
    | ZRangeStoreByScore Double Double
    | ZRangeStoreByLex (RangeLex ByteString) (RangeLex ByteString)
    deriving (Int -> ZRangeStoreRange -> ShowS
[ZRangeStoreRange] -> ShowS
ZRangeStoreRange -> String
(Int -> ZRangeStoreRange -> ShowS)
-> (ZRangeStoreRange -> String)
-> ([ZRangeStoreRange] -> ShowS)
-> Show ZRangeStoreRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ZRangeStoreRange -> ShowS
showsPrec :: Int -> ZRangeStoreRange -> ShowS
$cshow :: ZRangeStoreRange -> String
show :: ZRangeStoreRange -> String
$cshowList :: [ZRangeStoreRange] -> ShowS
showList :: [ZRangeStoreRange] -> ShowS
Show, ZRangeStoreRange -> ZRangeStoreRange -> Bool
(ZRangeStoreRange -> ZRangeStoreRange -> Bool)
-> (ZRangeStoreRange -> ZRangeStoreRange -> Bool)
-> Eq ZRangeStoreRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ZRangeStoreRange -> ZRangeStoreRange -> Bool
== :: ZRangeStoreRange -> ZRangeStoreRange -> Bool
$c/= :: ZRangeStoreRange -> ZRangeStoreRange -> Bool
/= :: ZRangeStoreRange -> ZRangeStoreRange -> Bool
Eq)

data ZRangeStoreOpts = ZRangeStoreOpts
    { ZRangeStoreOpts -> Bool
zRangeStoreRev :: Bool
    , ZRangeStoreOpts -> Maybe (Integer, Integer)
zRangeStoreLimit :: Maybe (Integer, Integer)
    } deriving (Int -> ZRangeStoreOpts -> ShowS
[ZRangeStoreOpts] -> ShowS
ZRangeStoreOpts -> String
(Int -> ZRangeStoreOpts -> ShowS)
-> (ZRangeStoreOpts -> String)
-> ([ZRangeStoreOpts] -> ShowS)
-> Show ZRangeStoreOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ZRangeStoreOpts -> ShowS
showsPrec :: Int -> ZRangeStoreOpts -> ShowS
$cshow :: ZRangeStoreOpts -> String
show :: ZRangeStoreOpts -> String
$cshowList :: [ZRangeStoreOpts] -> ShowS
showList :: [ZRangeStoreOpts] -> ShowS
Show, ZRangeStoreOpts -> ZRangeStoreOpts -> Bool
(ZRangeStoreOpts -> ZRangeStoreOpts -> Bool)
-> (ZRangeStoreOpts -> ZRangeStoreOpts -> Bool)
-> Eq ZRangeStoreOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ZRangeStoreOpts -> ZRangeStoreOpts -> Bool
== :: ZRangeStoreOpts -> ZRangeStoreOpts -> Bool
$c/= :: ZRangeStoreOpts -> ZRangeStoreOpts -> Bool
/= :: ZRangeStoreOpts -> ZRangeStoreOpts -> Bool
Eq)

defaultZRangeStoreOpts :: ZRangeStoreOpts
defaultZRangeStoreOpts :: ZRangeStoreOpts
defaultZRangeStoreOpts = ZRangeStoreOpts
    { zRangeStoreRev :: Bool
zRangeStoreRev = Bool
False
    , zRangeStoreLimit :: Maybe (Integer, Integer)
zRangeStoreLimit = Maybe (Integer, Integer)
forall a. Maybe a
Nothing
    }

-- |Stores a range of members from a sorted set in a destination key (<https://redis.io/commands/zrangestore>).
--
-- /O(\log(N) + M)/ with /N/ being the number of elements in the sorted set and /M/ the number of elements stored into the destination key.
--
-- Since Redis 6.2.0
zrangestore
    :: (RedisCtx m f)
    => ByteString
    -> ByteString
    -> Integer
    -> Integer
    -> m (f Integer)
zrangestore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> Integer -> Integer -> m (f Integer)
zrangestore ByteString
destination ByteString
source Integer
start Integer
stop =
    ByteString
-> ByteString
-> ZRangeStoreRange
-> ZRangeStoreOpts
-> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ZRangeStoreRange
-> ZRangeStoreOpts
-> m (f Integer)
zrangestoreOpts ByteString
destination ByteString
source (Integer -> Integer -> ZRangeStoreRange
ZRangeStoreByIndex Integer
start Integer
stop) ZRangeStoreOpts
defaultZRangeStoreOpts

-- |Stores a range of members from a sorted set in a destination key (<https://redis.io/commands/zrangestore>).
--
-- /O(\log(N) + M)/ with /N/ being the number of elements in the sorted set and /M/ the number of elements stored into the destination key.
--
-- Since Redis 6.2.0
zrangestoreOpts
    :: (RedisCtx m f)
    => ByteString
    -> ByteString
    -> ZRangeStoreRange
    -> ZRangeStoreOpts
    -> m (f Integer)
zrangestoreOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ZRangeStoreRange
-> ZRangeStoreOpts
-> m (f Integer)
zrangestoreOpts ByteString
destination ByteString
source ZRangeStoreRange
range ZRangeStoreOpts
opts =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"ZRANGESTORE", ByteString
destination, ByteString
source] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ZRangeStoreRange -> [ByteString]
zRangeStoreRangeArgs ZRangeStoreRange
range [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ZRangeStoreOpts -> [ByteString]
zRangeStoreOptsArgs ZRangeStoreOpts
opts

zRangeStoreRangeArgs :: ZRangeStoreRange -> [ByteString]
zRangeStoreRangeArgs :: ZRangeStoreRange -> [ByteString]
zRangeStoreRangeArgs ZRangeStoreRange
range = case ZRangeStoreRange
range of
    ZRangeStoreByIndex 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]
    ZRangeStoreByScore Double
minScore Double
maxScore ->
        [Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
minScore, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
maxScore, ByteString
"BYSCORE"]
    ZRangeStoreByLex RangeLex ByteString
minMember RangeLex ByteString
maxMember ->
        [RangeLex ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode RangeLex ByteString
minMember, RangeLex ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode RangeLex ByteString
maxMember, ByteString
"BYLEX"]

zRangeStoreOptsArgs :: ZRangeStoreOpts -> [ByteString]
zRangeStoreOptsArgs :: ZRangeStoreOpts -> [ByteString]
zRangeStoreOptsArgs ZRangeStoreOpts{Bool
Maybe (Integer, Integer)
zRangeStoreRev :: ZRangeStoreOpts -> Bool
zRangeStoreLimit :: ZRangeStoreOpts -> Maybe (Integer, Integer)
zRangeStoreRev :: Bool
zRangeStoreLimit :: Maybe (Integer, Integer)
..} =
    [ByteString]
revArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
limitArg
  where
    revArg :: [ByteString]
revArg = [ByteString
"REV" | Bool
zRangeStoreRev]
    limitArg :: [ByteString]
limitArg = [ByteString]
-> ((Integer, Integer) -> [ByteString])
-> Maybe (Integer, Integer)
-> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\(Integer
offset, Integer
count) -> [ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
offset, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]) Maybe (Integer, Integer)
zRangeStoreLimit

-- | Trimming strategy.
--
-- @since 0.16.0
data TrimStrategy
  = TrimMaxlen Integer
    -- ^ Evicts entries as long as the stream's length exceeds the specified threshold, where threshold is a positive integer.
  | TrimMinId ByteString
   {- ^  Evicts entries with IDs lower than threshold, where threshold is a stream ID.

   Since Redis 6.2: will fail if used on ealier versions.
   -}

-- | Type of the trimming.
--
-- @since 0.16.0
data TrimType
  = TrimExact {- ^ Exact trimming -}
  | TrimApprox (Maybe Integer) {- ^ Approximate trimming. Is faster, but may leave slightly more
    elements in the stream if they can't be immediately deleted.

    Additional parameter Specifies the maximal count of entries that will be evicted. When LIMIT and count aren't specified, the default value of 100 * the number of entries in a macro node will be implicitly used as the count, @Just 0@ removes the limit entirely.
    -}

data TrimOpts = TrimOpts
  { TrimOpts -> TrimStrategy
trimOptsStrategy :: TrimStrategy
  , TrimOpts -> TrimType
trimOptsType :: TrimType
  }

-- | Converts trim options to the low level parameters
internalTrimArgToList :: TrimOpts -> [ByteString]
internalTrimArgToList :: TrimOpts -> [ByteString]
internalTrimArgToList TrimOpts{TrimType
TrimStrategy
trimOptsStrategy :: TrimOpts -> TrimStrategy
trimOptsType :: TrimOpts -> TrimType
trimOptsStrategy :: TrimStrategy
trimOptsType :: TrimType
..} = [ByteString]
trimArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
limitArg
  where trimArg :: [ByteString]
trimArg = case TrimStrategy
trimOptsStrategy of
           TrimMaxlen Integer
max -> (ByteString
"MAXLEN"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:ByteString
approxArgByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
maxByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[])
           TrimMinId ByteString
i -> (ByteString
"MINID"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:ByteString
approxArgByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:ByteString
iByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[])
        (ByteString
approxArg, [ByteString]
limitArg) = case TrimType
trimOptsType of
            TrimType
TrimExact -> (ByteString
"=", [])
            TrimApprox Maybe Integer
limit -> (ByteString
"~",  [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] ((ByteString
"LIMIT"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:) ([ByteString] -> [ByteString])
-> (Integer -> [ByteString]) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[]) (ByteString -> [ByteString])
-> (Integer -> ByteString) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode) Maybe Integer
limit)

trimOpts :: TrimStrategy -> TrimType -> TrimOpts
trimOpts :: TrimStrategy -> TrimType -> TrimOpts
trimOpts = TrimStrategy -> TrimType -> TrimOpts
TrimOpts

data XAddOpts = XAddOpts {
    XAddOpts -> Maybe TrimOpts
xAddTrimOpts :: Maybe TrimOpts, -- ^ Call XTRIM right after XADD
    XAddOpts -> Bool
xAddnoMkStream :: Bool
    {- ^ Don't create a new stream if it doesn't exist

    @since Redis 6.2
    -}
}

defaultXAddOpts :: XAddOpts
defaultXAddOpts :: XAddOpts
defaultXAddOpts = XAddOpts {
    xAddTrimOpts :: Maybe TrimOpts
xAddTrimOpts = Maybe TrimOpts
forall a. Maybe a
Nothing,
    xAddnoMkStream :: Bool
xAddnoMkStream = Bool
False
}

-- |Add a value to a stream (<https://redis.io/commands/xadd>). The Redis command @XADD@ is split up into 'xadd', 'xaddOpts'. Since Redis 5.0.0
xaddOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Message ID
    -> [(ByteString, ByteString)] -- ^ Message data (field, value)
    -> XAddOpts -- ^ Additional parameteers
    -> m (f ByteString) -- ^ ID of the added entry.
xaddOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [(ByteString, ByteString)]
-> XAddOpts
-> m (f ByteString)
xaddOpts ByteString
key ByteString
entryId [(ByteString, ByteString)]
fieldValues XAddOpts
opts = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f ByteString))
-> [ByteString] -> m (f ByteString)
forall a b. (a -> b) -> a -> b
$
    [ByteString
"XADD", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
noMkStreamArgs [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
trimArgs [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
entryId] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
fieldArgs
    where
        fieldArgs :: [ByteString]
fieldArgs = ((ByteString, ByteString) -> [ByteString])
-> [(ByteString, ByteString)] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(ByteString
x,ByteString
y) -> [ByteString
x,ByteString
y]) [(ByteString, ByteString)]
fieldValues
        noMkStreamArgs :: [ByteString]
noMkStreamArgs = [ByteString
"NOMKSTREAM" | XAddOpts -> Bool
xAddnoMkStream XAddOpts
opts]
        trimArgs :: [ByteString]
trimArgs = [ByteString]
-> (TrimOpts -> [ByteString]) -> Maybe TrimOpts -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (TrimOpts -> [ByteString]
internalTrimArgToList) (XAddOpts -> Maybe TrimOpts
xAddTrimOpts XAddOpts
opts)

-- | /O(1)/ Adds a value to a stream (<https://redis.io/commands/xadd>). Since Redis 5.0.0
xadd
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name
    -> ByteString -- ^ Message id
    -> [(ByteString, ByteString)] -- ^ Message data (field, value)
    -> m (f ByteString)
xadd :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> [(ByteString, ByteString)] -> m (f ByteString)
xadd ByteString
key ByteString
entryId [(ByteString, ByteString)]
fieldValues = ByteString
-> ByteString
-> [(ByteString, ByteString)]
-> XAddOpts
-> m (f ByteString)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [(ByteString, ByteString)]
-> XAddOpts
-> m (f ByteString)
xaddOpts ByteString
key ByteString
entryId [(ByteString, ByteString)]
fieldValues XAddOpts
defaultXAddOpts

-- | Additional parameters.
newtype XAutoclaimOpts = XAutoclaimOpts {
    XAutoclaimOpts -> Maybe Integer
xAutoclaimCount :: Maybe Integer -- ^  The upper limit of the number of entries that the command attempts to claim (default: 100).
}

-- | Default 'XAutoclaimOpts' value.
--
-- Prefer to use this function over direct use of constructor to preserve
-- backwards compatibility.
--
-- Defaults to @[Count 100)@
defaultXAutoclaimOpts :: XAutoclaimOpts
defaultXAutoclaimOpts :: XAutoclaimOpts
defaultXAutoclaimOpts = XAutoclaimOpts {
    xAutoclaimCount :: Maybe Integer
xAutoclaimCount = Maybe Integer
forall a. Maybe a
Nothing
}

-- | Result of the 'xautoclaim' family of calls
data XAutoclaimResult resultFormat = XAutoclaimResult {
    forall resultFormat. XAutoclaimResult resultFormat -> ByteString
xAutoclaimResultId :: ByteString,
    -- ^ ID of message that should be used in the next 'xautoclaim' call as a start parameter.
    forall resultFormat.
XAutoclaimResult resultFormat -> [resultFormat]
xAutoclaimClaimedMessages :: [resultFormat],
    -- ^ List of succesfully claimed messages.
    forall resultFormat. XAutoclaimResult resultFormat -> [ByteString]
xAutoclaimDeletedMessages :: [ByteString]
    -- ^ List of the messages that are available in the PEL but already deleted from the stream.
} deriving (Int -> XAutoclaimResult resultFormat -> ShowS
[XAutoclaimResult resultFormat] -> ShowS
XAutoclaimResult resultFormat -> String
(Int -> XAutoclaimResult resultFormat -> ShowS)
-> (XAutoclaimResult resultFormat -> String)
-> ([XAutoclaimResult resultFormat] -> ShowS)
-> Show (XAutoclaimResult resultFormat)
forall resultFormat.
Show resultFormat =>
Int -> XAutoclaimResult resultFormat -> ShowS
forall resultFormat.
Show resultFormat =>
[XAutoclaimResult resultFormat] -> ShowS
forall resultFormat.
Show resultFormat =>
XAutoclaimResult resultFormat -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall resultFormat.
Show resultFormat =>
Int -> XAutoclaimResult resultFormat -> ShowS
showsPrec :: Int -> XAutoclaimResult resultFormat -> ShowS
$cshow :: forall resultFormat.
Show resultFormat =>
XAutoclaimResult resultFormat -> String
show :: XAutoclaimResult resultFormat -> String
$cshowList :: forall resultFormat.
Show resultFormat =>
[XAutoclaimResult resultFormat] -> ShowS
showList :: [XAutoclaimResult resultFormat] -> ShowS
Show, XAutoclaimResult resultFormat
-> XAutoclaimResult resultFormat -> Bool
(XAutoclaimResult resultFormat
 -> XAutoclaimResult resultFormat -> Bool)
-> (XAutoclaimResult resultFormat
    -> XAutoclaimResult resultFormat -> Bool)
-> Eq (XAutoclaimResult resultFormat)
forall resultFormat.
Eq resultFormat =>
XAutoclaimResult resultFormat
-> XAutoclaimResult resultFormat -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall resultFormat.
Eq resultFormat =>
XAutoclaimResult resultFormat
-> XAutoclaimResult resultFormat -> Bool
== :: XAutoclaimResult resultFormat
-> XAutoclaimResult resultFormat -> Bool
$c/= :: forall resultFormat.
Eq resultFormat =>
XAutoclaimResult resultFormat
-> XAutoclaimResult resultFormat -> Bool
/= :: XAutoclaimResult resultFormat
-> XAutoclaimResult resultFormat -> Bool
Eq)

instance RedisResult a => RedisResult (XAutoclaimResult a) where
    decode :: Reply -> Either Reply (XAutoclaimResult a)
decode (MultiBulk (Just [
        Bulk (Just ByteString
xAutoclaimResultId) ,
        Reply
claimedMsg,
        Reply
deletedMsg])) = do
            xAutoclaimClaimedMessages <- Reply -> Either Reply [a]
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
claimedMsg
            xAutoclaimDeletedMessages <- decode deletedMsg
            Right XAutoclaimResult{..}
    decode (MultiBulk (Just [
        Bulk (Just ByteString
xAutoclaimResultId) ,
        MultiBulk (Just [])
        ])) = do
            let xAutoclaimClaimedMessages :: [a]
xAutoclaimClaimedMessages = []
            let xAutoclaimDeletedMessages :: [a]
xAutoclaimDeletedMessages = []
            XAutoclaimResult a -> Either Reply (XAutoclaimResult a)
forall a b. b -> Either a b
Right XAutoclaimResult{[a]
[ByteString]
ByteString
forall a. [a]
xAutoclaimResultId :: ByteString
xAutoclaimClaimedMessages :: [a]
xAutoclaimDeletedMessages :: [ByteString]
xAutoclaimResultId :: ByteString
xAutoclaimClaimedMessages :: forall a. [a]
xAutoclaimDeletedMessages :: forall a. [a]
..}
    decode Reply
a = Reply -> Either Reply (XAutoclaimResult a)
forall a b. a -> Either a b
Left Reply
a

-- | Version of the autoclaim result that contains data of the messages.
type XAutoclaimStreamsResult = XAutoclaimResult StreamsRecord
-- | Version of the autoclaim result that contains only IDs.
type XAutoclaimJustIdsResult = XAutoclaimResult ByteString

-- | /O(1)/ Transfers ownership of pending stream entries that match
-- the specified criteria. The message should be pending for more than \<min-idle-time\>
-- milliseconds and ID should be greater than \<start\>.
--
-- @XAUTOCLAIM \<stream name\> \<consumer group name\> \<min idle time\> \<start\>@
--
-- This version of function  claims no more than 100 mesages, use 'xautoclaimOpt' to
-- override this behavior.
--
-- Since Redis 7.0: fails on ealier versions.
xautoclaim
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ Consumer name.
    -> Integer -- ^ Min idle time (ms).
    -> ByteString -- ^ ID of the message to start.
    -> m (f XAutoclaimStreamsResult)
xautoclaim :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Integer
-> ByteString
-> m (f XAutoclaimStreamsResult)
xautoclaim ByteString
key ByteString
group ByteString
consumer Integer
min_idle_time ByteString
start = ByteString
-> ByteString
-> ByteString
-> Integer
-> ByteString
-> XAutoclaimOpts
-> m (f XAutoclaimStreamsResult)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Integer
-> ByteString
-> XAutoclaimOpts
-> m (f XAutoclaimStreamsResult)
xautoclaimOpts ByteString
key ByteString
group ByteString
consumer Integer
min_idle_time ByteString
start XAutoclaimOpts
defaultXAutoclaimOpts

-- | /O(1) if count is small/. Transfers ownership of pending stream entries that match
-- the specified criteria. See 'xautoclaim' for details.
--
-- Allows to pass additional optional parameters to set limit.
--
-- @XAUTOCLAIM \<stream name\> \<consumer group name\> \<min idle time\> \<start\> COUNT \<count\>@
--
-- Since Redis 7.0: fails on the ealier versions.
xautoclaimOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ Consumer name.
    -> Integer -- ^ min idle time (ms).
    -> ByteString -- ^ start ID.
    -> XAutoclaimOpts -- ^ Additional parameters.
    -> m (f XAutoclaimStreamsResult)
xautoclaimOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Integer
-> ByteString
-> XAutoclaimOpts
-> m (f XAutoclaimStreamsResult)
xautoclaimOpts ByteString
key ByteString
group ByteString
consumer Integer
min_idle_time ByteString
start XAutoclaimOpts
opts = [ByteString] -> m (f XAutoclaimStreamsResult)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f XAutoclaimStreamsResult))
-> [ByteString] -> m (f XAutoclaimStreamsResult)
forall a b. (a -> b) -> a -> b
$
    [ByteString
"XAUTOCLAIM", ByteString
key, ByteString
group, ByteString
consumer, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
min_idle_time, ByteString
start] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
count
    where count :: [ByteString]
count  = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] ((ByteString
"COUNT"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:) ([ByteString] -> [ByteString])
-> (Integer -> [ByteString]) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[]) (ByteString -> [ByteString])
-> (Integer -> ByteString) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode) (XAutoclaimOpts -> Maybe Integer
xAutoclaimCount XAutoclaimOpts
opts)

-- | /O(1)/ Transfers ownership of pending stream entries that match
-- the specified criteria. See 'xautoclaim' for more details about criteria.
--
-- This variant returns only id of the messages without data. This method
-- claims no more than 100 messages, see 'xautoclaimJustIdsOpts' for changing
-- this default.
--
-- @XAUTOCLAIM \<stream name\> \<consumer group name\> \<min idle time\> \<start\> JUSTID@
--
-- Since Redis 7.0: fails on the ealier versions.
xautoclaimJustIds
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ Consumer name.
    -> Integer -- ^ Min idle time (ms).
    -> ByteString -- ^ start ID.
    -> m (f XAutoclaimJustIdsResult)
xautoclaimJustIds :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Integer
-> ByteString
-> m (f XAutoclaimJustIdsResult)
xautoclaimJustIds ByteString
key ByteString
group ByteString
consumer Integer
min_idle_time ByteString
start =
  ByteString
-> ByteString
-> ByteString
-> Integer
-> ByteString
-> XAutoclaimOpts
-> m (f XAutoclaimJustIdsResult)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Integer
-> ByteString
-> XAutoclaimOpts
-> m (f XAutoclaimJustIdsResult)
xautoclaimJustIdsOpts ByteString
key ByteString
group ByteString
consumer Integer
min_idle_time ByteString
start XAutoclaimOpts
defaultXAutoclaimOpts

-- | /O(1) if count is small/ Transfers ownership of pending stream entries that match
-- the specified criteria. See 'xautoclaim' for more details about criteria.
--
-- This variant returns only id of the messages without data and allows to set the maximum
-- number of messages to be claimed.
--
-- @XAUTOCLAIM \<stream name\> \<consumer group name\> \<min idle time\> \<start\> COUNT \<count\> JUSTID@
--
-- Since Redis 7.0: fails on the ealier versions.
xautoclaimJustIdsOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumers group name.
    -> ByteString -- ^ Consumer namee.
    -> Integer -- ^ min idle time (ms).
    -> ByteString -- ^ Start ID.
    -> XAutoclaimOpts -- ^ Additional parametres.
    -> m (f XAutoclaimJustIdsResult)
xautoclaimJustIdsOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Integer
-> ByteString
-> XAutoclaimOpts
-> m (f XAutoclaimJustIdsResult)
xautoclaimJustIdsOpts ByteString
key ByteString
group ByteString
consumer Integer
min_idle_time ByteString
start XAutoclaimOpts
opts = [ByteString] -> m (f XAutoclaimJustIdsResult)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f XAutoclaimJustIdsResult))
-> [ByteString] -> m (f XAutoclaimJustIdsResult)
forall a b. (a -> b) -> a -> b
$
    [ByteString
"XAUTOCLAIM", ByteString
key, ByteString
group, ByteString
consumer, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
min_idle_time, ByteString
start] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
count [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"JUSTID"]
    where count :: [ByteString]
count  = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] ((ByteString
"COUNT"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:) ([ByteString] -> [ByteString])
-> (Integer -> [ByteString]) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[]) (ByteString -> [ByteString])
-> (Integer -> ByteString) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode) (XAutoclaimOpts -> Maybe Integer
xAutoclaimCount XAutoclaimOpts
opts)

data StreamsRecord = StreamsRecord
    { StreamsRecord -> ByteString
recordId :: ByteString
    , StreamsRecord -> [(ByteString, ByteString)]
keyValues :: [(ByteString, ByteString)]
    } deriving (Int -> StreamsRecord -> ShowS
[StreamsRecord] -> ShowS
StreamsRecord -> String
(Int -> StreamsRecord -> ShowS)
-> (StreamsRecord -> String)
-> ([StreamsRecord] -> ShowS)
-> Show StreamsRecord
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StreamsRecord -> ShowS
showsPrec :: Int -> StreamsRecord -> ShowS
$cshow :: StreamsRecord -> String
show :: StreamsRecord -> String
$cshowList :: [StreamsRecord] -> ShowS
showList :: [StreamsRecord] -> ShowS
Show, StreamsRecord -> StreamsRecord -> Bool
(StreamsRecord -> StreamsRecord -> Bool)
-> (StreamsRecord -> StreamsRecord -> Bool) -> Eq StreamsRecord
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StreamsRecord -> StreamsRecord -> Bool
== :: StreamsRecord -> StreamsRecord -> Bool
$c/= :: StreamsRecord -> StreamsRecord -> Bool
/= :: StreamsRecord -> StreamsRecord -> Bool
Eq)

instance RedisResult StreamsRecord where
    decode :: Reply -> Either Reply StreamsRecord
decode (MultiBulk (Just [Bulk (Just ByteString
recordId), MultiBulk (Just [Reply]
rawKeyValues)])) = do
        keyValuesList <- (Reply -> Either Reply ByteString)
-> [Reply] -> Either Reply [ByteString]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode [Reply]
rawKeyValues
        let keyValues = [ByteString] -> [(ByteString, ByteString)]
decodeKeyValues [ByteString]
keyValuesList
        return StreamsRecord{..}
        where
            decodeKeyValues :: [ByteString] -> [(ByteString, ByteString)]
            decodeKeyValues :: [ByteString] -> [(ByteString, ByteString)]
decodeKeyValues (ByteString
x:ByteString
y:[ByteString]
rest) = (ByteString
x,ByteString
y)(ByteString, ByteString)
-> [(ByteString, ByteString)] -> [(ByteString, ByteString)]
forall a. a -> [a] -> [a]
:[ByteString] -> [(ByteString, ByteString)]
decodeKeyValues [ByteString]
rest
            decodeKeyValues [ByteString]
_ = []
    decode Reply
a = Reply -> Either Reply StreamsRecord
forall a b. a -> Either a b
Left Reply
a

data XReadOpts = XReadOpts
    { XReadOpts -> Maybe Integer
block :: Maybe Integer
    , XReadOpts -> Maybe Integer
recordCount :: Maybe Integer
    } deriving (Int -> XReadOpts -> ShowS
[XReadOpts] -> ShowS
XReadOpts -> String
(Int -> XReadOpts -> ShowS)
-> (XReadOpts -> String)
-> ([XReadOpts] -> ShowS)
-> Show XReadOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XReadOpts -> ShowS
showsPrec :: Int -> XReadOpts -> ShowS
$cshow :: XReadOpts -> String
show :: XReadOpts -> String
$cshowList :: [XReadOpts] -> ShowS
showList :: [XReadOpts] -> ShowS
Show, XReadOpts -> XReadOpts -> Bool
(XReadOpts -> XReadOpts -> Bool)
-> (XReadOpts -> XReadOpts -> Bool) -> Eq XReadOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XReadOpts -> XReadOpts -> Bool
== :: XReadOpts -> XReadOpts -> Bool
$c/= :: XReadOpts -> XReadOpts -> Bool
/= :: XReadOpts -> XReadOpts -> Bool
Eq)

-- |Redis default 'XReadOpts'. Equivalent to omitting all optional parameters.
--
-- @
-- XReadOpts
--     { block = Nothing -- Don't block waiting for more records
--     , recordCount    = Nothing   -- no record count
--     }
-- @
--
defaultXreadOpts :: XReadOpts
defaultXreadOpts :: XReadOpts
defaultXreadOpts = XReadOpts { block :: Maybe Integer
block = Maybe Integer
forall a. Maybe a
Nothing, recordCount :: Maybe Integer
recordCount = Maybe Integer
forall a. Maybe a
Nothing }

data XReadResponse = XReadResponse
    { XReadResponse -> ByteString
stream :: ByteString
    , XReadResponse -> [StreamsRecord]
records :: [StreamsRecord]
    } deriving (Int -> XReadResponse -> ShowS
[XReadResponse] -> ShowS
XReadResponse -> String
(Int -> XReadResponse -> ShowS)
-> (XReadResponse -> String)
-> ([XReadResponse] -> ShowS)
-> Show XReadResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XReadResponse -> ShowS
showsPrec :: Int -> XReadResponse -> ShowS
$cshow :: XReadResponse -> String
show :: XReadResponse -> String
$cshowList :: [XReadResponse] -> ShowS
showList :: [XReadResponse] -> ShowS
Show, XReadResponse -> XReadResponse -> Bool
(XReadResponse -> XReadResponse -> Bool)
-> (XReadResponse -> XReadResponse -> Bool) -> Eq XReadResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XReadResponse -> XReadResponse -> Bool
== :: XReadResponse -> XReadResponse -> Bool
$c/= :: XReadResponse -> XReadResponse -> Bool
/= :: XReadResponse -> XReadResponse -> Bool
Eq)

instance RedisResult XReadResponse where
    decode :: Reply -> Either Reply XReadResponse
decode (MultiBulk (Just [Bulk (Just ByteString
stream), MultiBulk (Just [Reply]
rawRecords)])) = do
        records <- (Reply -> Either Reply StreamsRecord)
-> [Reply] -> Either Reply [StreamsRecord]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply StreamsRecord
forall a. RedisResult a => Reply -> Either Reply a
decode [Reply]
rawRecords
        return XReadResponse{..}
    decode Reply
a = Reply -> Either Reply XReadResponse
forall a b. a -> Either a b
Left Reply
a

-- |Read values from a stream (<https://redis.io/commands/xread>). The Redis command @XREAD@ is split up into 'xread', 'xreadOpts'. Since Redis 5.0.0
xreadOpts
    :: (RedisCtx m f)
    => [(ByteString, ByteString)] -- ^ (stream, id) pairs
    -> XReadOpts -- ^ Options
    -> m (f (Maybe [XReadResponse]))
xreadOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
[(ByteString, ByteString)]
-> XReadOpts -> m (f (Maybe [XReadResponse]))
xreadOpts [(ByteString, ByteString)]
streamsAndIds XReadOpts
opts = [ByteString] -> m (f (Maybe [XReadResponse]))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe [XReadResponse])))
-> [ByteString] -> m (f (Maybe [XReadResponse]))
forall a b. (a -> b) -> a -> b
$
    [ByteString
"XREAD"] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ([(ByteString, ByteString)] -> XReadOpts -> [ByteString]
internalXreadArgs [(ByteString, ByteString)]
streamsAndIds XReadOpts
opts)

internalXreadArgs :: [(ByteString, ByteString)] -> XReadOpts -> [ByteString]
internalXreadArgs :: [(ByteString, ByteString)] -> XReadOpts -> [ByteString]
internalXreadArgs [(ByteString, ByteString)]
streamsAndIds XReadOpts{Maybe Integer
block :: XReadOpts -> Maybe Integer
recordCount :: XReadOpts -> Maybe Integer
block :: Maybe Integer
recordCount :: Maybe Integer
..} =
    [[ByteString]] -> [ByteString]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ByteString]
blockArgs, [ByteString]
countArgs, [ByteString
"STREAMS"], [ByteString]
streams, [ByteString]
recordIds]
    where
        blockArgs :: [ByteString]
blockArgs = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
blockMillis -> [ByteString
"BLOCK", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
blockMillis]) Maybe Integer
block
        countArgs :: [ByteString]
countArgs = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
countRecords -> [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
countRecords]) Maybe Integer
recordCount
        streams :: [ByteString]
streams = ((ByteString, ByteString) -> ByteString)
-> [(ByteString, ByteString)] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map (\(ByteString
stream, ByteString
_) -> ByteString
stream) [(ByteString, ByteString)]
streamsAndIds
        recordIds :: [ByteString]
recordIds = ((ByteString, ByteString) -> ByteString)
-> [(ByteString, ByteString)] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map (\(ByteString
_, ByteString
recordId) -> ByteString
recordId) [(ByteString, ByteString)]
streamsAndIds

-- |Read values from a stream (<https://redis.io/commands/xread>).
-- The Redis command @XREAD@ is split up into 'xread', 'xreadOpts'.
-- Since Redis 5.0.0
xread
    :: (RedisCtx m f)
    => [(ByteString, ByteString)] -- ^ (stream, id) pairs
    -> m( f (Maybe [XReadResponse]))
xread :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
[(ByteString, ByteString)] -> m (f (Maybe [XReadResponse]))
xread [(ByteString, ByteString)]
streamsAndIds = [(ByteString, ByteString)]
-> XReadOpts -> m (f (Maybe [XReadResponse]))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
[(ByteString, ByteString)]
-> XReadOpts -> m (f (Maybe [XReadResponse]))
xreadOpts [(ByteString, ByteString)]
streamsAndIds XReadOpts
defaultXreadOpts

data XReadGroupOpts = XReadGroupOpts
    { XReadGroupOpts -> Maybe Integer
xReadGroupBlock :: Maybe Integer
    , XReadGroupOpts -> Maybe Integer
xReadGroupCount :: Maybe Integer
    , XReadGroupOpts -> Bool
xReadGroupNoAck :: Bool
    } deriving (Int -> XReadGroupOpts -> ShowS
[XReadGroupOpts] -> ShowS
XReadGroupOpts -> String
(Int -> XReadGroupOpts -> ShowS)
-> (XReadGroupOpts -> String)
-> ([XReadGroupOpts] -> ShowS)
-> Show XReadGroupOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XReadGroupOpts -> ShowS
showsPrec :: Int -> XReadGroupOpts -> ShowS
$cshow :: XReadGroupOpts -> String
show :: XReadGroupOpts -> String
$cshowList :: [XReadGroupOpts] -> ShowS
showList :: [XReadGroupOpts] -> ShowS
Show, XReadGroupOpts -> XReadGroupOpts -> Bool
(XReadGroupOpts -> XReadGroupOpts -> Bool)
-> (XReadGroupOpts -> XReadGroupOpts -> Bool) -> Eq XReadGroupOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XReadGroupOpts -> XReadGroupOpts -> Bool
== :: XReadGroupOpts -> XReadGroupOpts -> Bool
$c/= :: XReadGroupOpts -> XReadGroupOpts -> Bool
/= :: XReadGroupOpts -> XReadGroupOpts -> Bool
Eq)

defaultXReadGroupOpts :: XReadGroupOpts
defaultXReadGroupOpts :: XReadGroupOpts
defaultXReadGroupOpts = XReadGroupOpts
    { xReadGroupBlock :: Maybe Integer
xReadGroupBlock = Maybe Integer
forall a. Maybe a
Nothing
    , xReadGroupCount :: Maybe Integer
xReadGroupCount = Maybe Integer
forall a. Maybe a
Nothing
    , xReadGroupNoAck :: Bool
xReadGroupNoAck = Bool
False
    }

xreadGroupOpts
    :: (RedisCtx m f)
    => ByteString -- ^ group name
    -> ByteString -- ^ consumer name
    -> [(ByteString, ByteString)] -- ^ (stream, id) pairs
    -> XReadGroupOpts -- ^ Options
    -> m (f (Maybe [XReadResponse]))
xreadGroupOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [(ByteString, ByteString)]
-> XReadGroupOpts
-> m (f (Maybe [XReadResponse]))
xreadGroupOpts ByteString
groupName ByteString
consumerName [(ByteString, ByteString)]
streamsAndIds XReadGroupOpts{Bool
Maybe Integer
xReadGroupBlock :: XReadGroupOpts -> Maybe Integer
xReadGroupCount :: XReadGroupOpts -> Maybe Integer
xReadGroupNoAck :: XReadGroupOpts -> Bool
xReadGroupBlock :: Maybe Integer
xReadGroupCount :: Maybe Integer
xReadGroupNoAck :: Bool
..} = [ByteString] -> m (f (Maybe [XReadResponse]))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe [XReadResponse])))
-> [ByteString] -> m (f (Maybe [XReadResponse]))
forall a b. (a -> b) -> a -> b
$
    [ByteString
"XREADGROUP", ByteString
"GROUP", ByteString
groupName, ByteString
consumerName] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
internalXreadGroupArgs
    where
        internalXreadGroupArgs :: [ByteString]
internalXreadGroupArgs = [[ByteString]] -> [ByteString]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[ByteString]
countArgs, [ByteString]
blockArgs, [ByteString]
noAckArgs, [ByteString
"STREAMS"], [ByteString]
streams, [ByteString]
recordIds]
        blockArgs :: [ByteString]
blockArgs = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
blockMillis -> [ByteString
"BLOCK", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
blockMillis]) Maybe Integer
xReadGroupBlock
        countArgs :: [ByteString]
countArgs = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
countRecords -> [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
countRecords]) Maybe Integer
xReadGroupCount
        noAckArgs :: [ByteString]
noAckArgs = [ByteString
"NOACK" | Bool
xReadGroupNoAck]
        streams :: [ByteString]
streams = ((ByteString, ByteString) -> ByteString)
-> [(ByteString, ByteString)] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map (\(ByteString
stream, ByteString
_) -> ByteString
stream) [(ByteString, ByteString)]
streamsAndIds
        recordIds :: [ByteString]
recordIds = ((ByteString, ByteString) -> ByteString)
-> [(ByteString, ByteString)] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map (\(ByteString
_, ByteString
recordId) -> ByteString
recordId) [(ByteString, ByteString)]
streamsAndIds

xreadGroup
    :: (RedisCtx m f)
    => ByteString -- ^ group name
    -> ByteString -- ^ consumer name
    -> [(ByteString, ByteString)] -- ^ (stream, id) pairs
    -> m (f (Maybe [XReadResponse]))
xreadGroup :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [(ByteString, ByteString)]
-> m (f (Maybe [XReadResponse]))
xreadGroup ByteString
groupName ByteString
consumerName [(ByteString, ByteString)]
streamsAndIds = ByteString
-> ByteString
-> [(ByteString, ByteString)]
-> XReadGroupOpts
-> m (f (Maybe [XReadResponse]))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> [(ByteString, ByteString)]
-> XReadGroupOpts
-> m (f (Maybe [XReadResponse]))
xreadGroupOpts ByteString
groupName ByteString
consumerName [(ByteString, ByteString)]
streamsAndIds XReadGroupOpts
defaultXReadGroupOpts

-- | Additional parameters of the XGroupCreate
data XGroupCreateOpts = XGroupCreateOpts
    { XGroupCreateOpts -> Bool
xGroupCreateMkStream :: Bool -- ^ If a stream does not exist, create it automatically with length of 0
    , XGroupCreateOpts -> Maybe ByteString
xGroupCreateEntriesRead :: Maybe ByteString
    {- ^ Enable consumer group lag tracking, specify an arbitrary ID.
     An arbitrary ID is any ID that isn't the ID of the stream's first entry,
     last entry, or zero (@"0-0"@) ID. Use it to find out how many entries
     are between the arbitrary ID (excluding it) and the stream's last entry.

     Since Redis 7.0, fails if set on the ealier versions.
    -}
    } deriving (Int -> XGroupCreateOpts -> ShowS
[XGroupCreateOpts] -> ShowS
XGroupCreateOpts -> String
(Int -> XGroupCreateOpts -> ShowS)
-> (XGroupCreateOpts -> String)
-> ([XGroupCreateOpts] -> ShowS)
-> Show XGroupCreateOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XGroupCreateOpts -> ShowS
showsPrec :: Int -> XGroupCreateOpts -> ShowS
$cshow :: XGroupCreateOpts -> String
show :: XGroupCreateOpts -> String
$cshowList :: [XGroupCreateOpts] -> ShowS
showList :: [XGroupCreateOpts] -> ShowS
Show, XGroupCreateOpts -> XGroupCreateOpts -> Bool
(XGroupCreateOpts -> XGroupCreateOpts -> Bool)
-> (XGroupCreateOpts -> XGroupCreateOpts -> Bool)
-> Eq XGroupCreateOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XGroupCreateOpts -> XGroupCreateOpts -> Bool
== :: XGroupCreateOpts -> XGroupCreateOpts -> Bool
$c/= :: XGroupCreateOpts -> XGroupCreateOpts -> Bool
/= :: XGroupCreateOpts -> XGroupCreateOpts -> Bool
Eq)

-- | Specifies default group opts.
--
-- Prefer using this method over use of constructor to preserve backwards compatibility.
defaultXGroupCreateOpts :: XGroupCreateOpts
defaultXGroupCreateOpts :: XGroupCreateOpts
defaultXGroupCreateOpts = XGroupCreateOpts{
    xGroupCreateEntriesRead :: Maybe ByteString
xGroupCreateEntriesRead = Maybe ByteString
forall a. Maybe a
Nothing,
    xGroupCreateMkStream :: Bool
xGroupCreateMkStream = Bool
False
}

-- | /O(1)/ Creates consumer group.
--
-- Fails if called on with the stream name that does not exist, use 'xgroupCreateOpts'
-- to override this behavior.
xgroupCreate
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ ID of the message to start reading with.
    -> m (f Status)
xgroupCreate :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Status)
xgroupCreate ByteString
stream ByteString
groupName ByteString
startId = ByteString
-> ByteString -> ByteString -> XGroupCreateOpts -> m (f Status)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> XGroupCreateOpts -> m (f Status)
xgroupCreateOpts ByteString
stream ByteString
groupName ByteString
startId XGroupCreateOpts
defaultXGroupCreateOpts

-- | /O(1)/ Creates consumer group, accepts additional parameters.
xgroupCreateOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ ID of the message to start reading with.
    -> XGroupCreateOpts -- ^ Additional parameters.
    -> m (f Status)
xgroupCreateOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> XGroupCreateOpts -> m (f Status)
xgroupCreateOpts ByteString
stream ByteString
groupName ByteString
startId XGroupCreateOpts
opts = [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
"XGROUP", ByteString
"CREATE", ByteString
stream, ByteString
groupName, ByteString
startId] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
args
    where args :: [ByteString]
args = [ByteString]
mkstream [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
entriesRead
          mkstream :: [ByteString]
mkstream    = [ByteString
"MKSTREAM" | XGroupCreateOpts -> Bool
xGroupCreateMkStream XGroupCreateOpts
opts]
          entriesRead :: [ByteString]
entriesRead = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe []  ((ByteString
"ENTRIESREAD"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:) ([ByteString] -> [ByteString])
-> (ByteString -> [ByteString]) -> ByteString -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[])) (XGroupCreateOpts -> Maybe ByteString
xGroupCreateEntriesRead XGroupCreateOpts
opts)

-- | /O(1)/ Creates new consumer in the consumers group.
--
-- Since redis 6.2.0: fails on the ealier versions.
xgroupCreateConsumer
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ Consumer name.
    -> m (f Bool) -- ^ Returns if the consumer was created or not.
xgroupCreateConsumer :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Bool)
xgroupCreateConsumer ByteString
key ByteString
group ByteString
consumer = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"XGROUP", ByteString
"CREATECONSUMER", ByteString
key, ByteString
group, ByteString
consumer]

-- | /O(1)/ Sets last delivered id for a consumer group.
xgroupSetId
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumr group name.
    -> ByteString -- ^ Message ID or @$@
    -> m (f Status)
xgroupSetId :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Status)
xgroupSetId ByteString
stream ByteString
group ByteString
messageId = ByteString
-> ByteString -> ByteString -> XGroupSetIdOpts -> m (f Status)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> XGroupSetIdOpts -> m (f Status)
xgroupSetIdOpts ByteString
stream ByteString
group ByteString
messageId XGroupSetIdOpts
defaultXGroupSetIdOpts

-- | Additional parameters for the 'xgroupSetId' method
newtype XGroupSetIdOpts = XGroupSetIdOpts {
    XGroupSetIdOpts -> Maybe ByteString
xGroupSetIdEntriesRead :: Maybe ByteString
    {- ^ Enable consumer group lag tracking for an arbitrary ID. An arbitrary ID is any ID that isn't the ID of the stream's first entry, its last entry or the zero (@"0-0"@) ID

    @since Redis 7.0, fails if set to Just on ealier versions.
    -}
}

-- | Default value for the 'XGroupSetIdOpts'.
--
-- Prefer use this method over the raw constructor in order to preserve
-- backwards compatibility.
defaultXGroupSetIdOpts :: XGroupSetIdOpts
defaultXGroupSetIdOpts :: XGroupSetIdOpts
defaultXGroupSetIdOpts = XGroupSetIdOpts {xGroupSetIdEntriesRead :: Maybe ByteString
xGroupSetIdEntriesRead = Maybe ByteString
forall a. Maybe a
Nothing}

-- | /O(1)/ a variant of the 'xgroupSetId' that allowes to pass additional parameters.
xgroupSetIdOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ Message id or @$S
    -> XGroupSetIdOpts -- ^ Additional parameters.
    -> m (f Status)
xgroupSetIdOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> XGroupSetIdOpts -> m (f Status)
xgroupSetIdOpts ByteString
stream ByteString
group ByteString
messageId XGroupSetIdOpts
opts = [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
"XGROUP", ByteString
"SETID", ByteString
stream, ByteString
group, ByteString
messageId] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
entriesRead
    where entriesRead :: [ByteString]
entriesRead = [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] ((ByteString
"ENTRIESREAD"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:) ([ByteString] -> [ByteString])
-> (ByteString -> [ByteString]) -> ByteString -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[])) (XGroupSetIdOpts -> Maybe ByteString
xGroupSetIdEntriesRead XGroupSetIdOpts
opts)

-- | /O(1)/ Delete consumer.
xgroupDelConsumer
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ Consumer name.
    -> m (f Integer) -- ^ The number of pending messages owned by the consumer.
xgroupDelConsumer :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> ByteString -> m (f Integer)
xgroupDelConsumer ByteString
stream ByteString
group ByteString
consumer = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"XGROUP", ByteString
"DELCONSUMER", ByteString
stream, ByteString
group, ByteString
consumer]

-- | /O(1)/ destroys a group.
xgroupDestroy
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> m (f Bool)  -- ^ Tells if the group was destroyed or not.
xgroupDestroy :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f Bool)
xgroupDestroy ByteString
stream ByteString
group = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"XGROUP", ByteString
"DESTROY", ByteString
stream, ByteString
group]

data XRefPolicy
    = XRefPolicyKeepRef -- ^ Deletes the specified entries from the stream, but preserves existing references to these entries in all consumer groups
    | XRefPolicyDelRef -- ^ Deletes the specified entries from the stream and also removes all references to these entries from all consumer groups' pending entry lists, effectively cleaning up all traces of the messages. If an entry ID is not in the stream, but there are dangling references, XDELEX with DELREF would still remove all those references.
    | XRefPolicyAcked -- ^ Deletes the specified entries from the stream only if they have been acknowledged by all consumer groups.
    deriving (Int -> XRefPolicy -> ShowS
[XRefPolicy] -> ShowS
XRefPolicy -> String
(Int -> XRefPolicy -> ShowS)
-> (XRefPolicy -> String)
-> ([XRefPolicy] -> ShowS)
-> Show XRefPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XRefPolicy -> ShowS
showsPrec :: Int -> XRefPolicy -> ShowS
$cshow :: XRefPolicy -> String
show :: XRefPolicy -> String
$cshowList :: [XRefPolicy] -> ShowS
showList :: [XRefPolicy] -> ShowS
Show, XRefPolicy -> XRefPolicy -> Bool
(XRefPolicy -> XRefPolicy -> Bool)
-> (XRefPolicy -> XRefPolicy -> Bool) -> Eq XRefPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XRefPolicy -> XRefPolicy -> Bool
== :: XRefPolicy -> XRefPolicy -> Bool
$c/= :: XRefPolicy -> XRefPolicy -> Bool
/= :: XRefPolicy -> XRefPolicy -> Bool
Eq)

instance RedisArg XRefPolicy where
    encode :: XRefPolicy -> ByteString
encode XRefPolicy
XRefPolicyKeepRef = ByteString
"KEEPREF"
    encode XRefPolicy
XRefPolicyDelRef = ByteString
"DELREF"
    encode XRefPolicy
XRefPolicyAcked = ByteString
"ACKED"

data XEntryDeletionOpts = XEntryDeletionOpts
    { XEntryDeletionOpts -> XRefPolicy
xEntryDeletionRefPolicy :: XRefPolicy
    } deriving (Int -> XEntryDeletionOpts -> ShowS
[XEntryDeletionOpts] -> ShowS
XEntryDeletionOpts -> String
(Int -> XEntryDeletionOpts -> ShowS)
-> (XEntryDeletionOpts -> String)
-> ([XEntryDeletionOpts] -> ShowS)
-> Show XEntryDeletionOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XEntryDeletionOpts -> ShowS
showsPrec :: Int -> XEntryDeletionOpts -> ShowS
$cshow :: XEntryDeletionOpts -> String
show :: XEntryDeletionOpts -> String
$cshowList :: [XEntryDeletionOpts] -> ShowS
showList :: [XEntryDeletionOpts] -> ShowS
Show, XEntryDeletionOpts -> XEntryDeletionOpts -> Bool
(XEntryDeletionOpts -> XEntryDeletionOpts -> Bool)
-> (XEntryDeletionOpts -> XEntryDeletionOpts -> Bool)
-> Eq XEntryDeletionOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XEntryDeletionOpts -> XEntryDeletionOpts -> Bool
== :: XEntryDeletionOpts -> XEntryDeletionOpts -> Bool
$c/= :: XEntryDeletionOpts -> XEntryDeletionOpts -> Bool
/= :: XEntryDeletionOpts -> XEntryDeletionOpts -> Bool
Eq)

defaultXEntryDeletionOpts :: XEntryDeletionOpts
defaultXEntryDeletionOpts :: XEntryDeletionOpts
defaultXEntryDeletionOpts = XEntryDeletionOpts
    { xEntryDeletionRefPolicy :: XRefPolicy
xEntryDeletionRefPolicy = XRefPolicy
XRefPolicyKeepRef
    }

data XCfgSetOpts = XCfgSetOpts
    { XCfgSetOpts -> Maybe Integer
xCfgSetIdmpDuration :: Maybe Integer
      -- ^ The duration in seconds that each idempotent ID is retained.
    , XCfgSetOpts -> Maybe Integer
xCfgSetIdmpMaxsize :: Maybe Integer
      -- ^ The maximum number of idempotent IDs tracked per producer.
    } deriving (Int -> XCfgSetOpts -> ShowS
[XCfgSetOpts] -> ShowS
XCfgSetOpts -> String
(Int -> XCfgSetOpts -> ShowS)
-> (XCfgSetOpts -> String)
-> ([XCfgSetOpts] -> ShowS)
-> Show XCfgSetOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XCfgSetOpts -> ShowS
showsPrec :: Int -> XCfgSetOpts -> ShowS
$cshow :: XCfgSetOpts -> String
show :: XCfgSetOpts -> String
$cshowList :: [XCfgSetOpts] -> ShowS
showList :: [XCfgSetOpts] -> ShowS
Show, XCfgSetOpts -> XCfgSetOpts -> Bool
(XCfgSetOpts -> XCfgSetOpts -> Bool)
-> (XCfgSetOpts -> XCfgSetOpts -> Bool) -> Eq XCfgSetOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XCfgSetOpts -> XCfgSetOpts -> Bool
== :: XCfgSetOpts -> XCfgSetOpts -> Bool
$c/= :: XCfgSetOpts -> XCfgSetOpts -> Bool
/= :: XCfgSetOpts -> XCfgSetOpts -> Bool
Eq)

-- |Redis default 'XCfgSetOpts'. Equivalent to omitting all optional parameters.
--
-- At least one field must be set before calling 'xcfgset'.
defaultXCfgSetOpts :: XCfgSetOpts
defaultXCfgSetOpts :: XCfgSetOpts
defaultXCfgSetOpts = XCfgSetOpts
    { xCfgSetIdmpDuration :: Maybe Integer
xCfgSetIdmpDuration = Maybe Integer
forall a. Maybe a
Nothing
    , xCfgSetIdmpMaxsize :: Maybe Integer
xCfgSetIdmpMaxsize = Maybe Integer
forall a. Maybe a
Nothing
    }

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

instance RedisArg XNackMode where
    encode :: XNackMode -> ByteString
encode XNackMode
XNackSilent = ByteString
"SILENT"
    encode XNackMode
XNackFail = ByteString
"FAIL"
    encode XNackMode
XNackFatal = ByteString
"FATAL"

data XNackOpts = XNackOpts
    { XNackOpts -> Maybe Integer
xNackRetryCount :: Maybe Integer
    , XNackOpts -> Bool
xNackForce :: Bool
    } deriving (Int -> XNackOpts -> ShowS
[XNackOpts] -> ShowS
XNackOpts -> String
(Int -> XNackOpts -> ShowS)
-> (XNackOpts -> String)
-> ([XNackOpts] -> ShowS)
-> Show XNackOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XNackOpts -> ShowS
showsPrec :: Int -> XNackOpts -> ShowS
$cshow :: XNackOpts -> String
show :: XNackOpts -> String
$cshowList :: [XNackOpts] -> ShowS
showList :: [XNackOpts] -> ShowS
Show, XNackOpts -> XNackOpts -> Bool
(XNackOpts -> XNackOpts -> Bool)
-> (XNackOpts -> XNackOpts -> Bool) -> Eq XNackOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XNackOpts -> XNackOpts -> Bool
== :: XNackOpts -> XNackOpts -> Bool
$c/= :: XNackOpts -> XNackOpts -> Bool
/= :: XNackOpts -> XNackOpts -> Bool
Eq)

-- |Redis default 'XNackOpts'. Equivalent to omitting all optional parameters.
defaultXNackOpts :: XNackOpts
defaultXNackOpts :: XNackOpts
defaultXNackOpts = XNackOpts
    { xNackRetryCount :: Maybe Integer
xNackRetryCount = Maybe Integer
forall a. Maybe a
Nothing
    , xNackForce :: Bool
xNackForce = Bool
False
    }

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

instance RedisResult XEntryDeletionResult where
    decode :: Reply -> Either Reply XEntryDeletionResult
decode Reply
r = do
        result <- Reply -> Either Reply Integer
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
r :: Either Reply Integer
        case result of
            -1 -> XEntryDeletionResult -> Either Reply XEntryDeletionResult
forall a b. b -> Either a b
Right XEntryDeletionResult
XEntryDeletionResultNotFound
            Integer
1 -> XEntryDeletionResult -> Either Reply XEntryDeletionResult
forall a b. b -> Either a b
Right XEntryDeletionResult
XEntryDeletionResultDeleted
            Integer
2 -> XEntryDeletionResult -> Either Reply XEntryDeletionResult
forall a b. b -> Either a b
Right XEntryDeletionResult
XEntryDeletionResultNotDeleted
            Integer
_ -> Reply -> Either Reply XEntryDeletionResult
forall a b. a -> Either a b
Left Reply
r

xEntryDeletionOptsToArgs :: XEntryDeletionOpts -> [ByteString]
xEntryDeletionOptsToArgs :: XEntryDeletionOpts -> [ByteString]
xEntryDeletionOptsToArgs XEntryDeletionOpts{XRefPolicy
xEntryDeletionRefPolicy :: XEntryDeletionOpts -> XRefPolicy
xEntryDeletionRefPolicy :: XRefPolicy
..} =
    [XRefPolicy -> ByteString
forall a. RedisArg a => a -> ByteString
encode XRefPolicy
xEntryDeletionRefPolicy]

xEntryIdsBlockArgs :: NonEmpty ByteString -> [ByteString]
xEntryIdsBlockArgs :: NonEmpty ByteString -> [ByteString]
xEntryIdsBlockArgs NonEmpty ByteString
messageIds =
    [ByteString
"IDS", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty ByteString -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty ByteString
messageIds)] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ByteString
messageIds

xack
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> ByteString -- ^ group name
    -> [ByteString] -- ^ message IDs
    -> m (f Integer)
xack :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> [ByteString] -> m (f Integer)
xack ByteString
stream ByteString
groupName [ByteString]
messageIds = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"XACK", ByteString
stream, ByteString
groupName] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
messageIds

-- |Acknowledges and conditionally deletes entries for a consumer group (<https://redis.io/commands/xackdel>).
--
-- /O(1)/ for each entry ID processed.
--
-- Since Redis 8.2.0
xackdel
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> NonEmpty ByteString -- ^ Entry IDs.
    -> m (f [XEntryDeletionResult])
xackdel :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> NonEmpty ByteString
-> m (f [XEntryDeletionResult])
xackdel ByteString
stream ByteString
groupName NonEmpty ByteString
messageIds =
    ByteString
-> ByteString
-> NonEmpty ByteString
-> XEntryDeletionOpts
-> m (f [XEntryDeletionResult])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> NonEmpty ByteString
-> XEntryDeletionOpts
-> m (f [XEntryDeletionResult])
xackdelOpts ByteString
stream ByteString
groupName NonEmpty ByteString
messageIds XEntryDeletionOpts
defaultXEntryDeletionOpts

-- |Acknowledges and conditionally deletes entries for a consumer group (<https://redis.io/commands/xackdel>).
--
-- /O(1)/ for each entry ID processed.
--
-- Since Redis 8.2.0
xackdelOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> NonEmpty ByteString -- ^ Entry IDs.
    -> XEntryDeletionOpts -- ^ Additional options.
    -> m (f [XEntryDeletionResult])
xackdelOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> NonEmpty ByteString
-> XEntryDeletionOpts
-> m (f [XEntryDeletionResult])
xackdelOpts ByteString
stream ByteString
groupName NonEmpty ByteString
messageIds XEntryDeletionOpts
opts =
    [ByteString] -> m (f [XEntryDeletionResult])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [XEntryDeletionResult]))
-> [ByteString] -> m (f [XEntryDeletionResult])
forall a b. (a -> b) -> a -> b
$ [ByteString
"XACKDEL", ByteString
stream, ByteString
groupName]
        [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ XEntryDeletionOpts -> [ByteString]
xEntryDeletionOptsToArgs XEntryDeletionOpts
opts
        [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
xEntryIdsBlockArgs NonEmpty ByteString
messageIds

xrange
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> ByteString -- ^ start
    -> ByteString -- ^ end
    -> Maybe Integer -- ^ COUNT
    -> m (f [StreamsRecord])
xrange :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Maybe Integer
-> m (f [StreamsRecord])
xrange ByteString
stream ByteString
start ByteString
end Maybe Integer
count = [ByteString] -> m (f [StreamsRecord])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [StreamsRecord]))
-> [ByteString] -> m (f [StreamsRecord])
forall a b. (a -> b) -> a -> b
$ [ByteString
"XRANGE", ByteString
stream, ByteString
start, ByteString
end] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
countArgs
    where countArgs :: [ByteString]
countArgs = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
c -> [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
c]) Maybe Integer
count

xrevRange
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> ByteString -- ^ end
    -> ByteString -- ^ start
    -> Maybe Integer -- ^ COUNT
    -> m (f [StreamsRecord])
xrevRange :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Maybe Integer
-> m (f [StreamsRecord])
xrevRange ByteString
stream ByteString
end ByteString
start Maybe Integer
count = [ByteString] -> m (f [StreamsRecord])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [StreamsRecord]))
-> [ByteString] -> m (f [StreamsRecord])
forall a b. (a -> b) -> a -> b
$ [ByteString
"XREVRANGE", ByteString
stream, ByteString
end, ByteString
start] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
countArgs
    where countArgs :: [ByteString]
countArgs = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
c -> [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
c]) Maybe Integer
count

xlen
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> m (f Integer)
xlen :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
xlen ByteString
stream = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"XLEN", ByteString
stream]

data XPendingSummaryResponse = XPendingSummaryResponse
    { XPendingSummaryResponse -> Integer
numPendingMessages :: Integer
    , XPendingSummaryResponse -> ByteString
smallestPendingMessageId :: ByteString
    , XPendingSummaryResponse -> ByteString
largestPendingMessageId :: ByteString
    , XPendingSummaryResponse -> [(ByteString, Integer)]
numPendingMessagesByconsumer :: [(ByteString, Integer)]
    } deriving (Int -> XPendingSummaryResponse -> ShowS
[XPendingSummaryResponse] -> ShowS
XPendingSummaryResponse -> String
(Int -> XPendingSummaryResponse -> ShowS)
-> (XPendingSummaryResponse -> String)
-> ([XPendingSummaryResponse] -> ShowS)
-> Show XPendingSummaryResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XPendingSummaryResponse -> ShowS
showsPrec :: Int -> XPendingSummaryResponse -> ShowS
$cshow :: XPendingSummaryResponse -> String
show :: XPendingSummaryResponse -> String
$cshowList :: [XPendingSummaryResponse] -> ShowS
showList :: [XPendingSummaryResponse] -> ShowS
Show, XPendingSummaryResponse -> XPendingSummaryResponse -> Bool
(XPendingSummaryResponse -> XPendingSummaryResponse -> Bool)
-> (XPendingSummaryResponse -> XPendingSummaryResponse -> Bool)
-> Eq XPendingSummaryResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XPendingSummaryResponse -> XPendingSummaryResponse -> Bool
== :: XPendingSummaryResponse -> XPendingSummaryResponse -> Bool
$c/= :: XPendingSummaryResponse -> XPendingSummaryResponse -> Bool
/= :: XPendingSummaryResponse -> XPendingSummaryResponse -> Bool
Eq)

instance RedisResult XPendingSummaryResponse where
    decode :: Reply -> Either Reply XPendingSummaryResponse
decode (MultiBulk (Just [
        Integer Integer
numPendingMessages,
        Bulk (Just ByteString
smallestPendingMessageId),
        Bulk (Just ByteString
largestPendingMessageId),
        MultiBulk (Just [MultiBulk (Just [Reply]
rawGroupsAndCounts)])])) = do
            let groupsAndCounts :: [(Reply, Reply)]
groupsAndCounts = [Reply] -> [(Reply, Reply)]
forall {b}. [b] -> [(b, b)]
chunksOfTwo [Reply]
rawGroupsAndCounts
            numPendingMessagesByconsumer <- [(Reply, Reply)] -> Either Reply [(ByteString, Integer)]
decodeGroupsAndCounts [(Reply, Reply)]
groupsAndCounts
            return XPendingSummaryResponse{..}
            where
                decodeGroupsAndCounts :: [(Reply, Reply)] -> Either Reply [(ByteString, Integer)]
                decodeGroupsAndCounts :: [(Reply, Reply)] -> Either Reply [(ByteString, Integer)]
decodeGroupsAndCounts [(Reply, Reply)]
bs = [Either Reply (ByteString, Integer)]
-> Either Reply [(ByteString, Integer)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([Either Reply (ByteString, Integer)]
 -> Either Reply [(ByteString, Integer)])
-> [Either Reply (ByteString, Integer)]
-> Either Reply [(ByteString, Integer)]
forall a b. (a -> b) -> a -> b
$ ((Reply, Reply) -> Either Reply (ByteString, Integer))
-> [(Reply, Reply)] -> [Either Reply (ByteString, Integer)]
forall a b. (a -> b) -> [a] -> [b]
map (Reply, Reply) -> Either Reply (ByteString, Integer)
decodeGroupCount [(Reply, Reply)]
bs
                decodeGroupCount :: (Reply, Reply) -> Either Reply (ByteString, Integer)
                decodeGroupCount :: (Reply, Reply) -> Either Reply (ByteString, Integer)
decodeGroupCount (Reply
x, Reply
y) = do
                    decodedX <- Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
x
                    decodedY <- decode y
                    return (decodedX, decodedY)
                chunksOfTwo :: [b] -> [(b, b)]
chunksOfTwo (b
x:b
y:[b]
rest) = (b
x,b
y)(b, b) -> [(b, b)] -> [(b, b)]
forall a. a -> [a] -> [a]
:[b] -> [(b, b)]
chunksOfTwo [b]
rest
                chunksOfTwo [b]
_ = []
    decode Reply
a = Reply -> Either Reply XPendingSummaryResponse
forall a b. a -> Either a b
Left Reply
a

-- | /O(N)/ N - number of message beign returned.
--
-- Get information about pending messages (https://redis.io/commands/xpending).
--
-- Since Redis 5.0.
xpendingSummary
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Stream consumer group.
    -> m (f XPendingSummaryResponse)
xpendingSummary :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f XPendingSummaryResponse)
xpendingSummary ByteString
stream ByteString
group = [ByteString] -> m (f XPendingSummaryResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f XPendingSummaryResponse))
-> [ByteString] -> m (f XPendingSummaryResponse)
forall a b. (a -> b) -> a -> b
$ [ByteString
"XPENDING", ByteString
stream, ByteString
group]

-- | Details about message returned by the 'xpendingDetails'
data XPendingDetailRecord = XPendingDetailRecord
    { XPendingDetailRecord -> ByteString
messageId :: ByteString
    , XPendingDetailRecord -> ByteString
consumer :: ByteString
    , XPendingDetailRecord -> Integer
millisSinceLastDelivered :: Integer
    , XPendingDetailRecord -> Integer
numTimesDelivered :: Integer
    } deriving (Int -> XPendingDetailRecord -> ShowS
[XPendingDetailRecord] -> ShowS
XPendingDetailRecord -> String
(Int -> XPendingDetailRecord -> ShowS)
-> (XPendingDetailRecord -> String)
-> ([XPendingDetailRecord] -> ShowS)
-> Show XPendingDetailRecord
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XPendingDetailRecord -> ShowS
showsPrec :: Int -> XPendingDetailRecord -> ShowS
$cshow :: XPendingDetailRecord -> String
show :: XPendingDetailRecord -> String
$cshowList :: [XPendingDetailRecord] -> ShowS
showList :: [XPendingDetailRecord] -> ShowS
Show, XPendingDetailRecord -> XPendingDetailRecord -> Bool
(XPendingDetailRecord -> XPendingDetailRecord -> Bool)
-> (XPendingDetailRecord -> XPendingDetailRecord -> Bool)
-> Eq XPendingDetailRecord
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XPendingDetailRecord -> XPendingDetailRecord -> Bool
== :: XPendingDetailRecord -> XPendingDetailRecord -> Bool
$c/= :: XPendingDetailRecord -> XPendingDetailRecord -> Bool
/= :: XPendingDetailRecord -> XPendingDetailRecord -> Bool
Eq)

instance RedisResult XPendingDetailRecord where
    decode :: Reply -> Either Reply XPendingDetailRecord
decode (MultiBulk (Just [
        Bulk (Just ByteString
messageId) ,
        Bulk (Just ByteString
consumer),
        Integer Integer
millisSinceLastDelivered,
        Integer Integer
numTimesDelivered])) = XPendingDetailRecord -> Either Reply XPendingDetailRecord
forall a b. b -> Either a b
Right XPendingDetailRecord{Integer
ByteString
messageId :: ByteString
consumer :: ByteString
millisSinceLastDelivered :: Integer
numTimesDelivered :: Integer
messageId :: ByteString
consumer :: ByteString
millisSinceLastDelivered :: Integer
numTimesDelivered :: Integer
..}
    decode Reply
a = Reply -> Either Reply XPendingDetailRecord
forall a b. a -> Either a b
Left Reply
a

-- | Additional parameters of the xpending call family
data XPendingDetailOpts = XPendingDetailOpts
  {
    XPendingDetailOpts -> Maybe ByteString
xPendingDetailConsumer :: Maybe ByteString, -- ^ Fetch the messages having a specific owner.
    XPendingDetailOpts -> Maybe Integer
xPendingDetailIdle :: Maybe Integer
    {- ^  Filter pending stream entries by their idle-time, ms

    Since Redis 6.2: Just values will fail
    -}
  }

-- | Default 'XPendingOpts' values.
--
-- Prefer this method over use of the constructor in order to preserve
-- backwards compatibility.
defaultXPendingDetailOpts :: XPendingDetailOpts
defaultXPendingDetailOpts :: XPendingDetailOpts
defaultXPendingDetailOpts = XPendingDetailOpts {
    xPendingDetailConsumer :: Maybe ByteString
xPendingDetailConsumer = Maybe ByteString
forall a. Maybe a
Nothing,
    xPendingDetailIdle :: Maybe Integer
xPendingDetailIdle     = Maybe Integer
forall a. Maybe a
Nothing
}

-- | /O(N)/ N - number of messages returned.
--
-- Get detailed information about pending messages (https://redis.io/commands/xpending).
xpendingDetail
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Consumer group name.
    -> ByteString -- ^ ID of the first interesting message.
    -> ByteString -- ^ ID of the last intersting message.
    -> Integer -- ^ Limits the numbere of messages returned from the call.
    -> XPendingDetailOpts
    -> m (f [XPendingDetailRecord])
xpendingDetail :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> ByteString
-> Integer
-> XPendingDetailOpts
-> m (f [XPendingDetailRecord])
xpendingDetail ByteString
stream ByteString
group ByteString
startId ByteString
endId Integer
count XPendingDetailOpts
opts = [ByteString] -> m (f [XPendingDetailRecord])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [XPendingDetailRecord]))
-> [ByteString] -> m (f [XPendingDetailRecord])
forall a b. (a -> b) -> a -> b
$
    [ByteString
"XPENDING", ByteString
stream, ByteString
group] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
idleArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
startId, ByteString
endId, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
consumerArg
    where consumerArg :: [ByteString]
consumerArg = Maybe ByteString -> [ByteString]
forall a. Maybe a -> [a]
maybeToList (XPendingDetailOpts -> Maybe ByteString
xPendingDetailConsumer XPendingDetailOpts
opts)
          idleArg :: [ByteString]
idleArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] ((ByteString
"IDLE"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:) ([ByteString] -> [ByteString])
-> (Integer -> [ByteString]) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[]) (ByteString -> [ByteString])
-> (Integer -> ByteString) -> Integer -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode) (XPendingDetailOpts -> Maybe Integer
xPendingDetailIdle XPendingDetailOpts
opts)

data XClaimOpts = XClaimOpts
    { XClaimOpts -> Maybe Integer
xclaimIdle :: Maybe Integer
    , XClaimOpts -> Maybe Integer
xclaimTime :: Maybe Integer
    , XClaimOpts -> Maybe Integer
xclaimRetryCount :: Maybe Integer
    , XClaimOpts -> Bool
xclaimForce :: Bool
    } deriving (Int -> XClaimOpts -> ShowS
[XClaimOpts] -> ShowS
XClaimOpts -> String
(Int -> XClaimOpts -> ShowS)
-> (XClaimOpts -> String)
-> ([XClaimOpts] -> ShowS)
-> Show XClaimOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XClaimOpts -> ShowS
showsPrec :: Int -> XClaimOpts -> ShowS
$cshow :: XClaimOpts -> String
show :: XClaimOpts -> String
$cshowList :: [XClaimOpts] -> ShowS
showList :: [XClaimOpts] -> ShowS
Show, XClaimOpts -> XClaimOpts -> Bool
(XClaimOpts -> XClaimOpts -> Bool)
-> (XClaimOpts -> XClaimOpts -> Bool) -> Eq XClaimOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XClaimOpts -> XClaimOpts -> Bool
== :: XClaimOpts -> XClaimOpts -> Bool
$c/= :: XClaimOpts -> XClaimOpts -> Bool
/= :: XClaimOpts -> XClaimOpts -> Bool
Eq)

defaultXClaimOpts :: XClaimOpts
defaultXClaimOpts :: XClaimOpts
defaultXClaimOpts = XClaimOpts
    { xclaimIdle :: Maybe Integer
xclaimIdle = Maybe Integer
forall a. Maybe a
Nothing
    , xclaimTime :: Maybe Integer
xclaimTime = Maybe Integer
forall a. Maybe a
Nothing
    , xclaimRetryCount :: Maybe Integer
xclaimRetryCount = Maybe Integer
forall a. Maybe a
Nothing
    , xclaimForce :: Bool
xclaimForce = Bool
False
    }


-- |Format a request for XCLAIM.
xclaimRequest
    :: ByteString -- ^ stream
    -> ByteString -- ^ group
    -> ByteString -- ^ consumer
    -> Integer -- ^ min idle time
    -> XClaimOpts -- ^ optional arguments
    -> [ByteString] -- ^ message IDs
    -> [ByteString]
xclaimRequest :: ByteString
-> ByteString
-> ByteString
-> Integer
-> XClaimOpts
-> [ByteString]
-> [ByteString]
xclaimRequest ByteString
stream ByteString
group ByteString
consumer Integer
minIdleTime XClaimOpts{Bool
Maybe Integer
xclaimIdle :: XClaimOpts -> Maybe Integer
xclaimTime :: XClaimOpts -> Maybe Integer
xclaimRetryCount :: XClaimOpts -> Maybe Integer
xclaimForce :: XClaimOpts -> Bool
xclaimIdle :: Maybe Integer
xclaimTime :: Maybe Integer
xclaimRetryCount :: Maybe Integer
xclaimForce :: Bool
..} [ByteString]
messageIds =
    [ByteString
"XCLAIM", ByteString
stream, ByteString
group, ByteString
consumer, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
minIdleTime] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ( (ByteString -> ByteString) -> [ByteString] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map ByteString -> ByteString
forall a. RedisArg a => a -> ByteString
encode [ByteString]
messageIds ) [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
optArgs
    where optArgs :: [ByteString]
optArgs = [ByteString]
idleArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
timeArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
retryCountArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
forceArg
          idleArg :: [ByteString]
idleArg = ByteString -> Maybe Integer -> [ByteString]
forall {a}. RedisArg a => ByteString -> Maybe a -> [ByteString]
optArg ByteString
"IDLE" Maybe Integer
xclaimIdle
          timeArg :: [ByteString]
timeArg = ByteString -> Maybe Integer -> [ByteString]
forall {a}. RedisArg a => ByteString -> Maybe a -> [ByteString]
optArg ByteString
"TIME" Maybe Integer
xclaimTime
          retryCountArg :: [ByteString]
retryCountArg = ByteString -> Maybe Integer -> [ByteString]
forall {a}. RedisArg a => ByteString -> Maybe a -> [ByteString]
optArg ByteString
"RETRYCOUNT" Maybe Integer
xclaimRetryCount
          forceArg :: [ByteString]
forceArg = if Bool
xclaimForce then [ByteString
"FORCE"] else []
          optArg :: ByteString -> Maybe a -> [ByteString]
optArg ByteString
name Maybe a
maybeArg = [ByteString] -> (a -> [ByteString]) -> Maybe a -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\a
x -> [ByteString
name, a -> ByteString
forall a. RedisArg a => a -> ByteString
encode a
x]) Maybe a
maybeArg

xclaim
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> ByteString -- ^ group
    -> ByteString -- ^ consumer
    -> Integer -- ^ min idle time
    -> XClaimOpts -- ^ optional arguments
    -> [ByteString] -- ^ message IDs
    -> m (f [StreamsRecord])
xclaim :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Integer
-> XClaimOpts
-> [ByteString]
-> m (f [StreamsRecord])
xclaim ByteString
stream ByteString
group ByteString
consumer Integer
minIdleTime XClaimOpts
opts [ByteString]
messageIds = [ByteString] -> m (f [StreamsRecord])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [StreamsRecord]))
-> [ByteString] -> m (f [StreamsRecord])
forall a b. (a -> b) -> a -> b
$
    ByteString
-> ByteString
-> ByteString
-> Integer
-> XClaimOpts
-> [ByteString]
-> [ByteString]
xclaimRequest ByteString
stream ByteString
group ByteString
consumer Integer
minIdleTime XClaimOpts
opts [ByteString]
messageIds

xclaimJustIds
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> ByteString -- ^ group
    -> ByteString -- ^ consumer
    -> Integer -- ^ min idle time
    -> XClaimOpts -- ^ optional arguments
    -> [ByteString] -- ^ message IDs
    -> m (f [ByteString])
xclaimJustIds :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Integer
-> XClaimOpts
-> [ByteString]
-> m (f [ByteString])
xclaimJustIds ByteString
stream ByteString
group ByteString
consumer Integer
minIdleTime XClaimOpts
opts [ByteString]
messageIds = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [ByteString]))
-> [ByteString] -> m (f [ByteString])
forall a b. (a -> b) -> a -> b
$
    (ByteString
-> ByteString
-> ByteString
-> Integer
-> XClaimOpts
-> [ByteString]
-> [ByteString]
xclaimRequest ByteString
stream ByteString
group ByteString
consumer Integer
minIdleTime XClaimOpts
opts [ByteString]
messageIds) [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"JUSTID"]

data GeoUnit
    = GeoMeters
    | GeoKilometers
    | GeoFeet
    | GeoMiles
    deriving (Int -> GeoUnit -> ShowS
[GeoUnit] -> ShowS
GeoUnit -> String
(Int -> GeoUnit -> ShowS)
-> (GeoUnit -> String) -> ([GeoUnit] -> ShowS) -> Show GeoUnit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeoUnit -> ShowS
showsPrec :: Int -> GeoUnit -> ShowS
$cshow :: GeoUnit -> String
show :: GeoUnit -> String
$cshowList :: [GeoUnit] -> ShowS
showList :: [GeoUnit] -> ShowS
Show, GeoUnit -> GeoUnit -> Bool
(GeoUnit -> GeoUnit -> Bool)
-> (GeoUnit -> GeoUnit -> Bool) -> Eq GeoUnit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeoUnit -> GeoUnit -> Bool
== :: GeoUnit -> GeoUnit -> Bool
$c/= :: GeoUnit -> GeoUnit -> Bool
/= :: GeoUnit -> GeoUnit -> Bool
Eq)

instance RedisArg GeoUnit where
    encode :: GeoUnit -> ByteString
encode GeoUnit
GeoMeters = ByteString
"m"
    encode GeoUnit
GeoKilometers = ByteString
"km"
    encode GeoUnit
GeoFeet = ByteString
"ft"
    encode GeoUnit
GeoMiles = ByteString
"mi"

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

instance RedisArg GeoOrder where
    encode :: GeoOrder -> ByteString
encode GeoOrder
GeoAsc = ByteString
"ASC"
    encode GeoOrder
GeoDesc = ByteString
"DESC"

data GeoCoordinates = GeoCoordinates
    { GeoCoordinates -> Double
geoLongitude :: Double
    , GeoCoordinates -> Double
geoLatitude :: Double
    } deriving (Int -> GeoCoordinates -> ShowS
[GeoCoordinates] -> ShowS
GeoCoordinates -> String
(Int -> GeoCoordinates -> ShowS)
-> (GeoCoordinates -> String)
-> ([GeoCoordinates] -> ShowS)
-> Show GeoCoordinates
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeoCoordinates -> ShowS
showsPrec :: Int -> GeoCoordinates -> ShowS
$cshow :: GeoCoordinates -> String
show :: GeoCoordinates -> String
$cshowList :: [GeoCoordinates] -> ShowS
showList :: [GeoCoordinates] -> ShowS
Show, GeoCoordinates -> GeoCoordinates -> Bool
(GeoCoordinates -> GeoCoordinates -> Bool)
-> (GeoCoordinates -> GeoCoordinates -> Bool) -> Eq GeoCoordinates
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeoCoordinates -> GeoCoordinates -> Bool
== :: GeoCoordinates -> GeoCoordinates -> Bool
$c/= :: GeoCoordinates -> GeoCoordinates -> Bool
/= :: GeoCoordinates -> GeoCoordinates -> Bool
Eq)

instance RedisResult GeoCoordinates where
    decode :: Reply -> Either Reply GeoCoordinates
decode (MultiBulk (Just [Reply
lon, Reply
lat])) =
        Double -> Double -> GeoCoordinates
GeoCoordinates (Double -> Double -> GeoCoordinates)
-> Either Reply Double -> Either Reply (Double -> GeoCoordinates)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
lon Either Reply (Double -> GeoCoordinates)
-> Either Reply Double -> Either Reply GeoCoordinates
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Double
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
lat
    decode Reply
r = Reply -> Either Reply GeoCoordinates
forall a b. a -> Either a b
Left Reply
r

data GeoLocation = GeoLocation
    { GeoLocation -> ByteString
geoLocationMember :: ByteString
    , GeoLocation -> Maybe Double
geoLocationDist :: Maybe Double
    , GeoLocation -> Maybe Integer
geoLocationHash :: Maybe Integer
    , GeoLocation -> Maybe GeoCoordinates
geoLocationCoordinates :: Maybe GeoCoordinates
    } deriving (Int -> GeoLocation -> ShowS
[GeoLocation] -> ShowS
GeoLocation -> String
(Int -> GeoLocation -> ShowS)
-> (GeoLocation -> String)
-> ([GeoLocation] -> ShowS)
-> Show GeoLocation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeoLocation -> ShowS
showsPrec :: Int -> GeoLocation -> ShowS
$cshow :: GeoLocation -> String
show :: GeoLocation -> String
$cshowList :: [GeoLocation] -> ShowS
showList :: [GeoLocation] -> ShowS
Show, GeoLocation -> GeoLocation -> Bool
(GeoLocation -> GeoLocation -> Bool)
-> (GeoLocation -> GeoLocation -> Bool) -> Eq GeoLocation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeoLocation -> GeoLocation -> Bool
== :: GeoLocation -> GeoLocation -> Bool
$c/= :: GeoLocation -> GeoLocation -> Bool
/= :: GeoLocation -> GeoLocation -> Bool
Eq)

instance RedisResult GeoLocation where
    decode :: Reply -> Either Reply GeoLocation
decode r :: Reply
r@(Bulk (Just ByteString
_)) =
        ByteString
-> Maybe Double
-> Maybe Integer
-> Maybe GeoCoordinates
-> GeoLocation
GeoLocation (ByteString
 -> Maybe Double
 -> Maybe Integer
 -> Maybe GeoCoordinates
 -> GeoLocation)
-> Either Reply ByteString
-> Either
     Reply
     (Maybe Double
      -> Maybe Integer -> Maybe GeoCoordinates -> GeoLocation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
r Either
  Reply
  (Maybe Double
   -> Maybe Integer -> Maybe GeoCoordinates -> GeoLocation)
-> Either Reply (Maybe Double)
-> Either
     Reply (Maybe Integer -> Maybe GeoCoordinates -> GeoLocation)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Double -> Either Reply (Maybe Double)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Double
forall a. Maybe a
Nothing Either Reply (Maybe Integer -> Maybe GeoCoordinates -> GeoLocation)
-> Either Reply (Maybe Integer)
-> Either Reply (Maybe GeoCoordinates -> GeoLocation)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Integer -> Either Reply (Maybe Integer)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Integer
forall a. Maybe a
Nothing Either Reply (Maybe GeoCoordinates -> GeoLocation)
-> Either Reply (Maybe GeoCoordinates) -> Either Reply GeoLocation
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe GeoCoordinates -> Either Reply (Maybe GeoCoordinates)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe GeoCoordinates
forall a. Maybe a
Nothing
    decode r :: Reply
r@(SingleLine ByteString
_) =
        ByteString
-> Maybe Double
-> Maybe Integer
-> Maybe GeoCoordinates
-> GeoLocation
GeoLocation (ByteString
 -> Maybe Double
 -> Maybe Integer
 -> Maybe GeoCoordinates
 -> GeoLocation)
-> Either Reply ByteString
-> Either
     Reply
     (Maybe Double
      -> Maybe Integer -> Maybe GeoCoordinates -> GeoLocation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
r Either
  Reply
  (Maybe Double
   -> Maybe Integer -> Maybe GeoCoordinates -> GeoLocation)
-> Either Reply (Maybe Double)
-> Either
     Reply (Maybe Integer -> Maybe GeoCoordinates -> GeoLocation)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Double -> Either Reply (Maybe Double)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Double
forall a. Maybe a
Nothing Either Reply (Maybe Integer -> Maybe GeoCoordinates -> GeoLocation)
-> Either Reply (Maybe Integer)
-> Either Reply (Maybe GeoCoordinates -> GeoLocation)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Integer -> Either Reply (Maybe Integer)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Integer
forall a. Maybe a
Nothing Either Reply (Maybe GeoCoordinates -> GeoLocation)
-> Either Reply (Maybe GeoCoordinates) -> Either Reply GeoLocation
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe GeoCoordinates -> Either Reply (Maybe GeoCoordinates)
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe GeoCoordinates
forall a. Maybe a
Nothing
    decode (MultiBulk (Just (Reply
memberReply:[Reply]
details))) = do
        geoLocationMember <- Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
memberReply
        (geoLocationDist, geoLocationHash, geoLocationCoordinates) <- decodeGeoLocationDetails details
        pure GeoLocation {..}
      where
        decodeGeoLocationDetails :: [Reply] -> Either Reply (Maybe Double, Maybe Integer, Maybe GeoCoordinates)
        decodeGeoLocationDetails :: [Reply]
-> Either Reply (Maybe Double, Maybe Integer, Maybe GeoCoordinates)
decodeGeoLocationDetails = Maybe Double
-> Maybe Integer
-> Maybe GeoCoordinates
-> [Reply]
-> Either Reply (Maybe Double, Maybe Integer, Maybe GeoCoordinates)
forall {a} {a} {a}.
(RedisResult a, RedisResult a, RedisResult a) =>
Maybe a
-> Maybe a
-> Maybe a
-> [Reply]
-> Either Reply (Maybe a, Maybe a, Maybe a)
go Maybe Double
forall a. Maybe a
Nothing Maybe Integer
forall a. Maybe a
Nothing Maybe GeoCoordinates
forall a. Maybe a
Nothing

        go :: Maybe a
-> Maybe a
-> Maybe a
-> [Reply]
-> Either Reply (Maybe a, Maybe a, Maybe a)
go Maybe a
md Maybe a
mh Maybe a
mc [] = (Maybe a, Maybe a, Maybe a)
-> Either Reply (Maybe a, Maybe a, Maybe a)
forall a b. b -> Either a b
Right (Maybe a
md, Maybe a
mh, Maybe a
mc)
        go Maybe a
md Maybe a
mh Maybe a
mc (Reply
x:[Reply]
xs) = case Reply
x of
            MultiBulk Maybe [Reply]
_ -> do
                coord <- Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
x
                go md mh (Just coord) xs
            Integer Integer
_ -> do
                hashValue <- Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
x
                go md (Just hashValue) mc xs
            Reply
_ -> do
                dist <- Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
x
                go (Just dist) mh mc xs
    decode Reply
r = Reply -> Either Reply GeoLocation
forall a b. a -> Either a b
Left Reply
r

data GeoSearchFrom
    = GeoSearchFromMember ByteString
    | GeoSearchFromLonLat Double Double
    deriving (Int -> GeoSearchFrom -> ShowS
[GeoSearchFrom] -> ShowS
GeoSearchFrom -> String
(Int -> GeoSearchFrom -> ShowS)
-> (GeoSearchFrom -> String)
-> ([GeoSearchFrom] -> ShowS)
-> Show GeoSearchFrom
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeoSearchFrom -> ShowS
showsPrec :: Int -> GeoSearchFrom -> ShowS
$cshow :: GeoSearchFrom -> String
show :: GeoSearchFrom -> String
$cshowList :: [GeoSearchFrom] -> ShowS
showList :: [GeoSearchFrom] -> ShowS
Show, GeoSearchFrom -> GeoSearchFrom -> Bool
(GeoSearchFrom -> GeoSearchFrom -> Bool)
-> (GeoSearchFrom -> GeoSearchFrom -> Bool) -> Eq GeoSearchFrom
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeoSearchFrom -> GeoSearchFrom -> Bool
== :: GeoSearchFrom -> GeoSearchFrom -> Bool
$c/= :: GeoSearchFrom -> GeoSearchFrom -> Bool
/= :: GeoSearchFrom -> GeoSearchFrom -> Bool
Eq)

data GeoSearchBy
    = GeoSearchByRadius Double GeoUnit
    | GeoSearchByBox Double Double GeoUnit
    deriving (Int -> GeoSearchBy -> ShowS
[GeoSearchBy] -> ShowS
GeoSearchBy -> String
(Int -> GeoSearchBy -> ShowS)
-> (GeoSearchBy -> String)
-> ([GeoSearchBy] -> ShowS)
-> Show GeoSearchBy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeoSearchBy -> ShowS
showsPrec :: Int -> GeoSearchBy -> ShowS
$cshow :: GeoSearchBy -> String
show :: GeoSearchBy -> String
$cshowList :: [GeoSearchBy] -> ShowS
showList :: [GeoSearchBy] -> ShowS
Show, GeoSearchBy -> GeoSearchBy -> Bool
(GeoSearchBy -> GeoSearchBy -> Bool)
-> (GeoSearchBy -> GeoSearchBy -> Bool) -> Eq GeoSearchBy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeoSearchBy -> GeoSearchBy -> Bool
== :: GeoSearchBy -> GeoSearchBy -> Bool
$c/= :: GeoSearchBy -> GeoSearchBy -> Bool
/= :: GeoSearchBy -> GeoSearchBy -> Bool
Eq)

data GeoSearchOpts = GeoSearchOpts
    { GeoSearchOpts -> Bool
geoSearchWithCoord :: Bool
    , GeoSearchOpts -> Bool
geoSearchWithDist :: Bool
    , GeoSearchOpts -> Bool
geoSearchWithHash :: Bool
    , GeoSearchOpts -> Maybe Integer
geoSearchCount :: Maybe Integer
    , GeoSearchOpts -> Bool
geoSearchCountAny :: Bool
    , GeoSearchOpts -> Maybe GeoOrder
geoSearchOrder :: Maybe GeoOrder
    } deriving (Int -> GeoSearchOpts -> ShowS
[GeoSearchOpts] -> ShowS
GeoSearchOpts -> String
(Int -> GeoSearchOpts -> ShowS)
-> (GeoSearchOpts -> String)
-> ([GeoSearchOpts] -> ShowS)
-> Show GeoSearchOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeoSearchOpts -> ShowS
showsPrec :: Int -> GeoSearchOpts -> ShowS
$cshow :: GeoSearchOpts -> String
show :: GeoSearchOpts -> String
$cshowList :: [GeoSearchOpts] -> ShowS
showList :: [GeoSearchOpts] -> ShowS
Show, GeoSearchOpts -> GeoSearchOpts -> Bool
(GeoSearchOpts -> GeoSearchOpts -> Bool)
-> (GeoSearchOpts -> GeoSearchOpts -> Bool) -> Eq GeoSearchOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeoSearchOpts -> GeoSearchOpts -> Bool
== :: GeoSearchOpts -> GeoSearchOpts -> Bool
$c/= :: GeoSearchOpts -> GeoSearchOpts -> Bool
/= :: GeoSearchOpts -> GeoSearchOpts -> Bool
Eq)

defaultGeoSearchOpts :: GeoSearchOpts
defaultGeoSearchOpts :: GeoSearchOpts
defaultGeoSearchOpts = GeoSearchOpts
    { geoSearchWithCoord :: Bool
geoSearchWithCoord = Bool
False
    , geoSearchWithDist :: Bool
geoSearchWithDist = Bool
False
    , geoSearchWithHash :: Bool
geoSearchWithHash = Bool
False
    , geoSearchCount :: Maybe Integer
geoSearchCount = Maybe Integer
forall a. Maybe a
Nothing
    , geoSearchCountAny :: Bool
geoSearchCountAny = Bool
False
    , geoSearchOrder :: Maybe GeoOrder
geoSearchOrder = Maybe GeoOrder
forall a. Maybe a
Nothing
    }

data GeoSearchStoreOpts = GeoSearchStoreOpts
    { GeoSearchStoreOpts -> Maybe Integer
geoSearchStoreCount :: Maybe Integer
    , GeoSearchStoreOpts -> Bool
geoSearchStoreCountAny :: Bool
    , GeoSearchStoreOpts -> Maybe GeoOrder
geoSearchStoreOrder :: Maybe GeoOrder
    , GeoSearchStoreOpts -> Bool
geoSearchStoreStoredist :: Bool
    } deriving (Int -> GeoSearchStoreOpts -> ShowS
[GeoSearchStoreOpts] -> ShowS
GeoSearchStoreOpts -> String
(Int -> GeoSearchStoreOpts -> ShowS)
-> (GeoSearchStoreOpts -> String)
-> ([GeoSearchStoreOpts] -> ShowS)
-> Show GeoSearchStoreOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeoSearchStoreOpts -> ShowS
showsPrec :: Int -> GeoSearchStoreOpts -> ShowS
$cshow :: GeoSearchStoreOpts -> String
show :: GeoSearchStoreOpts -> String
$cshowList :: [GeoSearchStoreOpts] -> ShowS
showList :: [GeoSearchStoreOpts] -> ShowS
Show, GeoSearchStoreOpts -> GeoSearchStoreOpts -> Bool
(GeoSearchStoreOpts -> GeoSearchStoreOpts -> Bool)
-> (GeoSearchStoreOpts -> GeoSearchStoreOpts -> Bool)
-> Eq GeoSearchStoreOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeoSearchStoreOpts -> GeoSearchStoreOpts -> Bool
== :: GeoSearchStoreOpts -> GeoSearchStoreOpts -> Bool
$c/= :: GeoSearchStoreOpts -> GeoSearchStoreOpts -> Bool
/= :: GeoSearchStoreOpts -> GeoSearchStoreOpts -> Bool
Eq)

defaultGeoSearchStoreOpts :: GeoSearchStoreOpts
defaultGeoSearchStoreOpts :: GeoSearchStoreOpts
defaultGeoSearchStoreOpts = GeoSearchStoreOpts
    { geoSearchStoreCount :: Maybe Integer
geoSearchStoreCount = Maybe Integer
forall a. Maybe a
Nothing
    , geoSearchStoreCountAny :: Bool
geoSearchStoreCountAny = Bool
False
    , geoSearchStoreOrder :: Maybe GeoOrder
geoSearchStoreOrder = Maybe GeoOrder
forall a. Maybe a
Nothing
    , geoSearchStoreStoredist :: Bool
geoSearchStoreStoredist = Bool
False
    }

-- |Adds one or more members to a geospatial index (<https://redis.io/commands/geoadd>). The Redis command @GEOADD@ is split up into 'geoadd' and 'geoAddOpts'. Since Redis 3.2.0
data GeoAddOpts = GeoAddOpts
    { GeoAddOpts -> Maybe Condition
geoAddCondition :: Maybe Condition
    , GeoAddOpts -> Bool
geoAddChange :: Bool
    {- ^ Modify the return value from the number of new elements added, to the number of elements changed.

    Since Redis 6.2.0
    -}
    } deriving (Int -> GeoAddOpts -> ShowS
[GeoAddOpts] -> ShowS
GeoAddOpts -> String
(Int -> GeoAddOpts -> ShowS)
-> (GeoAddOpts -> String)
-> ([GeoAddOpts] -> ShowS)
-> Show GeoAddOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeoAddOpts -> ShowS
showsPrec :: Int -> GeoAddOpts -> ShowS
$cshow :: GeoAddOpts -> String
show :: GeoAddOpts -> String
$cshowList :: [GeoAddOpts] -> ShowS
showList :: [GeoAddOpts] -> ShowS
Show, GeoAddOpts -> GeoAddOpts -> Bool
(GeoAddOpts -> GeoAddOpts -> Bool)
-> (GeoAddOpts -> GeoAddOpts -> Bool) -> Eq GeoAddOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeoAddOpts -> GeoAddOpts -> Bool
== :: GeoAddOpts -> GeoAddOpts -> Bool
$c/= :: GeoAddOpts -> GeoAddOpts -> Bool
/= :: GeoAddOpts -> GeoAddOpts -> Bool
Eq)

-- |Redis default 'GeoAddOpts'. Equivalent to omitting all optional parameters.
defaultGeoAddOpts :: GeoAddOpts
defaultGeoAddOpts :: GeoAddOpts
defaultGeoAddOpts = GeoAddOpts
    { geoAddCondition :: Maybe Condition
geoAddCondition = Maybe Condition
forall a. Maybe a
Nothing
    , geoAddChange :: Bool
geoAddChange = Bool
False
    }

-- |Adds one or more members to a geospatial index (<https://redis.io/commands/geoadd>).
-- The Redis command @GEOADD@ is split up into 'geoadd' and 'geoAddOpts'.
--
-- Note: there is no @geodel@ command because you can use 'zrem' to remove elements.
-- The Geo index structure is just a sorted set.
--
-- Since Redis 3.2.0
--
-- Redis tags: write, geo, slow
geoadd
    :: (RedisCtx m f)
    => ByteString
    -> [(Double, Double, ByteString)]
    -> m (f Integer)
geoadd :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [(Double, Double, ByteString)] -> m (f Integer)
geoadd ByteString
key [(Double, Double, ByteString)]
values = ByteString
-> [(Double, Double, ByteString)] -> GeoAddOpts -> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> [(Double, Double, ByteString)] -> GeoAddOpts -> m (f Integer)
geoaddOpts ByteString
key [(Double, Double, ByteString)]
values GeoAddOpts
defaultGeoAddOpts

-- |Adds one or more members to a geospatial index (<https://redis.io/commands/geoadd>).
-- The Redis command @GEOADD@ is split up into 'geoadd' and 'geoAddOpts'.
--
-- Since Redis 6.2.0
geoaddOpts
    :: (RedisCtx m f)
    => ByteString
    -> [(Double, Double, ByteString)]
    -> GeoAddOpts
    -> m (f Integer)
geoaddOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> [(Double, Double, ByteString)] -> GeoAddOpts -> m (f Integer)
geoaddOpts ByteString
key [(Double, Double, ByteString)]
values GeoAddOpts{Bool
Maybe Condition
geoAddCondition :: GeoAddOpts -> Maybe Condition
geoAddChange :: GeoAddOpts -> Bool
geoAddCondition :: Maybe Condition
geoAddChange :: Bool
..} =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"GEOADD", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
conditionArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
changeArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ((Double, Double, ByteString) -> [ByteString])
-> [(Double, Double, ByteString)] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Double, Double, ByteString) -> [ByteString]
forall {a} {a}.
(RedisArg a, RedisArg a) =>
(a, a, ByteString) -> [ByteString]
encodeGeoValue [(Double, Double, ByteString)]
values
  where
    conditionArg :: [ByteString]
conditionArg = (Condition -> [ByteString]) -> Maybe Condition -> [ByteString]
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\Condition
condition -> [Condition -> ByteString
forall a. RedisArg a => a -> ByteString
encode Condition
condition]) Maybe Condition
geoAddCondition
    changeArg :: [ByteString]
changeArg = [ByteString
"CH" | Bool
geoAddChange]
    encodeGeoValue :: (a, a, ByteString) -> [ByteString]
encodeGeoValue (a
lon, a
lat, ByteString
member) = [a -> ByteString
forall a. RedisArg a => a -> ByteString
encode a
lon, a -> ByteString
forall a. RedisArg a => a -> ByteString
encode a
lat, ByteString
member]

-- |Returns the distance between two members of a geospatial index (<https://redis.io/commands/geodist>). Since Redis 3.2.0
--
-- Redis tags: read, geo, slow
geodist
    :: (RedisCtx m f)
    => ByteString
    -> ByteString
    -> ByteString
    -> Maybe GeoUnit
    -> m (f (Maybe Double))
geodist :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> Maybe GeoUnit
-> m (f (Maybe Double))
geodist ByteString
key ByteString
member1 ByteString
member2 Maybe GeoUnit
munit =
    [ByteString] -> m (f (Maybe Double))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe Double)))
-> [ByteString] -> m (f (Maybe Double))
forall a b. (a -> b) -> a -> b
$ [ByteString
"GEODIST", ByteString
key, ByteString
member1, ByteString
member2] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ Maybe ByteString -> [ByteString]
forall a. Maybe a -> [a]
maybeToList (GeoUnit -> ByteString
forall a. RedisArg a => a -> ByteString
encode (GeoUnit -> ByteString) -> Maybe GeoUnit -> Maybe ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe GeoUnit
munit)

-- |Returns the longitude and latitude of members from a geospatial index (<https://redis.io/commands/geopos>). Since Redis 3.2.0
--
-- ACL categories: @read, @geo, @slow.
geopos
    :: (RedisCtx m f)
    => ByteString
    -> [ByteString]
    -> m (f [Maybe GeoCoordinates])
geopos :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> [ByteString] -> m (f [Maybe GeoCoordinates])
geopos ByteString
key [ByteString]
members = [ByteString] -> m (f [Maybe GeoCoordinates])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [Maybe GeoCoordinates]))
-> [ByteString] -> m (f [Maybe GeoCoordinates])
forall a b. (a -> b) -> a -> b
$ [ByteString
"GEOPOS", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
members

-- |Queries a geospatial index for members inside an area of a box or a circle (<https://redis.io/commands/geosearch>). Since Redis 6.2.0
--
-- /O(N+log(M))/ where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter and M is the number of items inside the shape
--
-- ACL: @read, @geo, @slow
--
-- Since: Redis 6.2.0
geoSearch
    :: (RedisCtx m f)
    => ByteString
    -> GeoSearchFrom
    -> GeoSearchBy
    -> GeoSearchOpts
    -> m (f [GeoLocation])
geoSearch :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> GeoSearchFrom
-> GeoSearchBy
-> GeoSearchOpts
-> m (f [GeoLocation])
geoSearch ByteString
key GeoSearchFrom
from GeoSearchBy
by GeoSearchOpts
opts =
    [ByteString] -> m (f [GeoLocation])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [GeoLocation]))
-> [ByteString] -> m (f [GeoLocation])
forall a b. (a -> b) -> a -> b
$ [ByteString
"GEOSEARCH", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ GeoSearchFrom -> [ByteString]
geoSearchFromArgs GeoSearchFrom
from [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ GeoSearchBy -> [ByteString]
geoSearchByArgs GeoSearchBy
by [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ GeoSearchOpts -> [ByteString]
geoSearchOptsArgs GeoSearchOpts
opts

-- |Queries a geospatial index for members inside an area of a box or a circle, optionally stores the result (<https://redis.io/commands/geosearchstore>). Since Redis 6.2.0
geoSearchStore
    :: (RedisCtx m f)
    => ByteString
    -> ByteString
    -> GeoSearchFrom
    -> GeoSearchBy
    -> GeoSearchStoreOpts
    -> m (f Integer)
geoSearchStore :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> GeoSearchFrom
-> GeoSearchBy
-> GeoSearchStoreOpts
-> m (f Integer)
geoSearchStore ByteString
destination ByteString
source GeoSearchFrom
from GeoSearchBy
by GeoSearchStoreOpts
opts =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"GEOSEARCHSTORE", ByteString
destination, ByteString
source] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ GeoSearchFrom -> [ByteString]
geoSearchFromArgs GeoSearchFrom
from [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ GeoSearchBy -> [ByteString]
geoSearchByArgs GeoSearchBy
by [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ GeoSearchStoreOpts -> [ByteString]
geoSearchStoreOptsArgs GeoSearchStoreOpts
opts

geoSearchFromArgs :: GeoSearchFrom -> [ByteString]
geoSearchFromArgs :: GeoSearchFrom -> [ByteString]
geoSearchFromArgs (GeoSearchFromMember ByteString
member) = [ByteString
"FROMMEMBER", ByteString
member]
geoSearchFromArgs (GeoSearchFromLonLat Double
lon Double
lat) = [ByteString
"FROMLONLAT", Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
lon, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
lat]

geoSearchByArgs :: GeoSearchBy -> [ByteString]
geoSearchByArgs :: GeoSearchBy -> [ByteString]
geoSearchByArgs (GeoSearchByRadius Double
radius GeoUnit
unit) = [ByteString
"BYRADIUS", Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
radius, GeoUnit -> ByteString
forall a. RedisArg a => a -> ByteString
encode GeoUnit
unit]
geoSearchByArgs (GeoSearchByBox Double
width Double
height GeoUnit
unit) = [ByteString
"BYBOX", Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
width, Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
height, GeoUnit -> ByteString
forall a. RedisArg a => a -> ByteString
encode GeoUnit
unit]

geoSearchOptsArgs :: GeoSearchOpts -> [ByteString]
geoSearchOptsArgs :: GeoSearchOpts -> [ByteString]
geoSearchOptsArgs GeoSearchOpts{Bool
Maybe Integer
Maybe GeoOrder
geoSearchWithCoord :: GeoSearchOpts -> Bool
geoSearchWithDist :: GeoSearchOpts -> Bool
geoSearchWithHash :: GeoSearchOpts -> Bool
geoSearchCount :: GeoSearchOpts -> Maybe Integer
geoSearchCountAny :: GeoSearchOpts -> Bool
geoSearchOrder :: GeoSearchOpts -> Maybe GeoOrder
geoSearchWithCoord :: Bool
geoSearchWithDist :: Bool
geoSearchWithHash :: Bool
geoSearchCount :: Maybe Integer
geoSearchCountAny :: Bool
geoSearchOrder :: Maybe GeoOrder
..} =
    [ByteString]
orderArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
countArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
withCoord [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
withDist [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
withHash
  where
    orderArg :: [ByteString]
orderArg = [ByteString]
-> (GeoOrder -> [ByteString]) -> Maybe GeoOrder -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\GeoOrder
order -> [GeoOrder -> ByteString
forall a. RedisArg a => a -> ByteString
encode GeoOrder
order]) Maybe GeoOrder
geoSearchOrder
    countArg :: [ByteString]
countArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
count -> [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"ANY" | Bool
geoSearchCountAny]) Maybe Integer
geoSearchCount
    withCoord :: [ByteString]
withCoord = [ByteString
"WITHCOORD" | Bool
geoSearchWithCoord]
    withDist :: [ByteString]
withDist = [ByteString
"WITHDIST" | Bool
geoSearchWithDist]
    withHash :: [ByteString]
withHash = [ByteString
"WITHHASH" | Bool
geoSearchWithHash]

geoSearchStoreOptsArgs :: GeoSearchStoreOpts -> [ByteString]
geoSearchStoreOptsArgs :: GeoSearchStoreOpts -> [ByteString]
geoSearchStoreOptsArgs GeoSearchStoreOpts{Bool
Maybe Integer
Maybe GeoOrder
geoSearchStoreCount :: GeoSearchStoreOpts -> Maybe Integer
geoSearchStoreCountAny :: GeoSearchStoreOpts -> Bool
geoSearchStoreOrder :: GeoSearchStoreOpts -> Maybe GeoOrder
geoSearchStoreStoredist :: GeoSearchStoreOpts -> Bool
geoSearchStoreCount :: Maybe Integer
geoSearchStoreCountAny :: Bool
geoSearchStoreOrder :: Maybe GeoOrder
geoSearchStoreStoredist :: Bool
..} =
    [ByteString]
orderArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
countArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
storeDistArg
  where
    orderArg :: [ByteString]
orderArg = [ByteString]
-> (GeoOrder -> [ByteString]) -> Maybe GeoOrder -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\GeoOrder
order -> [GeoOrder -> ByteString
forall a. RedisArg a => a -> ByteString
encode GeoOrder
order]) Maybe GeoOrder
geoSearchStoreOrder
    countArg :: [ByteString]
countArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
count -> [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"ANY" | Bool
geoSearchStoreCountAny]) Maybe Integer
geoSearchStoreCount
    storeDistArg :: [ByteString]
storeDistArg = [ByteString
"STOREDIST" | Bool
geoSearchStoreStoredist]

-- | Data structure that is returned as a result of  'xinfoConsumers'
data XInfoConsumersResponse = XInfoConsumersResponse
    { XInfoConsumersResponse -> ByteString
xinfoConsumerName :: ByteString -- ^ The name of the consumer.
    , XInfoConsumersResponse -> Integer
xinfoConsumerNumPendingMessages :: Integer -- ^ The number of entries in the PEL (pending elemeent list): pending messages for the consumer, which are messages that were delivered but are yet to be acknowledged
    , XInfoConsumersResponse -> Integer
xinfoConsumerIdleTime :: Integer -- ^ The number of milliseconds that have passed since the consumer's last attempted interaction (Examples: 'xreadGroup', 'xclam', 'xautoclaim')
    , XInfoConsumersResponse -> Maybe Integer
xinfoConsumerInactive :: Maybe Integer
    {- ^ The number of milliseconds that have passed since the consumer's last successful interaction (Examples: 'xreadGroup' that actually read some entries into the PEL, 'xclaim'/'xautoclaim' that actually claimed some entries)

    @since Redis 7.0: always @Nothing@ for previous versions.
    -}
    } deriving (Int -> XInfoConsumersResponse -> ShowS
[XInfoConsumersResponse] -> ShowS
XInfoConsumersResponse -> String
(Int -> XInfoConsumersResponse -> ShowS)
-> (XInfoConsumersResponse -> String)
-> ([XInfoConsumersResponse] -> ShowS)
-> Show XInfoConsumersResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XInfoConsumersResponse -> ShowS
showsPrec :: Int -> XInfoConsumersResponse -> ShowS
$cshow :: XInfoConsumersResponse -> String
show :: XInfoConsumersResponse -> String
$cshowList :: [XInfoConsumersResponse] -> ShowS
showList :: [XInfoConsumersResponse] -> ShowS
Show, XInfoConsumersResponse -> XInfoConsumersResponse -> Bool
(XInfoConsumersResponse -> XInfoConsumersResponse -> Bool)
-> (XInfoConsumersResponse -> XInfoConsumersResponse -> Bool)
-> Eq XInfoConsumersResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XInfoConsumersResponse -> XInfoConsumersResponse -> Bool
== :: XInfoConsumersResponse -> XInfoConsumersResponse -> Bool
$c/= :: XInfoConsumersResponse -> XInfoConsumersResponse -> Bool
/= :: XInfoConsumersResponse -> XInfoConsumersResponse -> Bool
Eq)

instance RedisResult XInfoConsumersResponse where
    decode :: Reply -> Either Reply XInfoConsumersResponse
decode = Reply -> Either Reply XInfoConsumersResponse
decodeRedis6 (Reply -> Either Reply XInfoConsumersResponse)
-> (Reply -> Either Reply XInfoConsumersResponse)
-> Reply
-> Either Reply XInfoConsumersResponse
forall a. Semigroup a => a -> a -> a
<> Reply -> Either Reply XInfoConsumersResponse
decodeRedis7
      where decodeRedis6 :: Reply -> Either Reply XInfoConsumersResponse
decodeRedis6 (MultiBulk (Just [
                Bulk (Just ByteString
"name"),
                Bulk (Just ByteString
xinfoConsumerName),
                Bulk (Just ByteString
"pending"),
                Integer Integer
xinfoConsumerNumPendingMessages,
                Bulk (Just ByteString
"idle"),
                Integer Integer
xinfoConsumerIdleTime])) = XInfoConsumersResponse -> Either Reply XInfoConsumersResponse
forall a b. b -> Either a b
Right XInfoConsumersResponse{xinfoConsumerInactive :: Maybe Integer
xinfoConsumerInactive = Maybe Integer
forall a. Maybe a
Nothing, Integer
ByteString
xinfoConsumerName :: ByteString
xinfoConsumerNumPendingMessages :: Integer
xinfoConsumerIdleTime :: Integer
xinfoConsumerName :: ByteString
xinfoConsumerNumPendingMessages :: Integer
xinfoConsumerIdleTime :: Integer
..}
            decodeRedis6 Reply
a = Reply -> Either Reply XInfoConsumersResponse
forall a b. a -> Either a b
Left Reply
a

            decodeRedis7 :: Reply -> Either Reply XInfoConsumersResponse
decodeRedis7 (MultiBulk (Just [
                Bulk (Just ByteString
"name"),
                Bulk (Just ByteString
xinfoConsumerName),
                Bulk (Just ByteString
"pending"),
                Integer Integer
xinfoConsumerNumPendingMessages,
                Bulk (Just ByteString
"idle"),
                Integer Integer
xinfoConsumerIdleTime,
                Bulk (Just ByteString
"inactive"),
                Integer Integer
xinfoConsumerInactive])) = XInfoConsumersResponse -> Either Reply XInfoConsumersResponse
forall a b. b -> Either a b
Right XInfoConsumersResponse{xinfoConsumerInactive :: Maybe Integer
xinfoConsumerInactive = Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
xinfoConsumerInactive, Integer
ByteString
xinfoConsumerName :: ByteString
xinfoConsumerNumPendingMessages :: Integer
xinfoConsumerIdleTime :: Integer
xinfoConsumerName :: ByteString
xinfoConsumerNumPendingMessages :: Integer
xinfoConsumerIdleTime :: Integer
..}
            decodeRedis7 Reply
a = Reply -> Either Reply XInfoConsumersResponse
forall a b. a -> Either a b
Left Reply
a

-- | /O(1)/
-- Returns information about the list of the consumers beloging to the consumer group.
--
-- Available since Redis 5.0.0
--
-- Wrapper over @XINFO CONSUMERS \<stream name\> \<group name\>@
xinfoConsumers
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> ByteString -- ^ Group name.
    -> m (f [XInfoConsumersResponse])
xinfoConsumers :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> ByteString -> m (f [XInfoConsumersResponse])
xinfoConsumers ByteString
stream ByteString
group = [ByteString] -> m (f [XInfoConsumersResponse])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [XInfoConsumersResponse]))
-> [ByteString] -> m (f [XInfoConsumersResponse])
forall a b. (a -> b) -> a -> b
$ [ByteString
"XINFO", ByteString
"CONSUMERS", ByteString
stream, ByteString
group]

-- | Result of the 'xinfoGroups' call.
data XInfoGroupsResponse = XInfoGroupsResponse
    { XInfoGroupsResponse -> ByteString
xinfoGroupsGroupName :: ByteString -- ^ Name of the consumer group.
    , XInfoGroupsResponse -> Integer
xinfoGroupsNumConsumers :: Integer -- ^ The number of consumers in the group.
    , XInfoGroupsResponse -> Integer
xinfoGroupsNumPendingMessages :: Integer -- ^ The length of the group's pending entries list (PEL), which are messages that were delivered but are yet to be acknowledged.
    , XInfoGroupsResponse -> ByteString
xinfoGroupsLastDeliveredMessageId :: ByteString -- ^ The ID of the last entry delivered to the group's consumers.
    , XInfoGroupsResponse -> Maybe Integer
xinfoGroupsEntriesRead :: Maybe Integer
    {- ^ The logical "read counter" of the last entry delivered to group's consumers.

    Since Redis 7.0: always @Nothing@ on the previous versions.
    -}
    , XInfoGroupsResponse -> Maybe Integer
xinfoGroupsLag :: Maybe Integer
    {- ^ the number of entries in the stream that are still waiting to be delivered to the group's consumers, or a Nothing when that number can't be determined.

    Since Redis 7.0: always @Nothing@ on the previous versions.
    -}
    } deriving (Int -> XInfoGroupsResponse -> ShowS
[XInfoGroupsResponse] -> ShowS
XInfoGroupsResponse -> String
(Int -> XInfoGroupsResponse -> ShowS)
-> (XInfoGroupsResponse -> String)
-> ([XInfoGroupsResponse] -> ShowS)
-> Show XInfoGroupsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XInfoGroupsResponse -> ShowS
showsPrec :: Int -> XInfoGroupsResponse -> ShowS
$cshow :: XInfoGroupsResponse -> String
show :: XInfoGroupsResponse -> String
$cshowList :: [XInfoGroupsResponse] -> ShowS
showList :: [XInfoGroupsResponse] -> ShowS
Show, XInfoGroupsResponse -> XInfoGroupsResponse -> Bool
(XInfoGroupsResponse -> XInfoGroupsResponse -> Bool)
-> (XInfoGroupsResponse -> XInfoGroupsResponse -> Bool)
-> Eq XInfoGroupsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XInfoGroupsResponse -> XInfoGroupsResponse -> Bool
== :: XInfoGroupsResponse -> XInfoGroupsResponse -> Bool
$c/= :: XInfoGroupsResponse -> XInfoGroupsResponse -> Bool
/= :: XInfoGroupsResponse -> XInfoGroupsResponse -> Bool
Eq)

instance RedisResult XInfoGroupsResponse where
    decode :: Reply -> Either Reply XInfoGroupsResponse
decode = Reply -> Either Reply XInfoGroupsResponse
decodeRedis6 (Reply -> Either Reply XInfoGroupsResponse)
-> (Reply -> Either Reply XInfoGroupsResponse)
-> Reply
-> Either Reply XInfoGroupsResponse
forall a. Semigroup a => a -> a -> a
<> Reply -> Either Reply XInfoGroupsResponse
decodeRedis7
      where decodeRedis6 :: Reply -> Either Reply XInfoGroupsResponse
decodeRedis6 (MultiBulk (Just [
              Bulk (Just ByteString
"name"),      Bulk (Just ByteString
xinfoGroupsGroupName),
              Bulk (Just ByteString
"consumers"), Integer Integer
xinfoGroupsNumConsumers,
              Bulk (Just ByteString
"pending"),   Integer Integer
xinfoGroupsNumPendingMessages,
              Bulk (Just ByteString
"last-delivered-id"),
              Bulk (Just ByteString
xinfoGroupsLastDeliveredMessageId)])) =
                XInfoGroupsResponse -> Either Reply XInfoGroupsResponse
forall a b. b -> Either a b
Right XInfoGroupsResponse{
                      xinfoGroupsEntriesRead :: Maybe Integer
xinfoGroupsEntriesRead = Maybe Integer
forall a. Maybe a
Nothing
                    , xinfoGroupsLag :: Maybe Integer
xinfoGroupsLag         = Maybe Integer
forall a. Maybe a
Nothing
                    , Integer
ByteString
xinfoGroupsGroupName :: ByteString
xinfoGroupsNumConsumers :: Integer
xinfoGroupsNumPendingMessages :: Integer
xinfoGroupsLastDeliveredMessageId :: ByteString
xinfoGroupsGroupName :: ByteString
xinfoGroupsNumConsumers :: Integer
xinfoGroupsNumPendingMessages :: Integer
xinfoGroupsLastDeliveredMessageId :: ByteString
..}
            decodeRedis6 Reply
a = Reply -> Either Reply XInfoGroupsResponse
forall a b. a -> Either a b
Left Reply
a

            decodeRedis7 :: Reply -> Either Reply XInfoGroupsResponse
decodeRedis7 (MultiBulk (Just [
              Bulk (Just ByteString
"name"),              Bulk (Just ByteString
xinfoGroupsGroupName),
              Bulk (Just ByteString
"consumers"),         Integer Integer
xinfoGroupsNumConsumers,
              Bulk (Just ByteString
"pending"),           Integer Integer
xinfoGroupsNumPendingMessages,
              Bulk (Just ByteString
"last-delivered-id"), Bulk (Just ByteString
xinfoGroupsLastDeliveredMessageId),
              Bulk (Just ByteString
"entries-read"),      Integer Integer
xinfoGroupsEntriesRead,
              Bulk (Just ByteString
"lag"),               Integer Integer
xinfoGroupsLag])) =
                XInfoGroupsResponse -> Either Reply XInfoGroupsResponse
forall a b. b -> Either a b
Right XInfoGroupsResponse{
                      xinfoGroupsEntriesRead :: Maybe Integer
xinfoGroupsEntriesRead = Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
xinfoGroupsEntriesRead
                    , xinfoGroupsLag :: Maybe Integer
xinfoGroupsLag         = Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
xinfoGroupsLag
                    , Integer
ByteString
xinfoGroupsGroupName :: ByteString
xinfoGroupsNumConsumers :: Integer
xinfoGroupsNumPendingMessages :: Integer
xinfoGroupsLastDeliveredMessageId :: ByteString
xinfoGroupsGroupName :: ByteString
xinfoGroupsNumConsumers :: Integer
xinfoGroupsNumPendingMessages :: Integer
xinfoGroupsLastDeliveredMessageId :: ByteString
..}
            decodeRedis7 Reply
a = Reply -> Either Reply XInfoGroupsResponse
forall a b. a -> Either a b
Left Reply
a

-- | /O(1)/ Returns information about the groups.
--
-- Available since: Redis 5.0.0
--
-- Wrapper around @XINFO GROUPS \<stream name\>@ call.
xinfoGroups
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> m (f [XInfoGroupsResponse])
xinfoGroups :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f [XInfoGroupsResponse])
xinfoGroups ByteString
stream = [ByteString] -> m (f [XInfoGroupsResponse])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"XINFO", ByteString
"GROUPS", ByteString
stream]

data XInfoStreamResponse
    = XInfoStreamResponse
    { XInfoStreamResponse -> Integer
xinfoStreamLength :: Integer -- ^ The number of entries in the stream.
    , XInfoStreamResponse -> Integer
xinfoStreamRadixTreeKeys :: Integer -- ^ The number of keys in the underlying radix data structure.
    , XInfoStreamResponse -> Integer
xinfoStreamRadixTreeNodes :: Integer -- ^ The number of nodes in the underlying radix data structure.
    , XInfoStreamResponse -> Maybe ByteString
xinfoMaxDeletedEntryId :: Maybe ByteString
    {- ^ The maximal entry ID that was deleted from the stream

    Since Redis 7.0: always returns @Nothing@ on the previous versions.
    -}
    , XInfoStreamResponse -> Maybe Integer
xinfoEntriesAdded :: Maybe Integer
    {- ^ The count of all entries added to the stream during its lifetime

    Since Redis 7.0: always returns @Nothing@ on the previous versions.
    -}
    , XInfoStreamResponse -> Maybe ByteString
xinfoRecordedFirstEntryId :: Maybe ByteString
    {- ^ ID of first recorded entry.

    Since Redis 7.0: always returns @Nothing@ on the previous versions.
    -}
    , XInfoStreamResponse -> Integer
xinfoStreamNumGroups :: Integer -- ^ The number of consumer groups defined for the stream.
    , XInfoStreamResponse -> ByteString
xinfoStreamLastEntryId :: ByteString -- ^ ID of the last entry in the stream.
    , XInfoStreamResponse -> StreamsRecord
xinfoStreamFirstEntry :: StreamsRecord -- ^ ID and field-value tuples of the first entry in the stream.
    , XInfoStreamResponse -> StreamsRecord
xinfoStreamLastEntry :: StreamsRecord -- ^ ID and field-value tuples of the last entry in the stream.
    }
    | XInfoStreamEmptyResponse
    { xinfoStreamLength :: Integer -- ^ The number of entries in the stream.
    , xinfoStreamRadixTreeKeys :: Integer -- ^ The number of keys in the underlying radix data structure.
    , xinfoStreamRadixTreeNodes :: Integer -- ^ The number of nodes in the underlying radix data structure.
    , xinfoMaxDeletedEntryId :: Maybe ByteString
    {- ^ The maximal entry ID that was deleted from the stream.

    Since Redis 7.0: always returns @Nothing@ on the previous versions.
    -}
    , xinfoEntriesAdded :: Maybe Integer
    {- ^ The count of all entries added to the stream during its lifetime

    Since Redis 7.0: always returns @Nothing@ on the previous versions.
    -}
    , xinfoRecordedFirstEntryId :: Maybe ByteString
    {- ^ ID of first recorded entry.

    Since Redis 7.0: always returns @Nothing@ on the previous versions.
    -}
    , xinfoStreamNumGroups :: Integer -- ^ The number of consumer groups defined for the stream.
    , xinfoStreamLastEntryId :: ByteString -- ^ The ID of the last entry in the stream.
    }
    deriving (Int -> XInfoStreamResponse -> ShowS
[XInfoStreamResponse] -> ShowS
XInfoStreamResponse -> String
(Int -> XInfoStreamResponse -> ShowS)
-> (XInfoStreamResponse -> String)
-> ([XInfoStreamResponse] -> ShowS)
-> Show XInfoStreamResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XInfoStreamResponse -> ShowS
showsPrec :: Int -> XInfoStreamResponse -> ShowS
$cshow :: XInfoStreamResponse -> String
show :: XInfoStreamResponse -> String
$cshowList :: [XInfoStreamResponse] -> ShowS
showList :: [XInfoStreamResponse] -> ShowS
Show, XInfoStreamResponse -> XInfoStreamResponse -> Bool
(XInfoStreamResponse -> XInfoStreamResponse -> Bool)
-> (XInfoStreamResponse -> XInfoStreamResponse -> Bool)
-> Eq XInfoStreamResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XInfoStreamResponse -> XInfoStreamResponse -> Bool
== :: XInfoStreamResponse -> XInfoStreamResponse -> Bool
$c/= :: XInfoStreamResponse -> XInfoStreamResponse -> Bool
/= :: XInfoStreamResponse -> XInfoStreamResponse -> Bool
Eq)

instance RedisResult XInfoStreamResponse where
    decode :: Reply -> Either Reply XInfoStreamResponse
decode = Reply -> Either Reply XInfoStreamResponse
decodeRedis5 (Reply -> Either Reply XInfoStreamResponse)
-> (Reply -> Either Reply XInfoStreamResponse)
-> Reply
-> Either Reply XInfoStreamResponse
forall a. Semigroup a => a -> a -> a
<> Reply -> Either Reply XInfoStreamResponse
decodeRedis6 (Reply -> Either Reply XInfoStreamResponse)
-> (Reply -> Either Reply XInfoStreamResponse)
-> Reply
-> Either Reply XInfoStreamResponse
forall a. Semigroup a => a -> a -> a
<> Reply -> Either Reply XInfoStreamResponse
decodeRedis7
        where
            decodeRedis5 :: Reply -> Either Reply XInfoStreamResponse
decodeRedis5 (MultiBulk (Just [
                 Bulk (Just ByteString
"length"),            Integer Integer
xinfoStreamLength,
                 Bulk (Just ByteString
"radix-tree-keys"),   Integer Integer
xinfoStreamRadixTreeKeys,
                 Bulk (Just ByteString
"radix-tree-nodes"),  Integer Integer
xinfoStreamRadixTreeNodes,
                 Bulk (Just ByteString
"groups"),            Integer Integer
xinfoStreamNumGroups,
                 Bulk (Just ByteString
"last-generated-id"), Bulk (Just ByteString
xinfoStreamLastEntryId),
                 Bulk (Just ByteString
"first-entry"),       Bulk Maybe ByteString
Nothing ,
                 Bulk (Just ByteString
"last-entry"),        Bulk Maybe ByteString
Nothing ])) = do
                    XInfoStreamResponse -> Either Reply XInfoStreamResponse
forall a. a -> Either Reply a
forall (m :: * -> *) a. Monad m => a -> m a
return XInfoStreamEmptyResponse{
                          xinfoMaxDeletedEntryId :: Maybe ByteString
xinfoMaxDeletedEntryId    = Maybe ByteString
forall a. Maybe a
Nothing
                        , xinfoEntriesAdded :: Maybe Integer
xinfoEntriesAdded         = Maybe Integer
forall a. Maybe a
Nothing
                        , xinfoRecordedFirstEntryId :: Maybe ByteString
xinfoRecordedFirstEntryId = Maybe ByteString
forall a. Maybe a
Nothing
                        , Integer
ByteString
xinfoStreamLength :: Integer
xinfoStreamRadixTreeKeys :: Integer
xinfoStreamRadixTreeNodes :: Integer
xinfoStreamNumGroups :: Integer
xinfoStreamLastEntryId :: ByteString
xinfoStreamLength :: Integer
xinfoStreamRadixTreeKeys :: Integer
xinfoStreamRadixTreeNodes :: Integer
xinfoStreamNumGroups :: Integer
xinfoStreamLastEntryId :: ByteString
..}
            decodeRedis5 (MultiBulk (Just [
                Bulk (Just ByteString
"length"),            Integer Integer
xinfoStreamLength,
                Bulk (Just ByteString
"radix-tree-keys"),   Integer Integer
xinfoStreamRadixTreeKeys,
                Bulk (Just ByteString
"radix-tree-nodes"),  Integer Integer
xinfoStreamRadixTreeNodes,
                Bulk (Just ByteString
"groups"),            Integer Integer
xinfoStreamNumGroups,
                Bulk (Just ByteString
"last-generated-id"), Bulk (Just ByteString
xinfoStreamLastEntryId),
                Bulk (Just ByteString
"first-entry"),       Reply
rawFirstEntry ,
                Bulk (Just ByteString
"last-entry"),        Reply
rawLastEntry ])) = do
                    xinfoStreamFirstEntry <- Reply -> Either Reply StreamsRecord
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
rawFirstEntry
                    xinfoStreamLastEntry  <- decode rawLastEntry
                    return XInfoStreamResponse{
                          xinfoMaxDeletedEntryId    = Nothing
                        , xinfoEntriesAdded         = Nothing
                        , xinfoRecordedFirstEntryId = Nothing
                        , ..}
            decodeRedis5 Reply
a = Reply -> Either Reply XInfoStreamResponse
forall a b. a -> Either a b
Left Reply
a

            decodeRedis6 :: Reply -> Either Reply XInfoStreamResponse
decodeRedis6 (MultiBulk (Just [
                Bulk (Just ByteString
"length"),            Integer Integer
xinfoStreamLength,
                Bulk (Just ByteString
"radix-tree-keys"),   Integer Integer
xinfoStreamRadixTreeKeys,
                Bulk (Just ByteString
"radix-tree-nodes"),  Integer Integer
xinfoStreamRadixTreeNodes,
                Bulk (Just ByteString
"last-generated-id"), Bulk (Just ByteString
xinfoStreamLastEntryId),
                Bulk (Just ByteString
"groups"),            Integer Integer
xinfoStreamNumGroups,
                Bulk (Just ByteString
"first-entry"),       Bulk Maybe ByteString
Nothing ,
                Bulk (Just ByteString
"last-entry"),        Bulk Maybe ByteString
Nothing ])) = do
                    XInfoStreamResponse -> Either Reply XInfoStreamResponse
forall a. a -> Either Reply a
forall (m :: * -> *) a. Monad m => a -> m a
return XInfoStreamEmptyResponse{
                          xinfoMaxDeletedEntryId :: Maybe ByteString
xinfoMaxDeletedEntryId    = Maybe ByteString
forall a. Maybe a
Nothing
                        , xinfoEntriesAdded :: Maybe Integer
xinfoEntriesAdded         = Maybe Integer
forall a. Maybe a
Nothing
                        , xinfoRecordedFirstEntryId :: Maybe ByteString
xinfoRecordedFirstEntryId = Maybe ByteString
forall a. Maybe a
Nothing
                        , Integer
ByteString
xinfoStreamLength :: Integer
xinfoStreamRadixTreeKeys :: Integer
xinfoStreamRadixTreeNodes :: Integer
xinfoStreamNumGroups :: Integer
xinfoStreamLastEntryId :: ByteString
xinfoStreamLength :: Integer
xinfoStreamRadixTreeKeys :: Integer
xinfoStreamRadixTreeNodes :: Integer
xinfoStreamLastEntryId :: ByteString
xinfoStreamNumGroups :: Integer
..}
            decodeRedis6 (MultiBulk (Just [
                Bulk (Just ByteString
"length"),            Integer Integer
xinfoStreamLength,
                Bulk (Just ByteString
"radix-tree-keys"),   Integer Integer
xinfoStreamRadixTreeKeys,
                Bulk (Just ByteString
"radix-tree-nodes"),  Integer Integer
xinfoStreamRadixTreeNodes,
                Bulk (Just ByteString
"last-generated-id"), Bulk (Just ByteString
xinfoStreamLastEntryId),
                Bulk (Just ByteString
"groups"),            Integer Integer
xinfoStreamNumGroups,
                Bulk (Just ByteString
"first-entry"),       Reply
rawFirstEntry ,
                Bulk (Just ByteString
"last-entry"),        Reply
rawLastEntry ])) = do
                    xinfoStreamFirstEntry <- Reply -> Either Reply StreamsRecord
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
rawFirstEntry
                    xinfoStreamLastEntry  <- decode rawLastEntry
                    return XInfoStreamResponse{
                          xinfoMaxDeletedEntryId    = Nothing
                        , xinfoEntriesAdded         = Nothing
                        , xinfoRecordedFirstEntryId = Nothing
                        , ..}
            decodeRedis6 Reply
a = Reply -> Either Reply XInfoStreamResponse
forall a b. a -> Either a b
Left Reply
a

            decodeRedis7 :: Reply -> Either Reply XInfoStreamResponse
decodeRedis7 (MultiBulk (Just [
                Bulk (Just ByteString
"length"),                  Integer Integer
xinfoStreamLength,
                Bulk (Just ByteString
"radix-tree-keys"),         Integer Integer
xinfoStreamRadixTreeKeys,
                Bulk (Just ByteString
"radix-tree-nodes"),        Integer Integer
xinfoStreamRadixTreeNodes,
                Bulk (Just ByteString
"last-generated-id"),       Bulk (Just ByteString
xinfoStreamLastEntryId),
                Bulk (Just ByteString
"max-deleted-entry-id"),    Bulk (Just ByteString
xinfoMaxDeletedEntryId),
                Bulk (Just ByteString
"entries-added"),           Integer Integer
xinfoEntriesAdded,
                Bulk (Just ByteString
"recorded-first-entry-id"), Bulk (Just ByteString
xinfoRecordedFirstEntryId),
                Bulk (Just ByteString
"groups"),                  Integer Integer
xinfoStreamNumGroups,
                Bulk (Just ByteString
"first-entry"),             Bulk Maybe ByteString
Nothing ,
                Bulk (Just ByteString
"last-entry"),              Bulk Maybe ByteString
Nothing ])) = do
                    XInfoStreamResponse -> Either Reply XInfoStreamResponse
forall a. a -> Either Reply a
forall (m :: * -> *) a. Monad m => a -> m a
return XInfoStreamEmptyResponse{
                          xinfoMaxDeletedEntryId :: Maybe ByteString
xinfoMaxDeletedEntryId    = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
xinfoMaxDeletedEntryId
                        , xinfoEntriesAdded :: Maybe Integer
xinfoEntriesAdded         = Integer -> Maybe Integer
forall a. a -> Maybe a
Just Integer
xinfoEntriesAdded
                        , xinfoRecordedFirstEntryId :: Maybe ByteString
xinfoRecordedFirstEntryId = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
xinfoRecordedFirstEntryId
                        , Integer
ByteString
xinfoStreamLength :: Integer
xinfoStreamRadixTreeKeys :: Integer
xinfoStreamRadixTreeNodes :: Integer
xinfoStreamNumGroups :: Integer
xinfoStreamLastEntryId :: ByteString
xinfoStreamLength :: Integer
xinfoStreamRadixTreeKeys :: Integer
xinfoStreamRadixTreeNodes :: Integer
xinfoStreamLastEntryId :: ByteString
xinfoStreamNumGroups :: Integer
..}

            decodeRedis7 (MultiBulk (Just [
                Bulk (Just ByteString
"length"),                  Integer Integer
xinfoStreamLength,
                Bulk (Just ByteString
"radix-tree-keys"),         Integer Integer
xinfoStreamRadixTreeKeys,
                Bulk (Just ByteString
"radix-tree-nodes"),        Integer Integer
xinfoStreamRadixTreeNodes,
                Bulk (Just ByteString
"last-generated-id"),       Bulk (Just ByteString
xinfoStreamLastEntryId),
                Bulk (Just ByteString
"max-deleted-entry-id"),    Bulk (Just ByteString
xinfoMaxDeletedEntryId),
                Bulk (Just ByteString
"entries-added"),           Integer Integer
xinfoEntriesAdded,
                Bulk (Just ByteString
"recorded-first-entry-id"), Bulk (Just ByteString
xinfoRecordedFirstEntryId),
                Bulk (Just ByteString
"groups"),                  Integer Integer
xinfoStreamNumGroups,
                Bulk (Just ByteString
"first-entry"),          Reply
rawFirstEntry ,
                Bulk (Just ByteString
"last-entry"),           Reply
rawLastEntry ])) = do
                    xinfoStreamFirstEntry <- Reply -> Either Reply StreamsRecord
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
rawFirstEntry
                    xinfoStreamLastEntry  <- decode rawLastEntry
                    return XInfoStreamResponse{
                          xinfoMaxDeletedEntryId    = Just xinfoMaxDeletedEntryId
                        , xinfoEntriesAdded         = Just xinfoEntriesAdded
                        , xinfoRecordedFirstEntryId = Just xinfoRecordedFirstEntryId
                        , ..}
            decodeRedis7 Reply
a = Reply -> Either Reply XInfoStreamResponse
forall a b. a -> Either a b
Left Reply
a

-- | Get info about a stream. The Redis command @XINFO@ is split into 'xinfoConsumers', 'xinfoGroups', and 'xinfoStream'.
-- Since Redis 5.0.0
xinfoStream
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> m (f XInfoStreamResponse)
xinfoStream :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f XInfoStreamResponse)
xinfoStream ByteString
stream = [ByteString] -> m (f XInfoStreamResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"XINFO", ByteString
"STREAM", ByteString
stream]

-- | Delete messages from a stream.
-- Since Redis 5.0.0
xdel
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> NonEmpty ByteString -- ^ message IDs
    -> m (f Integer)
xdel :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> m (f Integer)
xdel ByteString
stream (ByteString
messageId:|[ByteString]
messageIds) = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest (ByteString
"XDEL"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:ByteString
streamByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:ByteString
messageIdByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
messageIds)

-- |Conditionally deletes entries from a stream (<https://redis.io/commands/xdelex>).
--
-- /O(1)/ for each entry ID processed.
--
-- Since Redis 8.2.0
xdelex
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> NonEmpty ByteString -- ^ Entry IDs.
    -> m (f [XEntryDeletionResult])
xdelex :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> m (f [XEntryDeletionResult])
xdelex ByteString
stream NonEmpty ByteString
messageIds =
    ByteString
-> NonEmpty ByteString
-> XEntryDeletionOpts
-> m (f [XEntryDeletionResult])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty ByteString
-> XEntryDeletionOpts
-> m (f [XEntryDeletionResult])
xdelexOpts ByteString
stream NonEmpty ByteString
messageIds XEntryDeletionOpts
defaultXEntryDeletionOpts

-- |Conditionally deletes entries from a stream (<https://redis.io/commands/xdelex>).
--
-- /O(1)/ for each entry ID processed.
--
-- Since Redis 8.2.0
xdelexOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Stream name.
    -> NonEmpty ByteString -- ^ Entry IDs.
    -> XEntryDeletionOpts -- ^ Additional options.
    -> m (f [XEntryDeletionResult])
xdelexOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> NonEmpty ByteString
-> XEntryDeletionOpts
-> m (f [XEntryDeletionResult])
xdelexOpts ByteString
stream NonEmpty ByteString
messageIds XEntryDeletionOpts
opts =
    [ByteString] -> m (f [XEntryDeletionResult])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [XEntryDeletionResult]))
-> [ByteString] -> m (f [XEntryDeletionResult])
forall a b. (a -> b) -> a -> b
$ [ByteString
"XDELEX", ByteString
stream]
        [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ XEntryDeletionOpts -> [ByteString]
xEntryDeletionOptsToArgs XEntryDeletionOpts
opts
        [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
xEntryIdsBlockArgs NonEmpty ByteString
messageIds

-- |Sets the IDMP configuration parameters for a stream (<https://redis.io/commands/xcfgset>).
--
-- /O(1)/
--
-- Since Redis 8.6.0
xcfgset
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the stream key. The stream must already exist.
    -> XCfgSetOpts
    {- ^ Configuration parameters.

       At least one of `xCfgSetIdmpDuration` or `xCfgSetIdmpMaxsize` must be specified.
       Calling `XCFGSET` clears all existing producer IDMP maps for the stream.
     -}
    -> m (f Status)
xcfgset :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> XCfgSetOpts -> m (f Status)
xcfgset ByteString
key XCfgSetOpts{Maybe Integer
xCfgSetIdmpDuration :: XCfgSetOpts -> Maybe Integer
xCfgSetIdmpMaxsize :: XCfgSetOpts -> Maybe Integer
xCfgSetIdmpDuration :: Maybe Integer
xCfgSetIdmpMaxsize :: Maybe Integer
..} =
    [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
"XCFGSET", ByteString
key]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
duration -> [ByteString
"IDMP-DURATION", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
duration]) Maybe Integer
xCfgSetIdmpDuration
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
maxsize -> [ByteString
"IDMP-MAXSIZE", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
maxsize]) Maybe Integer
xCfgSetIdmpMaxsize

-- |Sets IDMP metadata on an existing stream message (<https://redis.io/commands/xidmprecord>).
--
-- This is an internal command used during AOF loading.
--
-- /O(1)/
--
-- Since Redis 8.6.2
xidmprecord
    :: (RedisCtx m f)
    => ByteString -- ^ Stream key.
    -> ByteString -- ^ Producer ID.
    -> ByteString -- ^ Idempotency ID.
    -> ByteString -- ^ Existing stream entry ID.
    -> m (f Status)
xidmprecord :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> ByteString -> ByteString -> m (f Status)
xidmprecord ByteString
key ByteString
producerId ByteString
idempotencyId ByteString
streamId =
    [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"XIDMPRECORD", ByteString
key, ByteString
producerId, ByteString
idempotencyId, ByteString
streamId]

-- |Releases claimed messages back to the group's PEL without acknowledging them (<https://redis.io/commands/xnack>).
--
-- /O(1)/ for each message ID processed.
--
-- Since Redis 8.8.0
xnack
    :: (RedisCtx m f)
    => ByteString -- ^ Stream key.
    -> ByteString -- ^ Consumer group name.
    -> XNackMode -- ^ Release strategy.
    -> NonEmpty ByteString -- ^ Stream entry IDs.
    -> m (f Integer)
xnack :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString -> XNackMode -> NonEmpty ByteString -> m (f Integer)
xnack ByteString
key ByteString
groupName XNackMode
mode NonEmpty ByteString
messageIds =
    ByteString
-> ByteString
-> XNackMode
-> NonEmpty ByteString
-> XNackOpts
-> m (f Integer)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> XNackMode
-> NonEmpty ByteString
-> XNackOpts
-> m (f Integer)
xnackOpts ByteString
key ByteString
groupName XNackMode
mode NonEmpty ByteString
messageIds XNackOpts
defaultXNackOpts

-- |Releases claimed messages back to the group's PEL without acknowledging them (<https://redis.io/commands/xnack>).
--
-- /O(1)/ for each message ID processed.
--
-- Since Redis 8.8.0
xnackOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Stream key.
    -> ByteString -- ^ Consumer group name.
    -> XNackMode -- ^ Release strategy.
    -> NonEmpty ByteString -- ^ Stream entry IDs.
    -> XNackOpts -- ^ Additional options.
    -> m (f Integer)
xnackOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> XNackMode
-> NonEmpty ByteString
-> XNackOpts
-> m (f Integer)
xnackOpts ByteString
key ByteString
groupName XNackMode
mode NonEmpty ByteString
messageIds XNackOpts{Bool
Maybe Integer
xNackRetryCount :: XNackOpts -> Maybe Integer
xNackForce :: XNackOpts -> Bool
xNackRetryCount :: Maybe Integer
xNackForce :: Bool
..} =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$
        [ByteString
"XNACK", ByteString
key, ByteString
groupName, XNackMode -> ByteString
forall a. RedisArg a => a -> ByteString
encode XNackMode
mode]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
xEntryIdsBlockArgs NonEmpty ByteString
messageIds
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
retryCount -> [ByteString
"RETRYCOUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
retryCount]) Maybe Integer
xNackRetryCount
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"FORCE" | Bool
xNackForce]

-- |Set the upper bound for number of messages in a stream. Since Redis 5.0.0
xtrim
    :: (RedisCtx m f)
    => ByteString -- ^ stream
    -> TrimOpts
    -> m (f Integer)
xtrim :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> TrimOpts -> m (f Integer)
xtrim ByteString
stream TrimOpts
opts = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest (ByteString
"XTRIM"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:ByteString
streamByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:TrimOpts -> [ByteString]
internalTrimArgToList TrimOpts
opts)

-- |Constructor for `inf` Redis argument values
inf :: RealFloat a => a
inf :: forall a. RealFloat a => a
inf = a
1 a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
0

-- | Additional parameters for the auth command.
data AuthOpts = AuthOpts
  { AuthOpts -> Maybe ByteString
authOptsUsername
    :: Maybe ByteString
    {- ^ Username.

      Since Redis 6.0: fails on earlier
     -}
  }
  deriving Int -> AuthOpts -> ShowS
[AuthOpts] -> ShowS
AuthOpts -> String
(Int -> AuthOpts -> ShowS)
-> (AuthOpts -> String) -> ([AuthOpts] -> ShowS) -> Show AuthOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AuthOpts -> ShowS
showsPrec :: Int -> AuthOpts -> ShowS
$cshow :: AuthOpts -> String
show :: AuthOpts -> String
$cshowList :: [AuthOpts] -> ShowS
showList :: [AuthOpts] -> ShowS
Show

-- | Default options for AuthOpts
--
-- >>> defaultAuthOpts
-- AuthOpts {authOptsUsername = Nothing}
defaultAuthOpts :: AuthOpts
defaultAuthOpts :: AuthOpts
defaultAuthOpts = AuthOpts
  { authOptsUsername :: Maybe ByteString
authOptsUsername = Maybe ByteString
forall a. Maybe a
Nothing
  }

-- | /O(N)/ where N is the number of passwords defined for the user.
--
-- Authenticates client to the server.
auth
    :: RedisCtx m f
    => ByteString -- ^ Password.
    -> m (f Status)
auth :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Status)
auth ByteString
password = ByteString -> AuthOpts -> m (f Status)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> AuthOpts -> m (f Status)
authOpts ByteString
password AuthOpts
defaultAuthOpts

-- | /O(N)/ where N is the number of passwords defined for the user.
--
-- Authenticates client to the server.
--
-- This method allows passing additional options.
authOpts
    :: RedisCtx m f
    => ByteString -- ^ Password.
    -> AuthOpts -- ^ Additional options.
    -> m (f Status)
authOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> AuthOpts -> m (f Status)
authOpts ByteString
password AuthOpts{Maybe ByteString
authOptsUsername :: AuthOpts -> Maybe ByteString
authOptsUsername :: Maybe ByteString
..} = [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
"AUTH"] [ByteString] -> [ByteString] -> [ByteString]
forall a. Semigroup a => a -> a -> a
<> [ByteString]
-> (ByteString -> [ByteString]) -> Maybe ByteString -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[]) Maybe ByteString
authOptsUsername [ByteString] -> [ByteString] -> [ByteString]
forall a. Semigroup a => a -> a -> a
<> [ByteString
password]

-- |Change the selected database for the current connection (<http://redis.io/commands/select>). Since Redis 1.0.0
select
    :: RedisCtx m f
    => Integer -- ^ index
    -> m (f Status)
select :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Integer -> m (f Status)
select Integer
ix = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SELECT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
ix]

-- |Ping the server (<http://redis.io/commands/ping>). Since Redis 1.0.0
ping
    :: (RedisCtx m f)
    => m (f Status)
ping :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Status)
ping  = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString
"PING"] )

-- https://redis.io/commands/cluster-info/
data ClusterInfoResponse = ClusterInfoResponse
  { ClusterInfoResponse -> ClusterInfoResponseState
clusterInfoResponseState :: ClusterInfoResponseState,
    ClusterInfoResponse -> Integer
clusterInfoResponseSlotsAssigned :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseSlotsOK :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseSlotsPfail :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseSlotsFail :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseKnownNodes :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseSize :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseCurrentEpoch :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseMyEpoch :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseStatsMessagesSent :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseStatsMessagesReceived :: Integer,
    ClusterInfoResponse -> Integer
clusterInfoResponseTotalLinksBufferLimitExceeded :: Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesPingSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesPingReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesPongSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesPongReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesMeetSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesMeetReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesFailSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesFailReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesPublishSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesPublishReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesAuthReqSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesAuthReqReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesAuthAckSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesAuthAckReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesUpdateSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesUpdateReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesMfstartSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesMfstartReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesModuleSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesModuleReceived :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesPublishshardSent :: Maybe Integer,
    ClusterInfoResponse -> Maybe Integer
clusterInfoResponseStatsMessagesPublishshardReceived :: Maybe Integer
  }
  deriving (Int -> ClusterInfoResponse -> ShowS
[ClusterInfoResponse] -> ShowS
ClusterInfoResponse -> String
(Int -> ClusterInfoResponse -> ShowS)
-> (ClusterInfoResponse -> String)
-> ([ClusterInfoResponse] -> ShowS)
-> Show ClusterInfoResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterInfoResponse -> ShowS
showsPrec :: Int -> ClusterInfoResponse -> ShowS
$cshow :: ClusterInfoResponse -> String
show :: ClusterInfoResponse -> String
$cshowList :: [ClusterInfoResponse] -> ShowS
showList :: [ClusterInfoResponse] -> ShowS
Show, ClusterInfoResponse -> ClusterInfoResponse -> Bool
(ClusterInfoResponse -> ClusterInfoResponse -> Bool)
-> (ClusterInfoResponse -> ClusterInfoResponse -> Bool)
-> Eq ClusterInfoResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterInfoResponse -> ClusterInfoResponse -> Bool
== :: ClusterInfoResponse -> ClusterInfoResponse -> Bool
$c/= :: ClusterInfoResponse -> ClusterInfoResponse -> Bool
/= :: ClusterInfoResponse -> ClusterInfoResponse -> Bool
Eq)

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

defClusterInfoResponse :: ClusterInfoResponse
defClusterInfoResponse :: ClusterInfoResponse
defClusterInfoResponse =
  ClusterInfoResponse
    { clusterInfoResponseState :: ClusterInfoResponseState
clusterInfoResponseState = ClusterInfoResponseState
Down,
      clusterInfoResponseSlotsAssigned :: Integer
clusterInfoResponseSlotsAssigned = Integer
0,
      clusterInfoResponseSlotsOK :: Integer
clusterInfoResponseSlotsOK = Integer
0,
      clusterInfoResponseSlotsPfail :: Integer
clusterInfoResponseSlotsPfail = Integer
0,
      clusterInfoResponseSlotsFail :: Integer
clusterInfoResponseSlotsFail = Integer
0,
      clusterInfoResponseKnownNodes :: Integer
clusterInfoResponseKnownNodes = Integer
0,
      clusterInfoResponseSize :: Integer
clusterInfoResponseSize = Integer
0,
      clusterInfoResponseCurrentEpoch :: Integer
clusterInfoResponseCurrentEpoch = Integer
0,
      clusterInfoResponseMyEpoch :: Integer
clusterInfoResponseMyEpoch = Integer
0,
      clusterInfoResponseStatsMessagesSent :: Integer
clusterInfoResponseStatsMessagesSent = Integer
0,
      clusterInfoResponseStatsMessagesReceived :: Integer
clusterInfoResponseStatsMessagesReceived = Integer
0,
      clusterInfoResponseTotalLinksBufferLimitExceeded :: Integer
clusterInfoResponseTotalLinksBufferLimitExceeded = Integer
0,
      clusterInfoResponseStatsMessagesPingSent :: Maybe Integer
clusterInfoResponseStatsMessagesPingSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesPingReceived :: Maybe Integer
clusterInfoResponseStatsMessagesPingReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesPongSent :: Maybe Integer
clusterInfoResponseStatsMessagesPongSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesPongReceived :: Maybe Integer
clusterInfoResponseStatsMessagesPongReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesMeetSent :: Maybe Integer
clusterInfoResponseStatsMessagesMeetSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesMeetReceived :: Maybe Integer
clusterInfoResponseStatsMessagesMeetReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesFailSent :: Maybe Integer
clusterInfoResponseStatsMessagesFailSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesFailReceived :: Maybe Integer
clusterInfoResponseStatsMessagesFailReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesPublishSent :: Maybe Integer
clusterInfoResponseStatsMessagesPublishSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesPublishReceived :: Maybe Integer
clusterInfoResponseStatsMessagesPublishReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesAuthReqSent :: Maybe Integer
clusterInfoResponseStatsMessagesAuthReqSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesAuthReqReceived :: Maybe Integer
clusterInfoResponseStatsMessagesAuthReqReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesAuthAckSent :: Maybe Integer
clusterInfoResponseStatsMessagesAuthAckSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesAuthAckReceived :: Maybe Integer
clusterInfoResponseStatsMessagesAuthAckReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesUpdateSent :: Maybe Integer
clusterInfoResponseStatsMessagesUpdateSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesUpdateReceived :: Maybe Integer
clusterInfoResponseStatsMessagesUpdateReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesMfstartSent :: Maybe Integer
clusterInfoResponseStatsMessagesMfstartSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesMfstartReceived :: Maybe Integer
clusterInfoResponseStatsMessagesMfstartReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesModuleSent :: Maybe Integer
clusterInfoResponseStatsMessagesModuleSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesModuleReceived :: Maybe Integer
clusterInfoResponseStatsMessagesModuleReceived = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesPublishshardSent :: Maybe Integer
clusterInfoResponseStatsMessagesPublishshardSent = Maybe Integer
forall a. Maybe a
Nothing,
      clusterInfoResponseStatsMessagesPublishshardReceived :: Maybe Integer
clusterInfoResponseStatsMessagesPublishshardReceived = Maybe Integer
forall a. Maybe a
Nothing
    }

parseClusterInfoResponse :: [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse :: [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fields ClusterInfoResponse
resp = case [[ByteString]]
fields of
  [] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ClusterInfoResponse
resp
  ([ByteString
"cluster_state", ByteString
state] : [[ByteString]]
fs) -> ByteString -> Maybe ClusterInfoResponseState
forall {a}.
(Eq a, IsString a) =>
a -> Maybe ClusterInfoResponseState
parseState ByteString
state Maybe ClusterInfoResponseState
-> (ClusterInfoResponseState -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ClusterInfoResponseState
s -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseState = s}
  ([ByteString
"cluster_slots_assigned", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseSlotsAssigned = v}
  ([ByteString
"cluster_slots_ok", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseSlotsOK = v}
  ([ByteString
"cluster_slots_pfail", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseSlotsPfail = v}
  ([ByteString
"cluster_slots_fail", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseSlotsFail = v}
  ([ByteString
"cluster_known_nodes", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseKnownNodes = v}
  ([ByteString
"cluster_size", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseSize = v}
  ([ByteString
"cluster_current_epoch", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseCurrentEpoch = v}
  ([ByteString
"cluster_my_epoch", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseMyEpoch = v}
  ([ByteString
"cluster_stats_messages_sent", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesSent = v}
  ([ByteString
"cluster_stats_messages_received", ByteString
value] : [[ByteString]]
fs) -> ByteString -> Maybe Integer
parseInteger ByteString
value Maybe Integer
-> (Integer -> Maybe ClusterInfoResponse)
-> Maybe ClusterInfoResponse
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Integer
v -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesReceived = v}
  ([ByteString
"total_cluster_links_buffer_limit_exceeded", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseTotalLinksBufferLimitExceeded = fromMaybe 0 $ parseInteger value} -- this value should be mandatory according to the spec, but isn't necessarily set in Redis 6
  ([ByteString
"cluster_stats_messages_ping_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesPingSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_ping_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesPingReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_pong_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesPongSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_pong_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesPongReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_meet_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesMeetSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_meet_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesMeetReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_fail_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesFailSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_fail_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesFailReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_publish_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesPublishSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_publish_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesPublishReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_auth_req_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesAuthReqSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_auth_req_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesAuthReqReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_auth_ack_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesAuthAckSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_auth_ack_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesAuthAckReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_update_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesUpdateSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_update_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesUpdateReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_mfstart_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesMfstartSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_mfstart_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesMfstartReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_module_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesModuleSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_module_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesModuleReceived = parseInteger value}
  ([ByteString
"cluster_stats_messages_publishshard_sent", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesPublishshardSent = parseInteger value}
  ([ByteString
"cluster_stats_messages_publishshard_received", ByteString
value] : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs (ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse -> Maybe ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ClusterInfoResponse
resp {clusterInfoResponseStatsMessagesPublishshardReceived = parseInteger value}
  ([ByteString]
_ : [[ByteString]]
fs) -> [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse [[ByteString]]
fs ClusterInfoResponse
resp
  where
    parseState :: a -> Maybe ClusterInfoResponseState
parseState a
bs = case a
bs of
      a
"ok" -> ClusterInfoResponseState -> Maybe ClusterInfoResponseState
forall a. a -> Maybe a
Just ClusterInfoResponseState
OK
      a
"fail" -> ClusterInfoResponseState -> Maybe ClusterInfoResponseState
forall a. a -> Maybe a
Just ClusterInfoResponseState
Down
      a
_ -> Maybe ClusterInfoResponseState
forall a. Maybe a
Nothing
    parseInteger :: ByteString -> Maybe Integer
parseInteger = ((Integer, ByteString) -> Integer)
-> Maybe (Integer, ByteString) -> Maybe Integer
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Integer, ByteString) -> Integer
forall a b. (a, b) -> a
fst (Maybe (Integer, ByteString) -> Maybe Integer)
-> (ByteString -> Maybe (Integer, ByteString))
-> ByteString
-> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Maybe (Integer, ByteString)
Char8.readInteger

instance RedisResult ClusterInfoResponse where
  decode :: Reply -> Either Reply ClusterInfoResponse
decode r :: Reply
r@(Bulk (Just ByteString
bulkData)) =
    Either Reply ClusterInfoResponse
-> (ClusterInfoResponse -> Either Reply ClusterInfoResponse)
-> Maybe ClusterInfoResponse
-> Either Reply ClusterInfoResponse
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Reply -> Either Reply ClusterInfoResponse
forall a b. a -> Either a b
Left Reply
r) ClusterInfoResponse -> Either Reply ClusterInfoResponse
forall a b. b -> Either a b
Right
      (Maybe ClusterInfoResponse -> Either Reply ClusterInfoResponse)
-> ([ByteString] -> Maybe ClusterInfoResponse)
-> [ByteString]
-> Either Reply ClusterInfoResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([[ByteString]]
 -> ClusterInfoResponse -> Maybe ClusterInfoResponse)
-> ClusterInfoResponse
-> [[ByteString]]
-> Maybe ClusterInfoResponse
forall a b c. (a -> b -> c) -> b -> a -> c
flip [[ByteString]] -> ClusterInfoResponse -> Maybe ClusterInfoResponse
parseClusterInfoResponse ClusterInfoResponse
defClusterInfoResponse
      ([[ByteString]] -> Maybe ClusterInfoResponse)
-> ([ByteString] -> [[ByteString]])
-> [ByteString]
-> Maybe ClusterInfoResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString]) -> [ByteString] -> [[ByteString]]
forall a b. (a -> b) -> [a] -> [b]
map (Char -> ByteString -> [ByteString]
Char8.split Char
':' (ByteString -> [ByteString])
-> (ByteString -> ByteString) -> ByteString -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ByteString -> ByteString
Char8.takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\r'))
      ([ByteString] -> Either Reply ClusterInfoResponse)
-> [ByteString] -> Either Reply ClusterInfoResponse
forall a b. (a -> b) -> a -> b
$ ByteString -> [ByteString]
Char8.lines ByteString
bulkData
  decode Reply
r = Reply -> Either Reply ClusterInfoResponse
forall a b. a -> Either a b
Left Reply
r

clusterInfo :: RedisCtx m f => m (f ClusterInfoResponse)
clusterInfo :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f ClusterInfoResponse)
clusterInfo = [ByteString] -> m (f ClusterInfoResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"INFO"]

-- |Returns the shard ID of a node (<https://redis.io/commands/cluster-myshardid>).
--
-- /O(1)/
--
-- Since Redis 7.2.0
clusterMyshardid
    :: (RedisCtx m f)
    => m (f ByteString)
clusterMyshardid :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f ByteString)
clusterMyshardid = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"MYSHARDID"]

data ClusterNodesResponse = ClusterNodesResponse
    { ClusterNodesResponse -> [ClusterNodesResponseEntry]
clusterNodesResponseEntries :: [ClusterNodesResponseEntry]
    } deriving (Int -> ClusterNodesResponse -> ShowS
[ClusterNodesResponse] -> ShowS
ClusterNodesResponse -> String
(Int -> ClusterNodesResponse -> ShowS)
-> (ClusterNodesResponse -> String)
-> ([ClusterNodesResponse] -> ShowS)
-> Show ClusterNodesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterNodesResponse -> ShowS
showsPrec :: Int -> ClusterNodesResponse -> ShowS
$cshow :: ClusterNodesResponse -> String
show :: ClusterNodesResponse -> String
$cshowList :: [ClusterNodesResponse] -> ShowS
showList :: [ClusterNodesResponse] -> ShowS
Show, ClusterNodesResponse -> ClusterNodesResponse -> Bool
(ClusterNodesResponse -> ClusterNodesResponse -> Bool)
-> (ClusterNodesResponse -> ClusterNodesResponse -> Bool)
-> Eq ClusterNodesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterNodesResponse -> ClusterNodesResponse -> Bool
== :: ClusterNodesResponse -> ClusterNodesResponse -> Bool
$c/= :: ClusterNodesResponse -> ClusterNodesResponse -> Bool
/= :: ClusterNodesResponse -> ClusterNodesResponse -> Bool
Eq)

data ClusterNodesResponseEntry = ClusterNodesResponseEntry { ClusterNodesResponseEntry -> ByteString
clusterNodesResponseNodeId :: ByteString
    , ClusterNodesResponseEntry -> ByteString
clusterNodesResponseNodeIp :: ByteString
    , ClusterNodesResponseEntry -> Integer
clusterNodesResponseNodePort :: Integer
    , ClusterNodesResponseEntry -> [ByteString]
clusterNodesResponseNodeFlags :: [ByteString]
    , ClusterNodesResponseEntry -> Maybe ByteString
clusterNodesResponseMasterId :: Maybe ByteString
    , ClusterNodesResponseEntry -> Integer
clusterNodesResponsePingSent :: Integer
    , ClusterNodesResponseEntry -> Integer
clusterNodesResponsePongReceived :: Integer
    , ClusterNodesResponseEntry -> Integer
clusterNodesResponseConfigEpoch :: Integer
    , ClusterNodesResponseEntry -> ByteString
clusterNodesResponseLinkState :: ByteString
    , ClusterNodesResponseEntry -> [ClusterNodesResponseSlotSpec]
clusterNodesResponseSlots :: [ClusterNodesResponseSlotSpec]
    } deriving (Int -> ClusterNodesResponseEntry -> ShowS
[ClusterNodesResponseEntry] -> ShowS
ClusterNodesResponseEntry -> String
(Int -> ClusterNodesResponseEntry -> ShowS)
-> (ClusterNodesResponseEntry -> String)
-> ([ClusterNodesResponseEntry] -> ShowS)
-> Show ClusterNodesResponseEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterNodesResponseEntry -> ShowS
showsPrec :: Int -> ClusterNodesResponseEntry -> ShowS
$cshow :: ClusterNodesResponseEntry -> String
show :: ClusterNodesResponseEntry -> String
$cshowList :: [ClusterNodesResponseEntry] -> ShowS
showList :: [ClusterNodesResponseEntry] -> ShowS
Show, ClusterNodesResponseEntry -> ClusterNodesResponseEntry -> Bool
(ClusterNodesResponseEntry -> ClusterNodesResponseEntry -> Bool)
-> (ClusterNodesResponseEntry -> ClusterNodesResponseEntry -> Bool)
-> Eq ClusterNodesResponseEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterNodesResponseEntry -> ClusterNodesResponseEntry -> Bool
== :: ClusterNodesResponseEntry -> ClusterNodesResponseEntry -> Bool
$c/= :: ClusterNodesResponseEntry -> ClusterNodesResponseEntry -> Bool
/= :: ClusterNodesResponseEntry -> ClusterNodesResponseEntry -> Bool
Eq)

data ClusterNodesResponseSlotSpec
    = ClusterNodesResponseSingleSlot Integer
    | ClusterNodesResponseSlotRange Integer Integer
    | ClusterNodesResponseSlotImporting Integer ByteString
    | ClusterNodesResponseSlotMigrating Integer ByteString deriving (Int -> ClusterNodesResponseSlotSpec -> ShowS
[ClusterNodesResponseSlotSpec] -> ShowS
ClusterNodesResponseSlotSpec -> String
(Int -> ClusterNodesResponseSlotSpec -> ShowS)
-> (ClusterNodesResponseSlotSpec -> String)
-> ([ClusterNodesResponseSlotSpec] -> ShowS)
-> Show ClusterNodesResponseSlotSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterNodesResponseSlotSpec -> ShowS
showsPrec :: Int -> ClusterNodesResponseSlotSpec -> ShowS
$cshow :: ClusterNodesResponseSlotSpec -> String
show :: ClusterNodesResponseSlotSpec -> String
$cshowList :: [ClusterNodesResponseSlotSpec] -> ShowS
showList :: [ClusterNodesResponseSlotSpec] -> ShowS
Show, ClusterNodesResponseSlotSpec
-> ClusterNodesResponseSlotSpec -> Bool
(ClusterNodesResponseSlotSpec
 -> ClusterNodesResponseSlotSpec -> Bool)
-> (ClusterNodesResponseSlotSpec
    -> ClusterNodesResponseSlotSpec -> Bool)
-> Eq ClusterNodesResponseSlotSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterNodesResponseSlotSpec
-> ClusterNodesResponseSlotSpec -> Bool
== :: ClusterNodesResponseSlotSpec
-> ClusterNodesResponseSlotSpec -> Bool
$c/= :: ClusterNodesResponseSlotSpec
-> ClusterNodesResponseSlotSpec -> Bool
/= :: ClusterNodesResponseSlotSpec
-> ClusterNodesResponseSlotSpec -> Bool
Eq)


instance RedisResult ClusterNodesResponse where
    decode :: Reply -> Either Reply ClusterNodesResponse
decode r :: Reply
r@(Bulk (Just ByteString
bulkData)) = Either Reply ClusterNodesResponse
-> (ClusterNodesResponse -> Either Reply ClusterNodesResponse)
-> Maybe ClusterNodesResponse
-> Either Reply ClusterNodesResponse
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Reply -> Either Reply ClusterNodesResponse
forall a b. a -> Either a b
Left Reply
r) ClusterNodesResponse -> Either Reply ClusterNodesResponse
forall a b. b -> Either a b
Right (Maybe ClusterNodesResponse -> Either Reply ClusterNodesResponse)
-> Maybe ClusterNodesResponse -> Either Reply ClusterNodesResponse
forall a b. (a -> b) -> a -> b
$ do
        infos <- (ByteString -> Maybe ClusterNodesResponseEntry)
-> [ByteString] -> Maybe [ClusterNodesResponseEntry]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ByteString -> Maybe ClusterNodesResponseEntry
parseNodeInfo ([ByteString] -> Maybe [ClusterNodesResponseEntry])
-> [ByteString] -> Maybe [ClusterNodesResponseEntry]
forall a b. (a -> b) -> a -> b
$ ByteString -> [ByteString]
Char8.lines ByteString
bulkData
        return $ ClusterNodesResponse infos where
            parseNodeInfo :: ByteString -> Maybe ClusterNodesResponseEntry
            parseNodeInfo :: ByteString -> Maybe ClusterNodesResponseEntry
parseNodeInfo ByteString
line = case ByteString -> [ByteString]
Char8.words ByteString
line of
              (ByteString
nodeId : ByteString
hostNamePort : ByteString
flags : ByteString
masterNodeId : ByteString
pingSent : ByteString
pongRecv : ByteString
epoch : ByteString
linkState : [ByteString]
slots) ->
                case Char -> ByteString -> [ByteString]
Char8.split Char
':' ByteString
hostNamePort of
                  [ByteString
hostName, ByteString
port] -> ByteString
-> ByteString
-> Integer
-> [ByteString]
-> Maybe ByteString
-> Integer
-> Integer
-> Integer
-> ByteString
-> [ClusterNodesResponseSlotSpec]
-> ClusterNodesResponseEntry
ClusterNodesResponseEntry (ByteString
 -> ByteString
 -> Integer
 -> [ByteString]
 -> Maybe ByteString
 -> Integer
 -> Integer
 -> Integer
 -> ByteString
 -> [ClusterNodesResponseSlotSpec]
 -> ClusterNodesResponseEntry)
-> Maybe ByteString
-> Maybe
     (ByteString
      -> Integer
      -> [ByteString]
      -> Maybe ByteString
      -> Integer
      -> Integer
      -> Integer
      -> ByteString
      -> [ClusterNodesResponseSlotSpec]
      -> ClusterNodesResponseEntry)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe ByteString
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByteString
nodeId
                                               Maybe
  (ByteString
   -> Integer
   -> [ByteString]
   -> Maybe ByteString
   -> Integer
   -> Integer
   -> Integer
   -> ByteString
   -> [ClusterNodesResponseSlotSpec]
   -> ClusterNodesResponseEntry)
-> Maybe ByteString
-> Maybe
     (Integer
      -> [ByteString]
      -> Maybe ByteString
      -> Integer
      -> Integer
      -> Integer
      -> ByteString
      -> [ClusterNodesResponseSlotSpec]
      -> ClusterNodesResponseEntry)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Maybe ByteString
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByteString
hostName
                                               Maybe
  (Integer
   -> [ByteString]
   -> Maybe ByteString
   -> Integer
   -> Integer
   -> Integer
   -> ByteString
   -> [ClusterNodesResponseSlotSpec]
   -> ClusterNodesResponseEntry)
-> Maybe Integer
-> Maybe
     ([ByteString]
      -> Maybe ByteString
      -> Integer
      -> Integer
      -> Integer
      -> ByteString
      -> [ClusterNodesResponseSlotSpec]
      -> ClusterNodesResponseEntry)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Maybe Integer
readInteger ByteString
port
                                               Maybe
  ([ByteString]
   -> Maybe ByteString
   -> Integer
   -> Integer
   -> Integer
   -> ByteString
   -> [ClusterNodesResponseSlotSpec]
   -> ClusterNodesResponseEntry)
-> Maybe [ByteString]
-> Maybe
     (Maybe ByteString
      -> Integer
      -> Integer
      -> Integer
      -> ByteString
      -> [ClusterNodesResponseSlotSpec]
      -> ClusterNodesResponseEntry)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [ByteString] -> Maybe [ByteString]
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Char -> ByteString -> [ByteString]
Char8.split Char
',' ByteString
flags)
                                               Maybe
  (Maybe ByteString
   -> Integer
   -> Integer
   -> Integer
   -> ByteString
   -> [ClusterNodesResponseSlotSpec]
   -> ClusterNodesResponseEntry)
-> Maybe (Maybe ByteString)
-> Maybe
     (Integer
      -> Integer
      -> Integer
      -> ByteString
      -> [ClusterNodesResponseSlotSpec]
      -> ClusterNodesResponseEntry)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe ByteString -> Maybe (Maybe ByteString)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ByteString -> Maybe ByteString
readMasterNodeId ByteString
masterNodeId)
                                               Maybe
  (Integer
   -> Integer
   -> Integer
   -> ByteString
   -> [ClusterNodesResponseSlotSpec]
   -> ClusterNodesResponseEntry)
-> Maybe Integer
-> Maybe
     (Integer
      -> Integer
      -> ByteString
      -> [ClusterNodesResponseSlotSpec]
      -> ClusterNodesResponseEntry)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Maybe Integer
readInteger ByteString
pingSent
                                               Maybe
  (Integer
   -> Integer
   -> ByteString
   -> [ClusterNodesResponseSlotSpec]
   -> ClusterNodesResponseEntry)
-> Maybe Integer
-> Maybe
     (Integer
      -> ByteString
      -> [ClusterNodesResponseSlotSpec]
      -> ClusterNodesResponseEntry)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Maybe Integer
readInteger ByteString
pongRecv
                                               Maybe
  (Integer
   -> ByteString
   -> [ClusterNodesResponseSlotSpec]
   -> ClusterNodesResponseEntry)
-> Maybe Integer
-> Maybe
     (ByteString
      -> [ClusterNodesResponseSlotSpec] -> ClusterNodesResponseEntry)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Maybe Integer
readInteger ByteString
epoch
                                               Maybe
  (ByteString
   -> [ClusterNodesResponseSlotSpec] -> ClusterNodesResponseEntry)
-> Maybe ByteString
-> Maybe
     ([ClusterNodesResponseSlotSpec] -> ClusterNodesResponseEntry)
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ByteString -> Maybe ByteString
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByteString
linkState
                                               Maybe ([ClusterNodesResponseSlotSpec] -> ClusterNodesResponseEntry)
-> Maybe [ClusterNodesResponseSlotSpec]
-> Maybe ClusterNodesResponseEntry
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([ClusterNodesResponseSlotSpec]
-> Maybe [ClusterNodesResponseSlotSpec]
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([ClusterNodesResponseSlotSpec]
 -> Maybe [ClusterNodesResponseSlotSpec])
-> ([Maybe ClusterNodesResponseSlotSpec]
    -> [ClusterNodesResponseSlotSpec])
-> [Maybe ClusterNodesResponseSlotSpec]
-> Maybe [ClusterNodesResponseSlotSpec]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe ClusterNodesResponseSlotSpec]
-> [ClusterNodesResponseSlotSpec]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe ClusterNodesResponseSlotSpec]
 -> Maybe [ClusterNodesResponseSlotSpec])
-> [Maybe ClusterNodesResponseSlotSpec]
-> Maybe [ClusterNodesResponseSlotSpec]
forall a b. (a -> b) -> a -> b
$ (ByteString -> Maybe ClusterNodesResponseSlotSpec)
-> [ByteString] -> [Maybe ClusterNodesResponseSlotSpec]
forall a b. (a -> b) -> [a] -> [b]
map ByteString -> Maybe ClusterNodesResponseSlotSpec
readNodeSlot [ByteString]
slots)
                  [ByteString]
_ -> Maybe ClusterNodesResponseEntry
forall a. Maybe a
Nothing
              [ByteString]
_ -> Maybe ClusterNodesResponseEntry
forall a. Maybe a
Nothing
            readInteger :: ByteString -> Maybe Integer
            readInteger :: ByteString -> Maybe Integer
readInteger = ((Integer, ByteString) -> Integer)
-> Maybe (Integer, ByteString) -> Maybe Integer
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Integer, ByteString) -> Integer
forall a b. (a, b) -> a
fst (Maybe (Integer, ByteString) -> Maybe Integer)
-> (ByteString -> Maybe (Integer, ByteString))
-> ByteString
-> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Maybe (Integer, ByteString)
Char8.readInteger

            readMasterNodeId :: ByteString -> Maybe ByteString
            readMasterNodeId :: ByteString -> Maybe ByteString
readMasterNodeId ByteString
"-"    = Maybe ByteString
forall a. Maybe a
Nothing
            readMasterNodeId ByteString
nodeId = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
nodeId

            readNodeSlot :: ByteString -> Maybe ClusterNodesResponseSlotSpec
            readNodeSlot :: ByteString -> Maybe ClusterNodesResponseSlotSpec
readNodeSlot ByteString
slotSpec = case Char
'[' Char -> ByteString -> Bool
`Char8.elem` ByteString
slotSpec of
                Bool
True -> ByteString -> Maybe ClusterNodesResponseSlotSpec
readSlotImportMigrate ByteString
slotSpec
                Bool
False -> case Char
'-' Char -> ByteString -> Bool
`Char8.elem` ByteString
slotSpec of
                    Bool
True -> ByteString -> Maybe ClusterNodesResponseSlotSpec
readSlotRange ByteString
slotSpec
                    Bool
False -> Integer -> ClusterNodesResponseSlotSpec
ClusterNodesResponseSingleSlot (Integer -> ClusterNodesResponseSlotSpec)
-> Maybe Integer -> Maybe ClusterNodesResponseSlotSpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe Integer
readInteger ByteString
slotSpec
            readSlotImportMigrate :: ByteString -> Maybe ClusterNodesResponseSlotSpec
            readSlotImportMigrate :: ByteString -> Maybe ClusterNodesResponseSlotSpec
readSlotImportMigrate ByteString
slotSpec = case ByteString -> ByteString -> (ByteString, ByteString)
BS.breakSubstring ByteString
"->-" ByteString
slotSpec of
                (ByteString
_, ByteString
"") -> case ByteString -> ByteString -> (ByteString, ByteString)
BS.breakSubstring ByteString
"-<-" ByteString
slotSpec of
                    (ByteString
_, ByteString
"") -> Maybe ClusterNodesResponseSlotSpec
forall a. Maybe a
Nothing
                    (ByteString
leftPart, ByteString
rightPart) -> Integer -> ByteString -> ClusterNodesResponseSlotSpec
ClusterNodesResponseSlotImporting
                        (Integer -> ByteString -> ClusterNodesResponseSlotSpec)
-> Maybe Integer
-> Maybe (ByteString -> ClusterNodesResponseSlotSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ByteString -> Maybe Integer
readInteger (ByteString -> Maybe Integer) -> ByteString -> Maybe Integer
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> ByteString
Char8.drop Int
1 ByteString
leftPart)
                        Maybe (ByteString -> ClusterNodesResponseSlotSpec)
-> Maybe ByteString -> Maybe ClusterNodesResponseSlotSpec
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ByteString -> Maybe ByteString
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> ByteString
BS.take (ByteString -> Int
BS.length ByteString
rightPart Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
rightPart)
                (ByteString
leftPart, ByteString
rightPart) -> Integer -> ByteString -> ClusterNodesResponseSlotSpec
ClusterNodesResponseSlotMigrating
                    (Integer -> ByteString -> ClusterNodesResponseSlotSpec)
-> Maybe Integer
-> Maybe (ByteString -> ClusterNodesResponseSlotSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ByteString -> Maybe Integer
readInteger (ByteString -> Maybe Integer) -> ByteString -> Maybe Integer
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> ByteString
Char8.drop Int
1 ByteString
leftPart)
                    Maybe (ByteString -> ClusterNodesResponseSlotSpec)
-> Maybe ByteString -> Maybe ClusterNodesResponseSlotSpec
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ByteString -> Maybe ByteString
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> ByteString
BS.take (ByteString -> Int
BS.length ByteString
rightPart Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
rightPart)
            readSlotRange :: ByteString -> Maybe ClusterNodesResponseSlotSpec
            readSlotRange :: ByteString -> Maybe ClusterNodesResponseSlotSpec
readSlotRange ByteString
slotSpec = case ByteString -> ByteString -> (ByteString, ByteString)
BS.breakSubstring ByteString
"-" ByteString
slotSpec of
                (ByteString
_, ByteString
"") -> Maybe ClusterNodesResponseSlotSpec
forall a. Maybe a
Nothing
                (ByteString
leftPart, ByteString
rightPart) -> Integer -> Integer -> ClusterNodesResponseSlotSpec
ClusterNodesResponseSlotRange
                    (Integer -> Integer -> ClusterNodesResponseSlotSpec)
-> Maybe Integer -> Maybe (Integer -> ClusterNodesResponseSlotSpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe Integer
readInteger ByteString
leftPart
                    Maybe (Integer -> ClusterNodesResponseSlotSpec)
-> Maybe Integer -> Maybe ClusterNodesResponseSlotSpec
forall a b. Maybe (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ByteString -> Maybe Integer
readInteger (ByteString -> Maybe Integer) -> ByteString -> Maybe Integer
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> ByteString
BS.drop Int
1 ByteString
rightPart)

    decode Reply
r = Reply -> Either Reply ClusterNodesResponse
forall a b. a -> Either a b
Left Reply
r

clusterNodes
    :: (RedisCtx m f)
    => m (f ClusterNodesResponse)
clusterNodes :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f ClusterNodesResponse)
clusterNodes = [ByteString] -> m (f ClusterNodesResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f ClusterNodesResponse))
-> [ByteString] -> m (f ClusterNodesResponse)
forall a b. (a -> b) -> a -> b
$ [ByteString
"CLUSTER", ByteString
"NODES"]

data ClusterSlotsResponse = ClusterSlotsResponse { ClusterSlotsResponse -> [ClusterSlotsResponseEntry]
clusterSlotsResponseEntries :: [ClusterSlotsResponseEntry] } deriving (Int -> ClusterSlotsResponse -> ShowS
[ClusterSlotsResponse] -> ShowS
ClusterSlotsResponse -> String
(Int -> ClusterSlotsResponse -> ShowS)
-> (ClusterSlotsResponse -> String)
-> ([ClusterSlotsResponse] -> ShowS)
-> Show ClusterSlotsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterSlotsResponse -> ShowS
showsPrec :: Int -> ClusterSlotsResponse -> ShowS
$cshow :: ClusterSlotsResponse -> String
show :: ClusterSlotsResponse -> String
$cshowList :: [ClusterSlotsResponse] -> ShowS
showList :: [ClusterSlotsResponse] -> ShowS
Show)

data ClusterSlotsNode = ClusterSlotsNode
    { ClusterSlotsNode -> ByteString
clusterSlotsNodeIP :: ByteString
    , ClusterSlotsNode -> Int
clusterSlotsNodePort :: Int
    , ClusterSlotsNode -> ByteString
clusterSlotsNodeID :: ByteString
    } deriving (Int -> ClusterSlotsNode -> ShowS
[ClusterSlotsNode] -> ShowS
ClusterSlotsNode -> String
(Int -> ClusterSlotsNode -> ShowS)
-> (ClusterSlotsNode -> String)
-> ([ClusterSlotsNode] -> ShowS)
-> Show ClusterSlotsNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterSlotsNode -> ShowS
showsPrec :: Int -> ClusterSlotsNode -> ShowS
$cshow :: ClusterSlotsNode -> String
show :: ClusterSlotsNode -> String
$cshowList :: [ClusterSlotsNode] -> ShowS
showList :: [ClusterSlotsNode] -> ShowS
Show)

data ClusterSlotsResponseEntry = ClusterSlotsResponseEntry
    { ClusterSlotsResponseEntry -> Int
clusterSlotsResponseEntryStartSlot :: Int
    , ClusterSlotsResponseEntry -> Int
clusterSlotsResponseEntryEndSlot :: Int
    , ClusterSlotsResponseEntry -> ClusterSlotsNode
clusterSlotsResponseEntryMaster :: ClusterSlotsNode
    , ClusterSlotsResponseEntry -> [ClusterSlotsNode]
clusterSlotsResponseEntryReplicas :: [ClusterSlotsNode]
    } deriving (Int -> ClusterSlotsResponseEntry -> ShowS
[ClusterSlotsResponseEntry] -> ShowS
ClusterSlotsResponseEntry -> String
(Int -> ClusterSlotsResponseEntry -> ShowS)
-> (ClusterSlotsResponseEntry -> String)
-> ([ClusterSlotsResponseEntry] -> ShowS)
-> Show ClusterSlotsResponseEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterSlotsResponseEntry -> ShowS
showsPrec :: Int -> ClusterSlotsResponseEntry -> ShowS
$cshow :: ClusterSlotsResponseEntry -> String
show :: ClusterSlotsResponseEntry -> String
$cshowList :: [ClusterSlotsResponseEntry] -> ShowS
showList :: [ClusterSlotsResponseEntry] -> ShowS
Show)

instance RedisResult ClusterSlotsResponse where
    decode :: Reply -> Either Reply ClusterSlotsResponse
decode (MultiBulk (Just [Reply]
bulkData)) = do
        clusterSlotsResponseEntries <- (Reply -> Either Reply ClusterSlotsResponseEntry)
-> [Reply] -> Either Reply [ClusterSlotsResponseEntry]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply ClusterSlotsResponseEntry
forall a. RedisResult a => Reply -> Either Reply a
decode [Reply]
bulkData
        return ClusterSlotsResponse{..}
    decode Reply
a = Reply -> Either Reply ClusterSlotsResponse
forall a b. a -> Either a b
Left Reply
a

instance RedisResult ClusterSlotsResponseEntry where
    decode :: Reply -> Either Reply ClusterSlotsResponseEntry
decode (MultiBulk (Just
        ((Integer Integer
startSlot):(Integer Integer
endSlot):Reply
masterData:[Reply]
replicas))) = do
            clusterSlotsResponseEntryMaster <- Reply -> Either Reply ClusterSlotsNode
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
masterData
            clusterSlotsResponseEntryReplicas <- mapM decode replicas
            let clusterSlotsResponseEntryStartSlot = Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
startSlot
            let clusterSlotsResponseEntryEndSlot = Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
endSlot
            return ClusterSlotsResponseEntry{..}
    decode Reply
a = Reply -> Either Reply ClusterSlotsResponseEntry
forall a b. a -> Either a b
Left Reply
a

instance RedisResult ClusterSlotsNode where
    decode :: Reply -> Either Reply ClusterSlotsNode
decode (MultiBulk (Just ((Bulk (Just ByteString
clusterSlotsNodeIP)):(Integer Integer
port):(Bulk (Just ByteString
clusterSlotsNodeID)):[Reply]
_))) = ClusterSlotsNode -> Either Reply ClusterSlotsNode
forall a b. b -> Either a b
Right ClusterSlotsNode{Int
ByteString
clusterSlotsNodeIP :: ByteString
clusterSlotsNodePort :: Int
clusterSlotsNodeID :: ByteString
clusterSlotsNodeIP :: ByteString
clusterSlotsNodeID :: ByteString
clusterSlotsNodePort :: Int
..}
        where clusterSlotsNodePort :: Int
clusterSlotsNodePort = Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
port
    decode Reply
a = Reply -> Either Reply ClusterSlotsNode
forall a b. a -> Either a b
Left Reply
a


clusterSlots
    :: (RedisCtx m f)
    => m (f ClusterSlotsResponse)
clusterSlots :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f ClusterSlotsResponse)
clusterSlots = [ByteString] -> m (f ClusterSlotsResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f ClusterSlotsResponse))
-> [ByteString] -> m (f ClusterSlotsResponse)
forall a b. (a -> b) -> a -> b
$ [ByteString
"CLUSTER", ByteString
"SLOTS"]

data ClusterSlotStatsMetric
    = ClusterSlotStatsKeyCount
    | ClusterSlotStatsCpuUsec
    | ClusterSlotStatsMemoryBytes
    | ClusterSlotStatsNetworkBytesIn
    | ClusterSlotStatsNetworkBytesOut
    deriving (Int -> ClusterSlotStatsMetric -> ShowS
[ClusterSlotStatsMetric] -> ShowS
ClusterSlotStatsMetric -> String
(Int -> ClusterSlotStatsMetric -> ShowS)
-> (ClusterSlotStatsMetric -> String)
-> ([ClusterSlotStatsMetric] -> ShowS)
-> Show ClusterSlotStatsMetric
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterSlotStatsMetric -> ShowS
showsPrec :: Int -> ClusterSlotStatsMetric -> ShowS
$cshow :: ClusterSlotStatsMetric -> String
show :: ClusterSlotStatsMetric -> String
$cshowList :: [ClusterSlotStatsMetric] -> ShowS
showList :: [ClusterSlotStatsMetric] -> ShowS
Show, ClusterSlotStatsMetric -> ClusterSlotStatsMetric -> Bool
(ClusterSlotStatsMetric -> ClusterSlotStatsMetric -> Bool)
-> (ClusterSlotStatsMetric -> ClusterSlotStatsMetric -> Bool)
-> Eq ClusterSlotStatsMetric
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterSlotStatsMetric -> ClusterSlotStatsMetric -> Bool
== :: ClusterSlotStatsMetric -> ClusterSlotStatsMetric -> Bool
$c/= :: ClusterSlotStatsMetric -> ClusterSlotStatsMetric -> Bool
/= :: ClusterSlotStatsMetric -> ClusterSlotStatsMetric -> Bool
Eq)

instance RedisArg ClusterSlotStatsMetric where
    encode :: ClusterSlotStatsMetric -> ByteString
encode ClusterSlotStatsMetric
ClusterSlotStatsKeyCount = ByteString
"KEY-COUNT"
    encode ClusterSlotStatsMetric
ClusterSlotStatsCpuUsec = ByteString
"CPU-USEC"
    encode ClusterSlotStatsMetric
ClusterSlotStatsMemoryBytes = ByteString
"MEMORY-BYTES"
    encode ClusterSlotStatsMetric
ClusterSlotStatsNetworkBytesIn = ByteString
"NETWORK-BYTES-IN"
    encode ClusterSlotStatsMetric
ClusterSlotStatsNetworkBytesOut = ByteString
"NETWORK-BYTES-OUT"

data ClusterSlotStatsOrderByOpts = ClusterSlotStatsOrderByOpts
    { ClusterSlotStatsOrderByOpts -> Maybe Integer
clusterSlotStatsOrderByLimit :: Maybe Integer
    , ClusterSlotStatsOrderByOpts -> SortOrder
clusterSlotStatsOrderByDirection :: SortOrder
    } deriving (Int -> ClusterSlotStatsOrderByOpts -> ShowS
[ClusterSlotStatsOrderByOpts] -> ShowS
ClusterSlotStatsOrderByOpts -> String
(Int -> ClusterSlotStatsOrderByOpts -> ShowS)
-> (ClusterSlotStatsOrderByOpts -> String)
-> ([ClusterSlotStatsOrderByOpts] -> ShowS)
-> Show ClusterSlotStatsOrderByOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterSlotStatsOrderByOpts -> ShowS
showsPrec :: Int -> ClusterSlotStatsOrderByOpts -> ShowS
$cshow :: ClusterSlotStatsOrderByOpts -> String
show :: ClusterSlotStatsOrderByOpts -> String
$cshowList :: [ClusterSlotStatsOrderByOpts] -> ShowS
showList :: [ClusterSlotStatsOrderByOpts] -> ShowS
Show, ClusterSlotStatsOrderByOpts -> ClusterSlotStatsOrderByOpts -> Bool
(ClusterSlotStatsOrderByOpts
 -> ClusterSlotStatsOrderByOpts -> Bool)
-> (ClusterSlotStatsOrderByOpts
    -> ClusterSlotStatsOrderByOpts -> Bool)
-> Eq ClusterSlotStatsOrderByOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterSlotStatsOrderByOpts -> ClusterSlotStatsOrderByOpts -> Bool
== :: ClusterSlotStatsOrderByOpts -> ClusterSlotStatsOrderByOpts -> Bool
$c/= :: ClusterSlotStatsOrderByOpts -> ClusterSlotStatsOrderByOpts -> Bool
/= :: ClusterSlotStatsOrderByOpts -> ClusterSlotStatsOrderByOpts -> Bool
Eq)

defaultClusterSlotStatsOrderByOpts :: ClusterSlotStatsOrderByOpts
defaultClusterSlotStatsOrderByOpts :: ClusterSlotStatsOrderByOpts
defaultClusterSlotStatsOrderByOpts = ClusterSlotStatsOrderByOpts
    { clusterSlotStatsOrderByLimit :: Maybe Integer
clusterSlotStatsOrderByLimit = Maybe Integer
forall a. Maybe a
Nothing
    , clusterSlotStatsOrderByDirection :: SortOrder
clusterSlotStatsOrderByDirection = SortOrder
Desc
    }

data ClusterSlotStatsQuery
    = ClusterSlotStatsSlotsRange Integer Integer
    | ClusterSlotStatsOrderBy ClusterSlotStatsMetric ClusterSlotStatsOrderByOpts
    deriving (Int -> ClusterSlotStatsQuery -> ShowS
[ClusterSlotStatsQuery] -> ShowS
ClusterSlotStatsQuery -> String
(Int -> ClusterSlotStatsQuery -> ShowS)
-> (ClusterSlotStatsQuery -> String)
-> ([ClusterSlotStatsQuery] -> ShowS)
-> Show ClusterSlotStatsQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterSlotStatsQuery -> ShowS
showsPrec :: Int -> ClusterSlotStatsQuery -> ShowS
$cshow :: ClusterSlotStatsQuery -> String
show :: ClusterSlotStatsQuery -> String
$cshowList :: [ClusterSlotStatsQuery] -> ShowS
showList :: [ClusterSlotStatsQuery] -> ShowS
Show, ClusterSlotStatsQuery -> ClusterSlotStatsQuery -> Bool
(ClusterSlotStatsQuery -> ClusterSlotStatsQuery -> Bool)
-> (ClusterSlotStatsQuery -> ClusterSlotStatsQuery -> Bool)
-> Eq ClusterSlotStatsQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterSlotStatsQuery -> ClusterSlotStatsQuery -> Bool
== :: ClusterSlotStatsQuery -> ClusterSlotStatsQuery -> Bool
$c/= :: ClusterSlotStatsQuery -> ClusterSlotStatsQuery -> Bool
/= :: ClusterSlotStatsQuery -> ClusterSlotStatsQuery -> Bool
Eq)

data ClusterSlotStatsResponse = ClusterSlotStatsResponse
    { ClusterSlotStatsResponse -> [ClusterSlotStatsResponseEntry]
clusterSlotStatsResponseEntries :: [ClusterSlotStatsResponseEntry]
    } deriving (Int -> ClusterSlotStatsResponse -> ShowS
[ClusterSlotStatsResponse] -> ShowS
ClusterSlotStatsResponse -> String
(Int -> ClusterSlotStatsResponse -> ShowS)
-> (ClusterSlotStatsResponse -> String)
-> ([ClusterSlotStatsResponse] -> ShowS)
-> Show ClusterSlotStatsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterSlotStatsResponse -> ShowS
showsPrec :: Int -> ClusterSlotStatsResponse -> ShowS
$cshow :: ClusterSlotStatsResponse -> String
show :: ClusterSlotStatsResponse -> String
$cshowList :: [ClusterSlotStatsResponse] -> ShowS
showList :: [ClusterSlotStatsResponse] -> ShowS
Show, ClusterSlotStatsResponse -> ClusterSlotStatsResponse -> Bool
(ClusterSlotStatsResponse -> ClusterSlotStatsResponse -> Bool)
-> (ClusterSlotStatsResponse -> ClusterSlotStatsResponse -> Bool)
-> Eq ClusterSlotStatsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterSlotStatsResponse -> ClusterSlotStatsResponse -> Bool
== :: ClusterSlotStatsResponse -> ClusterSlotStatsResponse -> Bool
$c/= :: ClusterSlotStatsResponse -> ClusterSlotStatsResponse -> Bool
/= :: ClusterSlotStatsResponse -> ClusterSlotStatsResponse -> Bool
Eq)

data ClusterSlotStatsResponseEntry = ClusterSlotStatsResponseEntry
    { ClusterSlotStatsResponseEntry -> Integer
clusterSlotStatsResponseEntrySlot :: Integer
    , ClusterSlotStatsResponseEntry -> Maybe Integer
clusterSlotStatsResponseEntryKeyCount :: Maybe Integer
    , ClusterSlotStatsResponseEntry -> Maybe Integer
clusterSlotStatsResponseEntryCpuUsec :: Maybe Integer
    , ClusterSlotStatsResponseEntry -> Maybe Integer
clusterSlotStatsResponseEntryMemoryBytes :: Maybe Integer
    , ClusterSlotStatsResponseEntry -> Maybe Integer
clusterSlotStatsResponseEntryNetworkBytesIn :: Maybe Integer
    , ClusterSlotStatsResponseEntry -> Maybe Integer
clusterSlotStatsResponseEntryNetworkBytesOut :: Maybe Integer
    } deriving (Int -> ClusterSlotStatsResponseEntry -> ShowS
[ClusterSlotStatsResponseEntry] -> ShowS
ClusterSlotStatsResponseEntry -> String
(Int -> ClusterSlotStatsResponseEntry -> ShowS)
-> (ClusterSlotStatsResponseEntry -> String)
-> ([ClusterSlotStatsResponseEntry] -> ShowS)
-> Show ClusterSlotStatsResponseEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterSlotStatsResponseEntry -> ShowS
showsPrec :: Int -> ClusterSlotStatsResponseEntry -> ShowS
$cshow :: ClusterSlotStatsResponseEntry -> String
show :: ClusterSlotStatsResponseEntry -> String
$cshowList :: [ClusterSlotStatsResponseEntry] -> ShowS
showList :: [ClusterSlotStatsResponseEntry] -> ShowS
Show, ClusterSlotStatsResponseEntry
-> ClusterSlotStatsResponseEntry -> Bool
(ClusterSlotStatsResponseEntry
 -> ClusterSlotStatsResponseEntry -> Bool)
-> (ClusterSlotStatsResponseEntry
    -> ClusterSlotStatsResponseEntry -> Bool)
-> Eq ClusterSlotStatsResponseEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterSlotStatsResponseEntry
-> ClusterSlotStatsResponseEntry -> Bool
== :: ClusterSlotStatsResponseEntry
-> ClusterSlotStatsResponseEntry -> Bool
$c/= :: ClusterSlotStatsResponseEntry
-> ClusterSlotStatsResponseEntry -> Bool
/= :: ClusterSlotStatsResponseEntry
-> ClusterSlotStatsResponseEntry -> Bool
Eq)

instance RedisResult ClusterSlotStatsResponse where
    decode :: Reply -> Either Reply ClusterSlotStatsResponse
decode (MultiBulk (Just [Reply]
entries)) =
        [ClusterSlotStatsResponseEntry] -> ClusterSlotStatsResponse
ClusterSlotStatsResponse ([ClusterSlotStatsResponseEntry] -> ClusterSlotStatsResponse)
-> Either Reply [ClusterSlotStatsResponseEntry]
-> Either Reply ClusterSlotStatsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Reply -> Either Reply ClusterSlotStatsResponseEntry)
-> [Reply] -> Either Reply [ClusterSlotStatsResponseEntry]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply ClusterSlotStatsResponseEntry
forall a. RedisResult a => Reply -> Either Reply a
decode [Reply]
entries
    decode Reply
r = Reply -> Either Reply ClusterSlotStatsResponse
forall a b. a -> Either a b
Left Reply
r

instance RedisResult ClusterSlotStatsResponseEntry where
    decode :: Reply -> Either Reply ClusterSlotStatsResponseEntry
decode r :: Reply
r@(MultiBulk (Just [Reply]
entries)) =
        [Reply] -> Either Reply ClusterSlotStatsResponseEntry
parseClusterSlotStatsEntry [Reply]
entries
      where
        parseClusterSlotStatsEntry :: [Reply] -> Either Reply ClusterSlotStatsResponseEntry
        parseClusterSlotStatsEntry :: [Reply] -> Either Reply ClusterSlotStatsResponseEntry
parseClusterSlotStatsEntry ((Integer Integer
slot):Reply
statsReply:[]) =
            Integer
-> [(ByteString, Integer)]
-> Either Reply ClusterSlotStatsResponseEntry
parseClusterSlotStatsFields Integer
slot ([(ByteString, Integer)]
 -> Either Reply ClusterSlotStatsResponseEntry)
-> Either Reply [(ByteString, Integer)]
-> Either Reply ClusterSlotStatsResponseEntry
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Reply -> Either Reply [(ByteString, Integer)]
parseClusterSlotStatsMetricPairs Reply
statsReply
        parseClusterSlotStatsEntry [Reply]
fields =
            case [Reply] -> Either Reply [(ByteString, Integer)]
parseClusterSlotStatsFieldPairs [Reply]
fields of
                Right [(ByteString, Integer)]
kvs -> do
                    slot <- Either Reply Integer
-> (Integer -> Either Reply Integer)
-> Maybe Integer
-> Either Reply Integer
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Reply -> Either Reply Integer
forall a b. a -> Either a b
Left Reply
r) Integer -> Either Reply Integer
forall a b. b -> Either a b
Right (ByteString -> [(ByteString, Integer)] -> Maybe Integer
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
"slot" [(ByteString, Integer)]
kvs)
                    parseClusterSlotStatsFields slot (filter ((/= "slot") . fst) kvs)
                Left Reply
_ -> Reply -> Either Reply ClusterSlotStatsResponseEntry
forall a b. a -> Either a b
Left Reply
r

        parseClusterSlotStatsMetricPairs :: Reply -> Either Reply [(ByteString, Integer)]
        parseClusterSlotStatsMetricPairs :: Reply -> Either Reply [(ByteString, Integer)]
parseClusterSlotStatsMetricPairs (MultiBulk (Just [Reply]
replies)) =
            case [Reply] -> Either Reply [(ByteString, Integer)]
parseClusterSlotStatsFieldPairs [Reply]
replies of
                Right [(ByteString, Integer)]
kvs -> [(ByteString, Integer)] -> Either Reply [(ByteString, Integer)]
forall a b. b -> Either a b
Right [(ByteString, Integer)]
kvs
                Left Reply
_ -> (Reply -> Either Reply (ByteString, Integer))
-> [Reply] -> Either Reply [(ByteString, Integer)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply (ByteString, Integer)
forall {a} {a}.
(RedisResult a, RedisResult a) =>
Reply -> Either Reply (a, a)
parseNestedPair [Reply]
replies
          where
            parseNestedPair :: Reply -> Either Reply (a, a)
parseNestedPair (MultiBulk (Just [Reply
keyReply, Reply
valueReply])) =
                (,) (a -> a -> (a, a)) -> Either Reply a -> Either Reply (a -> (a, a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
keyReply Either Reply (a -> (a, a)) -> Either Reply a -> Either Reply (a, a)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
valueReply
            parseNestedPair Reply
nestedReply = Reply -> Either Reply (a, a)
forall a b. a -> Either a b
Left Reply
nestedReply
        parseClusterSlotStatsMetricPairs Reply
reply' = Reply -> Either Reply [(ByteString, Integer)]
forall a b. a -> Either a b
Left Reply
reply'

        parseClusterSlotStatsFieldPairs :: [Reply] -> Either Reply [(ByteString, Integer)]
        parseClusterSlotStatsFieldPairs :: [Reply] -> Either Reply [(ByteString, Integer)]
parseClusterSlotStatsFieldPairs [] = [(ByteString, Integer)] -> Either Reply [(ByteString, Integer)]
forall a b. b -> Either a b
Right []
        parseClusterSlotStatsFieldPairs (Reply
keyReply:Reply
valueReply:[Reply]
rest) =
            (:) ((ByteString, Integer)
 -> [(ByteString, Integer)] -> [(ByteString, Integer)])
-> Either Reply (ByteString, Integer)
-> Either
     Reply ([(ByteString, Integer)] -> [(ByteString, Integer)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (ByteString -> Integer -> (ByteString, Integer))
-> Either Reply ByteString
-> Either Reply (Integer -> (ByteString, Integer))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
keyReply Either Reply (Integer -> (ByteString, Integer))
-> Either Reply Integer -> Either Reply (ByteString, Integer)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Integer
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
valueReply)
                Either Reply ([(ByteString, Integer)] -> [(ByteString, Integer)])
-> Either Reply [(ByteString, Integer)]
-> Either Reply [(ByteString, Integer)]
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Reply] -> Either Reply [(ByteString, Integer)]
parseClusterSlotStatsFieldPairs [Reply]
rest
        parseClusterSlotStatsFieldPairs [Reply
badReply] = Reply -> Either Reply [(ByteString, Integer)]
forall a b. a -> Either a b
Left Reply
badReply

        parseClusterSlotStatsFields :: Integer -> [(ByteString, Integer)] -> Either Reply ClusterSlotStatsResponseEntry
        parseClusterSlotStatsFields :: Integer
-> [(ByteString, Integer)]
-> Either Reply ClusterSlotStatsResponseEntry
parseClusterSlotStatsFields Integer
slot [(ByteString, Integer)]
fields =
            ClusterSlotStatsResponseEntry
-> Either Reply ClusterSlotStatsResponseEntry
forall a b. b -> Either a b
Right ClusterSlotStatsResponseEntry
                { clusterSlotStatsResponseEntrySlot :: Integer
clusterSlotStatsResponseEntrySlot = Integer
slot
                , clusterSlotStatsResponseEntryKeyCount :: Maybe Integer
clusterSlotStatsResponseEntryKeyCount = ByteString -> [(ByteString, Integer)] -> Maybe Integer
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
"key-count" [(ByteString, Integer)]
fields
                , clusterSlotStatsResponseEntryCpuUsec :: Maybe Integer
clusterSlotStatsResponseEntryCpuUsec = ByteString -> [(ByteString, Integer)] -> Maybe Integer
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
"cpu-usec" [(ByteString, Integer)]
fields
                , clusterSlotStatsResponseEntryMemoryBytes :: Maybe Integer
clusterSlotStatsResponseEntryMemoryBytes = ByteString -> [(ByteString, Integer)] -> Maybe Integer
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
"memory-bytes" [(ByteString, Integer)]
fields
                , clusterSlotStatsResponseEntryNetworkBytesIn :: Maybe Integer
clusterSlotStatsResponseEntryNetworkBytesIn = ByteString -> [(ByteString, Integer)] -> Maybe Integer
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
"network-bytes-in" [(ByteString, Integer)]
fields
                , clusterSlotStatsResponseEntryNetworkBytesOut :: Maybe Integer
clusterSlotStatsResponseEntryNetworkBytesOut = ByteString -> [(ByteString, Integer)] -> Maybe Integer
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
"network-bytes-out" [(ByteString, Integer)]
fields
                }
    decode Reply
r = Reply -> Either Reply ClusterSlotStatsResponseEntry
forall a b. a -> Either a b
Left Reply
r

clusterSlotStats
    :: (RedisCtx m f)
    => ClusterSlotStatsQuery
    -> m (f ClusterSlotStatsResponse)
clusterSlotStats :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ClusterSlotStatsQuery -> m (f ClusterSlotStatsResponse)
clusterSlotStats ClusterSlotStatsQuery
query = [ByteString] -> m (f ClusterSlotStatsResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f ClusterSlotStatsResponse))
-> [ByteString] -> m (f ClusterSlotStatsResponse)
forall a b. (a -> b) -> a -> b
$ [ByteString
"CLUSTER", ByteString
"SLOT-STATS"] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ClusterSlotStatsQuery -> [ByteString]
clusterSlotStatsQueryArgs ClusterSlotStatsQuery
query

clusterSlotStatsSlotsRange
    :: (RedisCtx m f)
    => Integer
    -> Integer
    -> m (f ClusterSlotStatsResponse)
clusterSlotStatsSlotsRange :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Integer -> Integer -> m (f ClusterSlotStatsResponse)
clusterSlotStatsSlotsRange Integer
startSlot Integer
endSlot =
    ClusterSlotStatsQuery -> m (f ClusterSlotStatsResponse)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ClusterSlotStatsQuery -> m (f ClusterSlotStatsResponse)
clusterSlotStats (Integer -> Integer -> ClusterSlotStatsQuery
ClusterSlotStatsSlotsRange Integer
startSlot Integer
endSlot)

clusterSlotStatsOrderBy
    :: (RedisCtx m f)
    => ClusterSlotStatsMetric
    -> m (f ClusterSlotStatsResponse)
clusterSlotStatsOrderBy :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ClusterSlotStatsMetric -> m (f ClusterSlotStatsResponse)
clusterSlotStatsOrderBy ClusterSlotStatsMetric
metric =
    ClusterSlotStatsMetric
-> ClusterSlotStatsOrderByOpts -> m (f ClusterSlotStatsResponse)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ClusterSlotStatsMetric
-> ClusterSlotStatsOrderByOpts -> m (f ClusterSlotStatsResponse)
clusterSlotStatsOrderByOpts ClusterSlotStatsMetric
metric ClusterSlotStatsOrderByOpts
defaultClusterSlotStatsOrderByOpts

clusterSlotStatsOrderByOpts
    :: (RedisCtx m f)
    => ClusterSlotStatsMetric
    -> ClusterSlotStatsOrderByOpts
    -> m (f ClusterSlotStatsResponse)
clusterSlotStatsOrderByOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ClusterSlotStatsMetric
-> ClusterSlotStatsOrderByOpts -> m (f ClusterSlotStatsResponse)
clusterSlotStatsOrderByOpts ClusterSlotStatsMetric
metric ClusterSlotStatsOrderByOpts
opts =
    ClusterSlotStatsQuery -> m (f ClusterSlotStatsResponse)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ClusterSlotStatsQuery -> m (f ClusterSlotStatsResponse)
clusterSlotStats (ClusterSlotStatsMetric
-> ClusterSlotStatsOrderByOpts -> ClusterSlotStatsQuery
ClusterSlotStatsOrderBy ClusterSlotStatsMetric
metric ClusterSlotStatsOrderByOpts
opts)

clusterSlotStatsQueryArgs :: ClusterSlotStatsQuery -> [ByteString]
clusterSlotStatsQueryArgs :: ClusterSlotStatsQuery -> [ByteString]
clusterSlotStatsQueryArgs ClusterSlotStatsQuery
query =
    case ClusterSlotStatsQuery
query of
        ClusterSlotStatsSlotsRange Integer
startSlot Integer
endSlot ->
            [ByteString
"SLOTSRANGE", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
startSlot, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
endSlot]
        ClusterSlotStatsOrderBy ClusterSlotStatsMetric
metric ClusterSlotStatsOrderByOpts{Maybe Integer
SortOrder
clusterSlotStatsOrderByLimit :: ClusterSlotStatsOrderByOpts -> Maybe Integer
clusterSlotStatsOrderByDirection :: ClusterSlotStatsOrderByOpts -> SortOrder
clusterSlotStatsOrderByLimit :: Maybe Integer
clusterSlotStatsOrderByDirection :: SortOrder
..} ->
            [ByteString
"ORDERBY", ClusterSlotStatsMetric -> ByteString
forall a. RedisArg a => a -> ByteString
encode ClusterSlotStatsMetric
metric]
                [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
limit -> [ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
limit]) Maybe Integer
clusterSlotStatsOrderByLimit
                [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [case SortOrder
clusterSlotStatsOrderByDirection of
                        SortOrder
Asc -> ByteString
"ASC"
                        SortOrder
Desc -> ByteString
"DESC"
                   ]

clusterSetSlotImporting
    :: (RedisCtx m f)
    => Integer
    -> ByteString
    -> m (f Status)
clusterSetSlotImporting :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Integer -> ByteString -> m (f Status)
clusterSetSlotImporting Integer
slot ByteString
sourceNodeId = [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
"CLUSTER", ByteString
"SETSLOT", (Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
slot), ByteString
"IMPORTING", ByteString
sourceNodeId]

clusterSetSlotMigrating
    :: (RedisCtx m f)
    => Integer
    -> ByteString
    -> m (f Status)
clusterSetSlotMigrating :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Integer -> ByteString -> m (f Status)
clusterSetSlotMigrating Integer
slot ByteString
destinationNodeId = [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
"CLUSTER", ByteString
"SETSLOT", (Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
slot), ByteString
"MIGRATING", ByteString
destinationNodeId]

clusterSetSlotStable
    :: (RedisCtx m f)
    => Integer
    -> m (f Status)
clusterSetSlotStable :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Integer -> m (f Status)
clusterSetSlotStable Integer
slot = [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
"CLUSTER", ByteString
"SETSLOT", ByteString
"STABLE", (Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
slot)]

clusterSetSlotNode
    :: (RedisCtx m f)
    => Integer
    -> ByteString
    -> m (f Status)
clusterSetSlotNode :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Integer -> ByteString -> m (f Status)
clusterSetSlotNode Integer
slot ByteString
node = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"SETSLOT", (Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
slot), ByteString
"NODE", ByteString
node]

clusterGetKeysInSlot
    :: (RedisCtx m f)
    => Integer
    -> Integer
    -> m (f [ByteString])
clusterGetKeysInSlot :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Integer -> Integer -> m (f [ByteString])
clusterGetKeysInSlot Integer
slot Integer
count = [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"GETKEYSINSLOT", (Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
slot), (Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count)]

data ClusterMigrationSlotRange = ClusterMigrationSlotRange
    { ClusterMigrationSlotRange -> Integer
clusterMigrationSlotRangeStart :: Integer
    , ClusterMigrationSlotRange -> Integer
clusterMigrationSlotRangeEnd :: Integer
    } deriving (Int -> ClusterMigrationSlotRange -> ShowS
[ClusterMigrationSlotRange] -> ShowS
ClusterMigrationSlotRange -> String
(Int -> ClusterMigrationSlotRange -> ShowS)
-> (ClusterMigrationSlotRange -> String)
-> ([ClusterMigrationSlotRange] -> ShowS)
-> Show ClusterMigrationSlotRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterMigrationSlotRange -> ShowS
showsPrec :: Int -> ClusterMigrationSlotRange -> ShowS
$cshow :: ClusterMigrationSlotRange -> String
show :: ClusterMigrationSlotRange -> String
$cshowList :: [ClusterMigrationSlotRange] -> ShowS
showList :: [ClusterMigrationSlotRange] -> ShowS
Show, ClusterMigrationSlotRange -> ClusterMigrationSlotRange -> Bool
(ClusterMigrationSlotRange -> ClusterMigrationSlotRange -> Bool)
-> (ClusterMigrationSlotRange -> ClusterMigrationSlotRange -> Bool)
-> Eq ClusterMigrationSlotRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterMigrationSlotRange -> ClusterMigrationSlotRange -> Bool
== :: ClusterMigrationSlotRange -> ClusterMigrationSlotRange -> Bool
$c/= :: ClusterMigrationSlotRange -> ClusterMigrationSlotRange -> Bool
/= :: ClusterMigrationSlotRange -> ClusterMigrationSlotRange -> Bool
Eq)

data ClusterMigrationTask = ClusterMigrationTask
    { ClusterMigrationTask -> ByteString
clusterMigrationTaskId :: ByteString
    , ClusterMigrationTask -> [ClusterMigrationSlotRange]
clusterMigrationTaskSlots :: [ClusterMigrationSlotRange]
    , ClusterMigrationTask -> Maybe ByteString
clusterMigrationTaskSource :: Maybe ByteString
    , ClusterMigrationTask -> Maybe ByteString
clusterMigrationTaskDest :: Maybe ByteString
    , ClusterMigrationTask -> Maybe ByteString
clusterMigrationTaskOperation :: Maybe ByteString
    , ClusterMigrationTask -> Maybe ByteString
clusterMigrationTaskState :: Maybe ByteString
    , ClusterMigrationTask -> Maybe ByteString
clusterMigrationTaskLastError :: Maybe ByteString
    , ClusterMigrationTask -> Maybe Integer
clusterMigrationTaskRetries :: Maybe Integer
    , ClusterMigrationTask -> Maybe Integer
clusterMigrationTaskCreateTime :: Maybe Integer
    , ClusterMigrationTask -> Maybe Integer
clusterMigrationTaskStartTime :: Maybe Integer
    , ClusterMigrationTask -> Maybe Integer
clusterMigrationTaskEndTime :: Maybe Integer
    , ClusterMigrationTask -> Maybe Integer
clusterMigrationTaskWritePauseMs :: Maybe Integer
    } deriving (Int -> ClusterMigrationTask -> ShowS
[ClusterMigrationTask] -> ShowS
ClusterMigrationTask -> String
(Int -> ClusterMigrationTask -> ShowS)
-> (ClusterMigrationTask -> String)
-> ([ClusterMigrationTask] -> ShowS)
-> Show ClusterMigrationTask
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterMigrationTask -> ShowS
showsPrec :: Int -> ClusterMigrationTask -> ShowS
$cshow :: ClusterMigrationTask -> String
show :: ClusterMigrationTask -> String
$cshowList :: [ClusterMigrationTask] -> ShowS
showList :: [ClusterMigrationTask] -> ShowS
Show, ClusterMigrationTask -> ClusterMigrationTask -> Bool
(ClusterMigrationTask -> ClusterMigrationTask -> Bool)
-> (ClusterMigrationTask -> ClusterMigrationTask -> Bool)
-> Eq ClusterMigrationTask
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterMigrationTask -> ClusterMigrationTask -> Bool
== :: ClusterMigrationTask -> ClusterMigrationTask -> Bool
$c/= :: ClusterMigrationTask -> ClusterMigrationTask -> Bool
/= :: ClusterMigrationTask -> ClusterMigrationTask -> Bool
Eq)

newtype ClusterMigrationStatusResponse = ClusterMigrationStatusResponse
    { ClusterMigrationStatusResponse -> [ClusterMigrationTask]
clusterMigrationStatusTasks :: [ClusterMigrationTask]
    } deriving (Int -> ClusterMigrationStatusResponse -> ShowS
[ClusterMigrationStatusResponse] -> ShowS
ClusterMigrationStatusResponse -> String
(Int -> ClusterMigrationStatusResponse -> ShowS)
-> (ClusterMigrationStatusResponse -> String)
-> ([ClusterMigrationStatusResponse] -> ShowS)
-> Show ClusterMigrationStatusResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClusterMigrationStatusResponse -> ShowS
showsPrec :: Int -> ClusterMigrationStatusResponse -> ShowS
$cshow :: ClusterMigrationStatusResponse -> String
show :: ClusterMigrationStatusResponse -> String
$cshowList :: [ClusterMigrationStatusResponse] -> ShowS
showList :: [ClusterMigrationStatusResponse] -> ShowS
Show, ClusterMigrationStatusResponse
-> ClusterMigrationStatusResponse -> Bool
(ClusterMigrationStatusResponse
 -> ClusterMigrationStatusResponse -> Bool)
-> (ClusterMigrationStatusResponse
    -> ClusterMigrationStatusResponse -> Bool)
-> Eq ClusterMigrationStatusResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClusterMigrationStatusResponse
-> ClusterMigrationStatusResponse -> Bool
== :: ClusterMigrationStatusResponse
-> ClusterMigrationStatusResponse -> Bool
$c/= :: ClusterMigrationStatusResponse
-> ClusterMigrationStatusResponse -> Bool
/= :: ClusterMigrationStatusResponse
-> ClusterMigrationStatusResponse -> Bool
Eq)

instance RedisResult ClusterMigrationStatusResponse where
    decode :: Reply -> Either Reply ClusterMigrationStatusResponse
decode (MultiBulk (Just [Reply]
tasks)) =
        [ClusterMigrationTask] -> ClusterMigrationStatusResponse
ClusterMigrationStatusResponse ([ClusterMigrationTask] -> ClusterMigrationStatusResponse)
-> Either Reply [ClusterMigrationTask]
-> Either Reply ClusterMigrationStatusResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Reply -> Either Reply ClusterMigrationTask)
-> [Reply] -> Either Reply [ClusterMigrationTask]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply ClusterMigrationTask
forall a. RedisResult a => Reply -> Either Reply a
decode [Reply]
tasks
    decode Reply
r = Reply -> Either Reply ClusterMigrationStatusResponse
forall a b. a -> Either a b
Left Reply
r

instance RedisResult ClusterMigrationTask where
    decode :: Reply -> Either Reply ClusterMigrationTask
decode r :: Reply
r@(MultiBulk (Just [Reply]
replies)) = do
        pairs <- [Reply] -> Either Reply [(ByteString, Reply)]
parsePairs [Reply]
replies
        clusterMigrationTaskId <- lookupRequired "id" pairs
        clusterMigrationTaskSlots <- maybe (Right []) parseSlotsReply (lookup "slots" pairs)
        let clusterMigrationTaskSource = ByteString -> [(ByteString, Reply)] -> Maybe ByteString
lookupMaybeByteString ByteString
"source" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskDest = ByteString -> [(ByteString, Reply)] -> Maybe ByteString
lookupMaybeByteString ByteString
"dest" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskOperation = ByteString -> [(ByteString, Reply)] -> Maybe ByteString
lookupMaybeByteString ByteString
"operation" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskState = ByteString -> [(ByteString, Reply)] -> Maybe ByteString
lookupMaybeByteString ByteString
"state" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskLastError = ByteString -> [(ByteString, Reply)] -> Maybe ByteString
lookupMaybeByteString ByteString
"last_error" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskRetries = ByteString -> [(ByteString, Reply)] -> Maybe Integer
lookupInteger ByteString
"retries" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskCreateTime = ByteString -> [(ByteString, Reply)] -> Maybe Integer
lookupInteger ByteString
"create_time" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskStartTime = ByteString -> [(ByteString, Reply)] -> Maybe Integer
lookupInteger ByteString
"start_time" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskEndTime = ByteString -> [(ByteString, Reply)] -> Maybe Integer
lookupInteger ByteString
"end_time" [(ByteString, Reply)]
pairs
        let clusterMigrationTaskWritePauseMs = ByteString -> [(ByteString, Reply)] -> Maybe Integer
lookupInteger ByteString
"write_pause_ms" [(ByteString, Reply)]
pairs
        Right ClusterMigrationTask{..}
      where
        parsePairs :: [Reply] -> Either Reply [(ByteString, Reply)]
        parsePairs :: [Reply] -> Either Reply [(ByteString, Reply)]
parsePairs [] = [(ByteString, Reply)] -> Either Reply [(ByteString, Reply)]
forall a b. b -> Either a b
Right []
        parsePairs (Reply
keyReply:Reply
valueReply:[Reply]
rest) =
            (:) ((ByteString, Reply)
 -> [(ByteString, Reply)] -> [(ByteString, Reply)])
-> Either Reply (ByteString, Reply)
-> Either Reply ([(ByteString, Reply)] -> [(ByteString, Reply)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (ByteString -> Reply -> (ByteString, Reply))
-> Either Reply ByteString
-> Either Reply (Reply -> (ByteString, Reply))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
keyReply Either Reply (Reply -> (ByteString, Reply))
-> Either Reply Reply -> Either Reply (ByteString, Reply)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Reply
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Reply
valueReply) Either Reply ([(ByteString, Reply)] -> [(ByteString, Reply)])
-> Either Reply [(ByteString, Reply)]
-> Either Reply [(ByteString, Reply)]
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Reply] -> Either Reply [(ByteString, Reply)]
parsePairs [Reply]
rest
        parsePairs [Reply
nestedReply] =
            case Reply
nestedReply of
                MultiBulk (Just [Reply]
nestedReplies) -> [Reply] -> Either Reply [(ByteString, Reply)]
parseNestedPairs [Reply]
nestedReplies
                Reply
_ -> Reply -> Either Reply [(ByteString, Reply)]
forall a b. a -> Either a b
Left Reply
nestedReply

        parseNestedPairs :: [Reply] -> Either Reply [(ByteString, Reply)]
        parseNestedPairs :: [Reply] -> Either Reply [(ByteString, Reply)]
parseNestedPairs [Reply]
nestedReplies = (Reply -> Either Reply (ByteString, Reply))
-> [Reply] -> Either Reply [(ByteString, Reply)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply (ByteString, Reply)
parseNestedPair [Reply]
nestedReplies

        parseNestedPair :: Reply -> Either Reply (ByteString, Reply)
        parseNestedPair :: Reply -> Either Reply (ByteString, Reply)
parseNestedPair (MultiBulk (Just [Reply
keyReply, Reply
valueReply])) =
            (,) (ByteString -> Reply -> (ByteString, Reply))
-> Either Reply ByteString
-> Either Reply (Reply -> (ByteString, Reply))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply ByteString
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
keyReply Either Reply (Reply -> (ByteString, Reply))
-> Either Reply Reply -> Either Reply (ByteString, Reply)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Reply
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Reply
valueReply
        parseNestedPair Reply
nestedReply = Reply -> Either Reply (ByteString, Reply)
forall a b. a -> Either a b
Left Reply
nestedReply

        lookupRequired :: RedisResult a => ByteString -> [(ByteString, Reply)] -> Either Reply a
        lookupRequired :: forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Either Reply a
lookupRequired ByteString
key [(ByteString, Reply)]
pairs =
            Either Reply a
-> (Reply -> Either Reply a) -> Maybe Reply -> Either Reply a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Reply -> Either Reply a
forall a b. a -> Either a b
Left Reply
r) Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode (ByteString -> [(ByteString, Reply)] -> Maybe Reply
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
key [(ByteString, Reply)]
pairs)

        lookupMaybeByteString :: ByteString -> [(ByteString, Reply)] -> Maybe ByteString
        lookupMaybeByteString :: ByteString -> [(ByteString, Reply)] -> Maybe ByteString
lookupMaybeByteString ByteString
key [(ByteString, Reply)]
pairs =
            case ByteString -> [(ByteString, Reply)] -> Maybe Reply
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
key [(ByteString, Reply)]
pairs of
                Just (Bulk (Just ByteString
"")) -> Maybe ByteString
forall a. Maybe a
Nothing
                Just Reply
valueReply -> (Reply -> Maybe ByteString)
-> (Maybe ByteString -> Maybe ByteString)
-> Either Reply (Maybe ByteString)
-> Maybe ByteString
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe ByteString -> Reply -> Maybe ByteString
forall a b. a -> b -> a
const Maybe ByteString
forall a. Maybe a
Nothing) Maybe ByteString -> Maybe ByteString
forall a. a -> a
id (Reply -> Either Reply (Maybe ByteString)
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
valueReply)
                Maybe Reply
Nothing -> Maybe ByteString
forall a. Maybe a
Nothing

        lookupInteger :: ByteString -> [(ByteString, Reply)] -> Maybe Integer
        lookupInteger :: ByteString -> [(ByteString, Reply)] -> Maybe Integer
lookupInteger ByteString
key [(ByteString, Reply)]
pairs =
            case ByteString -> [(ByteString, Reply)] -> Maybe Reply
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
key [(ByteString, Reply)]
pairs of
                Just Reply
valueReply -> (Reply -> Maybe Integer)
-> (Integer -> Maybe Integer)
-> Either Reply Integer
-> Maybe Integer
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe Integer -> Reply -> Maybe Integer
forall a b. a -> b -> a
const Maybe Integer
forall a. Maybe a
Nothing) Integer -> Maybe Integer
forall a. a -> Maybe a
Just (Reply -> Either Reply Integer
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
valueReply)
                Maybe Reply
Nothing -> Maybe Integer
forall a. Maybe a
Nothing

        parseSlotsReply :: Reply -> Either Reply [ClusterMigrationSlotRange]
        parseSlotsReply :: Reply -> Either Reply [ClusterMigrationSlotRange]
parseSlotsReply (Bulk (Just ByteString
slotRanges)) =
            (ByteString -> Either Reply ClusterMigrationSlotRange)
-> [ByteString] -> Either Reply [ClusterMigrationSlotRange]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ByteString -> Either Reply ClusterMigrationSlotRange
parseSlotToken (ByteString -> [ByteString]
Char8.words (ByteString -> [ByteString]) -> ByteString -> [ByteString]
forall a b. (a -> b) -> a -> b
$ (Char -> Char) -> ByteString -> ByteString
Char8.map Char -> Char
normalizeDelimiter ByteString
slotRanges)
          where
            normalizeDelimiter :: Char -> Char
normalizeDelimiter Char
',' = Char
' '
            normalizeDelimiter Char
c = Char
c
        parseSlotsReply (MultiBulk (Just [Reply]
slotReplies))
            | (Reply -> Bool) -> [Reply] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Reply -> Bool
isIntegerReply [Reply]
slotReplies = [Reply] -> Either Reply [ClusterMigrationSlotRange]
parseIntegerPairs [Reply]
slotReplies
            | Bool
otherwise = (Reply -> Either Reply ClusterMigrationSlotRange)
-> [Reply] -> Either Reply [ClusterMigrationSlotRange]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Reply -> Either Reply ClusterMigrationSlotRange
parseNestedRange [Reply]
slotReplies
          where
            isIntegerReply :: Reply -> Bool
isIntegerReply (Integer Integer
_) = Bool
True
            isIntegerReply Reply
_ = Bool
False

            parseIntegerPairs :: [Reply] -> Either Reply [ClusterMigrationSlotRange]
            parseIntegerPairs :: [Reply] -> Either Reply [ClusterMigrationSlotRange]
parseIntegerPairs [] = [ClusterMigrationSlotRange]
-> Either Reply [ClusterMigrationSlotRange]
forall a b. b -> Either a b
Right []
            parseIntegerPairs (Integer Integer
startSlot:Integer Integer
endSlot:[Reply]
rest) =
                (Integer -> Integer -> ClusterMigrationSlotRange
ClusterMigrationSlotRange Integer
startSlot Integer
endSlot ClusterMigrationSlotRange
-> [ClusterMigrationSlotRange] -> [ClusterMigrationSlotRange]
forall a. a -> [a] -> [a]
:) ([ClusterMigrationSlotRange] -> [ClusterMigrationSlotRange])
-> Either Reply [ClusterMigrationSlotRange]
-> Either Reply [ClusterMigrationSlotRange]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Reply] -> Either Reply [ClusterMigrationSlotRange]
parseIntegerPairs [Reply]
rest
            parseIntegerPairs [Reply]
badReplies = Reply -> Either Reply [ClusterMigrationSlotRange]
forall a b. a -> Either a b
Left (Reply -> Either Reply [ClusterMigrationSlotRange])
-> Reply -> Either Reply [ClusterMigrationSlotRange]
forall a b. (a -> b) -> a -> b
$ Maybe [Reply] -> Reply
MultiBulk ([Reply] -> Maybe [Reply]
forall a. a -> Maybe a
Just [Reply]
badReplies)

            parseNestedRange :: Reply -> Either Reply ClusterMigrationSlotRange
            parseNestedRange :: Reply -> Either Reply ClusterMigrationSlotRange
parseNestedRange (MultiBulk (Just [Integer Integer
startSlot, Integer Integer
endSlot])) =
                ClusterMigrationSlotRange -> Either Reply ClusterMigrationSlotRange
forall a b. b -> Either a b
Right (ClusterMigrationSlotRange
 -> Either Reply ClusterMigrationSlotRange)
-> ClusterMigrationSlotRange
-> Either Reply ClusterMigrationSlotRange
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClusterMigrationSlotRange
ClusterMigrationSlotRange Integer
startSlot Integer
endSlot
            parseNestedRange Reply
nestedReply = Reply -> Either Reply ClusterMigrationSlotRange
forall a b. a -> Either a b
Left Reply
nestedReply
        parseSlotsReply Reply
badReply = Reply -> Either Reply [ClusterMigrationSlotRange]
forall a b. a -> Either a b
Left Reply
badReply

        parseSlotToken :: ByteString -> Either Reply ClusterMigrationSlotRange
        parseSlotToken :: ByteString -> Either Reply ClusterMigrationSlotRange
parseSlotToken ByteString
token =
            case (Char -> Bool) -> ByteString -> (ByteString, ByteString)
Char8.break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-') ByteString
token of
                (ByteString
startPart, ByteString
endPart)
                    | ByteString -> Bool
BS.null ByteString
endPart -> do
                        startSlot <- ByteString -> Either Reply Integer
parseIntegerToken ByteString
token
                        Right $ ClusterMigrationSlotRange startSlot startSlot
                    | Bool
otherwise -> do
                        startSlot <- ByteString -> Either Reply Integer
parseIntegerToken ByteString
startPart
                        endSlot <- parseIntegerToken (Char8.drop 1 endPart)
                        Right $ ClusterMigrationSlotRange startSlot endSlot

        parseIntegerToken :: ByteString -> Either Reply Integer
        parseIntegerToken :: ByteString -> Either Reply Integer
parseIntegerToken ByteString
token =
            Either Reply Integer
-> (Integer -> Either Reply Integer)
-> Maybe Integer
-> Either Reply Integer
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Reply -> Either Reply Integer
forall a b. a -> Either a b
Left Reply
r) Integer -> Either Reply Integer
forall a b. b -> Either a b
Right ((Integer, ByteString) -> Integer
forall a b. (a, b) -> a
fst ((Integer, ByteString) -> Integer)
-> Maybe (Integer, ByteString) -> Maybe Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString -> Maybe (Integer, ByteString)
Char8.readInteger ByteString
token)
    decode Reply
r = Reply -> Either Reply ClusterMigrationTask
forall a b. a -> Either a b
Left Reply
r

-- |Starts an atomic slot migration import task on the current node (<https://redis.io/commands/cluster-migration>).
--
-- /O(N)/ where /N/ is the total number of slots between the specified start and end slot arguments.
--
-- Since Redis 8.4.0
clusterMigrationImport
    :: (RedisCtx m f)
    => NonEmpty (Integer, Integer)
    {- ^ Slot ranges to import.

       Execute this subcommand on the destination master. It accepts multiple slot ranges and returns a task ID that can later be used to monitor the migration.
     -}
    -> m (f ByteString)
clusterMigrationImport :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty (Integer, Integer) -> m (f ByteString)
clusterMigrationImport NonEmpty (Integer, Integer)
slotRanges =
    [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f ByteString))
-> [ByteString] -> m (f ByteString)
forall a b. (a -> b) -> a -> b
$ [ByteString
"CLUSTER", ByteString
"MIGRATION", ByteString
"IMPORT"]
        [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ((Integer, Integer) -> [ByteString])
-> [(Integer, Integer)] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(Integer
startSlot, Integer
endSlot) -> [Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
startSlot, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
endSlot]) (NonEmpty (Integer, Integer) -> [(Integer, Integer)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Integer, Integer)
slotRanges)

-- |Cancels an ongoing migration task by task ID (<https://redis.io/commands/cluster-migration>).
--
-- /O(N)/ where /N/ is the total number of slots between the specified start and end slot arguments.
--
-- Since Redis 8.4.0
clusterMigrationCancelId
    :: (RedisCtx m f)
    => ByteString -- ^ Task identifier.
    -> m (f Integer)
clusterMigrationCancelId :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
clusterMigrationCancelId ByteString
taskId =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"MIGRATION", ByteString
"CANCEL", ByteString
"ID", ByteString
taskId]

-- |Cancels all ongoing migration tasks (<https://redis.io/commands/cluster-migration>).
--
-- /O(N)/ where /N/ is the total number of slots between the specified start and end slot arguments.
--
-- Since Redis 8.4.0
clusterMigrationCancelAll
    :: (RedisCtx m f)
    => m (f Integer)
clusterMigrationCancelAll :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Integer)
clusterMigrationCancelAll =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"MIGRATION", ByteString
"CANCEL", ByteString
"ALL"]

-- |Returns the status of current and completed atomic slot migration tasks (<https://redis.io/commands/cluster-migration>).
--
-- /O(N)/ where /N/ is the total number of slots between the specified start and end slot arguments.
--
-- Since Redis 8.4.0
clusterMigrationStatus
    :: (RedisCtx m f)
    => m (f ClusterMigrationStatusResponse)
clusterMigrationStatus :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f ClusterMigrationStatusResponse)
clusterMigrationStatus =
    [ByteString] -> m (f ClusterMigrationStatusResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"MIGRATION", ByteString
"STATUS"]

-- |Returns the status of all current and completed atomic slot migration tasks (<https://redis.io/commands/cluster-migration>).
--
-- /O(N)/ where /N/ is the total number of slots between the specified start and end slot arguments.
--
-- Since Redis 8.4.0
clusterMigrationStatusAll
    :: (RedisCtx m f)
    => m (f ClusterMigrationStatusResponse)
clusterMigrationStatusAll :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f ClusterMigrationStatusResponse)
clusterMigrationStatusAll =
    [ByteString] -> m (f ClusterMigrationStatusResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"MIGRATION", ByteString
"STATUS", ByteString
"ALL"]

-- |Returns the status of a specific atomic slot migration task (<https://redis.io/commands/cluster-migration>).
--
-- /O(N)/ where /N/ is the total number of slots between the specified start and end slot arguments.
--
-- Since Redis 8.4.0
clusterMigrationStatusId
    :: (RedisCtx m f)
    => ByteString -- ^ Task identifier.
    -> m (f ClusterMigrationStatusResponse)
clusterMigrationStatusId :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f ClusterMigrationStatusResponse)
clusterMigrationStatusId ByteString
taskId =
    [ByteString] -> m (f ClusterMigrationStatusResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"CLUSTER", ByteString
"MIGRATION", ByteString
"STATUS", ByteString
"ID", ByteString
taskId]

command :: (RedisCtx m f) => m (f [CMD.CommandInfo])
command :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f [CommandInfo])
command = [ByteString] -> m (f [CommandInfo])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"COMMAND"]

-- |Returns a list of command names (<https://redis.io/commands/command-list>).
--
-- /O(N)/ where /N/ is the total number of Redis commands.
--
-- Since Redis 7.0.0
commandList
    :: (RedisCtx m f)
    => m (f [ByteString])
commandList :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f [ByteString])
commandList = Maybe CommandListFilter -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Maybe CommandListFilter -> m (f [ByteString])
commandListOpts Maybe CommandListFilter
forall a. Maybe a
Nothing

data CommandListFilter
    = CommandListFilterByModule ByteString
    | CommandListFilterByAclCat ByteString
    | CommandListFilterByPattern ByteString
    deriving (Int -> CommandListFilter -> ShowS
[CommandListFilter] -> ShowS
CommandListFilter -> String
(Int -> CommandListFilter -> ShowS)
-> (CommandListFilter -> String)
-> ([CommandListFilter] -> ShowS)
-> Show CommandListFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CommandListFilter -> ShowS
showsPrec :: Int -> CommandListFilter -> ShowS
$cshow :: CommandListFilter -> String
show :: CommandListFilter -> String
$cshowList :: [CommandListFilter] -> ShowS
showList :: [CommandListFilter] -> ShowS
Show, CommandListFilter -> CommandListFilter -> Bool
(CommandListFilter -> CommandListFilter -> Bool)
-> (CommandListFilter -> CommandListFilter -> Bool)
-> Eq CommandListFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CommandListFilter -> CommandListFilter -> Bool
== :: CommandListFilter -> CommandListFilter -> Bool
$c/= :: CommandListFilter -> CommandListFilter -> Bool
/= :: CommandListFilter -> CommandListFilter -> Bool
Eq)

-- |Returns a list of command names (<https://redis.io/commands/command-list>).
--
-- /O(N)/ where /N/ is the total number of Redis commands.
--
-- Since Redis 7.0.0
commandListOpts
    :: (RedisCtx m f)
    => Maybe CommandListFilter
    {- ^ Optional filtering mode.

       `CommandListFilterByModule` keeps only commands that belong to the given module.
       `CommandListFilterByAclCat` keeps only commands from the given ACL category.
       `CommandListFilterByPattern` keeps only commands whose names match the specified glob-style pattern.
     -}
    -> m (f [ByteString])
commandListOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
Maybe CommandListFilter -> m (f [ByteString])
commandListOpts Maybe CommandListFilter
commandFilter =
    [ByteString] -> m (f [ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [ByteString]))
-> [ByteString] -> m (f [ByteString])
forall a b. (a -> b) -> a -> b
$ [ByteString
"COMMAND", ByteString
"LIST"] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
filterArgs
  where
    filterArgs :: [ByteString]
filterArgs =
        case Maybe CommandListFilter
commandFilter of
            Maybe CommandListFilter
Nothing -> []
            Just (CommandListFilterByModule ByteString
moduleName) ->
                [ByteString
"FILTERBY", ByteString
"MODULE", ByteString
moduleName]
            Just (CommandListFilterByAclCat ByteString
category) ->
                [ByteString
"FILTERBY", ByteString
"ACLCAT", ByteString
category]
            Just (CommandListFilterByPattern ByteString
pattern_) ->
                [ByteString
"FILTERBY", ByteString
"PATTERN", ByteString
pattern_]

data IncrexExpiration
    = IncrexSeconds Integer
    | IncrexMilliseconds Integer
    | IncrexUnixSeconds Integer
    | IncrexUnixMilliseconds Integer
    | IncrexPersist
    deriving (Int -> IncrexExpiration -> ShowS
[IncrexExpiration] -> ShowS
IncrexExpiration -> String
(Int -> IncrexExpiration -> ShowS)
-> (IncrexExpiration -> String)
-> ([IncrexExpiration] -> ShowS)
-> Show IncrexExpiration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IncrexExpiration -> ShowS
showsPrec :: Int -> IncrexExpiration -> ShowS
$cshow :: IncrexExpiration -> String
show :: IncrexExpiration -> String
$cshowList :: [IncrexExpiration] -> ShowS
showList :: [IncrexExpiration] -> ShowS
Show, IncrexExpiration -> IncrexExpiration -> Bool
(IncrexExpiration -> IncrexExpiration -> Bool)
-> (IncrexExpiration -> IncrexExpiration -> Bool)
-> Eq IncrexExpiration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IncrexExpiration -> IncrexExpiration -> Bool
== :: IncrexExpiration -> IncrexExpiration -> Bool
$c/= :: IncrexExpiration -> IncrexExpiration -> Bool
/= :: IncrexExpiration -> IncrexExpiration -> Bool
Eq)

data IncrexOpts a = IncrexOpts
    { forall a. IncrexOpts a -> Maybe a
increxLowerBound :: Maybe a
    , forall a. IncrexOpts a -> Maybe a
increxUpperBound :: Maybe a
    , forall a. IncrexOpts a -> Bool
increxSaturate :: Bool
    , forall a. IncrexOpts a -> Maybe IncrexExpiration
increxExpiration :: Maybe IncrexExpiration
    , forall a. IncrexOpts a -> Bool
increxExpirationIfNotExists :: Bool
    } deriving (Int -> IncrexOpts a -> ShowS
[IncrexOpts a] -> ShowS
IncrexOpts a -> String
(Int -> IncrexOpts a -> ShowS)
-> (IncrexOpts a -> String)
-> ([IncrexOpts a] -> ShowS)
-> Show (IncrexOpts a)
forall a. Show a => Int -> IncrexOpts a -> ShowS
forall a. Show a => [IncrexOpts a] -> ShowS
forall a. Show a => IncrexOpts a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> IncrexOpts a -> ShowS
showsPrec :: Int -> IncrexOpts a -> ShowS
$cshow :: forall a. Show a => IncrexOpts a -> String
show :: IncrexOpts a -> String
$cshowList :: forall a. Show a => [IncrexOpts a] -> ShowS
showList :: [IncrexOpts a] -> ShowS
Show, IncrexOpts a -> IncrexOpts a -> Bool
(IncrexOpts a -> IncrexOpts a -> Bool)
-> (IncrexOpts a -> IncrexOpts a -> Bool) -> Eq (IncrexOpts a)
forall a. Eq a => IncrexOpts a -> IncrexOpts a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => IncrexOpts a -> IncrexOpts a -> Bool
== :: IncrexOpts a -> IncrexOpts a -> Bool
$c/= :: forall a. Eq a => IncrexOpts a -> IncrexOpts a -> Bool
/= :: IncrexOpts a -> IncrexOpts a -> Bool
Eq)

-- |Redis default 'IncrexOpts'. Equivalent to omitting all optional parameters.
defaultIncrexOpts :: IncrexOpts a
defaultIncrexOpts :: forall a. IncrexOpts a
defaultIncrexOpts = IncrexOpts
    { increxLowerBound :: Maybe a
increxLowerBound = Maybe a
forall a. Maybe a
Nothing
    , increxUpperBound :: Maybe a
increxUpperBound = Maybe a
forall a. Maybe a
Nothing
    , increxSaturate :: Bool
increxSaturate = Bool
False
    , increxExpiration :: Maybe IncrexExpiration
increxExpiration = Maybe IncrexExpiration
forall a. Maybe a
Nothing
    , increxExpirationIfNotExists :: Bool
increxExpirationIfNotExists = Bool
False
    }

-- |Increments the numeric value of a key by one and optionally updates its expiration (<https://redis.io/commands/increx>).
--
-- /O(1)/
--
-- Since Redis 8.8.0
increx
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key to increment.
    -> m (f (Integer, Integer))
increx :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Integer, Integer))
increx ByteString
key = ByteString -> IncrexOpts Integer -> m (f (Integer, Integer))
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> IncrexOpts Integer -> m (f (Integer, Integer))
increxOpts ByteString
key IncrexOpts Integer
forall a. IncrexOpts a
defaultIncrexOpts

-- |Increments the numeric value of a key by one and optionally updates its expiration (<https://redis.io/commands/increx>).
--
-- /O(1)/
--
-- Since Redis 8.8.0
increxOpts
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key to increment.
    -> IncrexOpts Integer
    {- ^ Bound and expiration options.

       `LBOUND` and `UBOUND` constrain the result.
       `SATURATE` clips out-of-bounds values instead of rejecting the increment.
       `EX`/`PX`/`EXAT`/`PXAT`/`PERSIST` control the key expiration.
       `ENX` only sets the expiration when the key currently has no TTL.
     -}
    -> m (f (Integer, Integer))
increxOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> IncrexOpts Integer -> m (f (Integer, Integer))
increxOpts ByteString
key IncrexOpts Integer
opts =
    [ByteString] -> m (f (Integer, Integer))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Integer, Integer)))
-> [ByteString] -> m (f (Integer, Integer))
forall a b. (a -> b) -> a -> b
$ [ByteString
"INCREX", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ IncrexOpts Integer -> [ByteString]
forall a. RedisArg a => IncrexOpts a -> [ByteString]
increxCommonArgs IncrexOpts Integer
opts

-- |Increments the integer value of a key by a specific amount and optionally updates its expiration (<https://redis.io/commands/increx>).
--
-- /O(1)/
--
-- Since Redis 8.8.0
increxBy
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key to increment.
    -> Integer -- ^ The integer increment to apply.
    -> IncrexOpts Integer -- ^ Bound and expiration options.
    -> m (f (Integer, Integer))
increxBy :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer -> IncrexOpts Integer -> m (f (Integer, Integer))
increxBy ByteString
key Integer
increment IncrexOpts Integer
opts =
    [ByteString] -> m (f (Integer, Integer))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Integer, Integer)))
-> [ByteString] -> m (f (Integer, Integer))
forall a b. (a -> b) -> a -> b
$ [ByteString
"INCREX", ByteString
key, ByteString
"BYINT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
increment] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ IncrexOpts Integer -> [ByteString]
forall a. RedisArg a => IncrexOpts a -> [ByteString]
increxCommonArgs IncrexOpts Integer
opts

-- |Increments the floating-point value of a key by a specific amount and optionally updates its expiration (<https://redis.io/commands/increx>).
--
-- /O(1)/
--
-- Since Redis 8.8.0
increxByFloat
    :: (RedisCtx m f)
    => ByteString -- ^ The name of the key to increment.
    -> Double -- ^ The floating-point increment to apply.
    -> IncrexOpts Double -- ^ Bound and expiration options.
    -> m (f (Double, Double))
increxByFloat :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Double -> IncrexOpts Double -> m (f (Double, Double))
increxByFloat ByteString
key Double
increment IncrexOpts Double
opts =
    [ByteString] -> m (f (Double, Double))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Double, Double)))
-> [ByteString] -> m (f (Double, Double))
forall a b. (a -> b) -> a -> b
$ [ByteString
"INCREX", ByteString
key, ByteString
"BYFLOAT", Double -> ByteString
forall a. RedisArg a => a -> ByteString
encode Double
increment] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ IncrexOpts Double -> [ByteString]
forall a. RedisArg a => IncrexOpts a -> [ByteString]
increxCommonArgs IncrexOpts Double
opts

increxCommonArgs :: RedisArg a => IncrexOpts a -> [ByteString]
increxCommonArgs :: forall a. RedisArg a => IncrexOpts a -> [ByteString]
increxCommonArgs IncrexOpts{Bool
Maybe a
Maybe IncrexExpiration
increxLowerBound :: forall a. IncrexOpts a -> Maybe a
increxUpperBound :: forall a. IncrexOpts a -> Maybe a
increxSaturate :: forall a. IncrexOpts a -> Bool
increxExpiration :: forall a. IncrexOpts a -> Maybe IncrexExpiration
increxExpirationIfNotExists :: forall a. IncrexOpts a -> Bool
increxLowerBound :: Maybe a
increxUpperBound :: Maybe a
increxSaturate :: Bool
increxExpiration :: Maybe IncrexExpiration
increxExpirationIfNotExists :: Bool
..} =
    [ByteString]
lowerBoundArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
upperBoundArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
saturateArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
expirationArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
enxArg
  where
    lowerBoundArg :: [ByteString]
lowerBoundArg = [ByteString] -> (a -> [ByteString]) -> Maybe a -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\a
bound -> [ByteString
"LBOUND", a -> ByteString
forall a. RedisArg a => a -> ByteString
encode a
bound]) Maybe a
increxLowerBound
    upperBoundArg :: [ByteString]
upperBoundArg = [ByteString] -> (a -> [ByteString]) -> Maybe a -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\a
bound -> [ByteString
"UBOUND", a -> ByteString
forall a. RedisArg a => a -> ByteString
encode a
bound]) Maybe a
increxUpperBound
    saturateArg :: [ByteString]
saturateArg = [ByteString
"SATURATE" | Bool
increxSaturate]
    expirationArg :: [ByteString]
expirationArg =
        case Maybe IncrexExpiration
increxExpiration of
            Maybe IncrexExpiration
Nothing -> []
            Just (IncrexSeconds Integer
seconds) -> [ByteString
"EX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds]
            Just (IncrexMilliseconds Integer
milliseconds) -> [ByteString
"PX", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds]
            Just (IncrexUnixSeconds Integer
seconds) -> [ByteString
"EXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds]
            Just (IncrexUnixMilliseconds Integer
milliseconds) -> [ByteString
"PXAT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
milliseconds]
            Just IncrexExpiration
IncrexPersist -> [ByteString
"PERSIST"]
    enxArg :: [ByteString]
enxArg = [ByteString
"ENX" | Bool
increxExpirationIfNotExists]

data ARGrepPredicate
    = ARGrepExact ByteString
    | ARGrepMatch ByteString
    | ARGrepGlob ByteString
    | ARGrepRegex ByteString
    deriving (Int -> ARGrepPredicate -> ShowS
[ARGrepPredicate] -> ShowS
ARGrepPredicate -> String
(Int -> ARGrepPredicate -> ShowS)
-> (ARGrepPredicate -> String)
-> ([ARGrepPredicate] -> ShowS)
-> Show ARGrepPredicate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ARGrepPredicate -> ShowS
showsPrec :: Int -> ARGrepPredicate -> ShowS
$cshow :: ARGrepPredicate -> String
show :: ARGrepPredicate -> String
$cshowList :: [ARGrepPredicate] -> ShowS
showList :: [ARGrepPredicate] -> ShowS
Show, ARGrepPredicate -> ARGrepPredicate -> Bool
(ARGrepPredicate -> ARGrepPredicate -> Bool)
-> (ARGrepPredicate -> ARGrepPredicate -> Bool)
-> Eq ARGrepPredicate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ARGrepPredicate -> ARGrepPredicate -> Bool
== :: ARGrepPredicate -> ARGrepPredicate -> Bool
$c/= :: ARGrepPredicate -> ARGrepPredicate -> Bool
/= :: ARGrepPredicate -> ARGrepPredicate -> Bool
Eq)

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

data ARGrepOpts = ARGrepOpts
    { ARGrepOpts -> Maybe ARGrepCombine
arGrepCombine :: Maybe ARGrepCombine
    , ARGrepOpts -> Maybe Integer
arGrepLimit :: Maybe Integer
    , ARGrepOpts -> Bool
arGrepNoCase :: Bool
    } deriving (Int -> ARGrepOpts -> ShowS
[ARGrepOpts] -> ShowS
ARGrepOpts -> String
(Int -> ARGrepOpts -> ShowS)
-> (ARGrepOpts -> String)
-> ([ARGrepOpts] -> ShowS)
-> Show ARGrepOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ARGrepOpts -> ShowS
showsPrec :: Int -> ARGrepOpts -> ShowS
$cshow :: ARGrepOpts -> String
show :: ARGrepOpts -> String
$cshowList :: [ARGrepOpts] -> ShowS
showList :: [ARGrepOpts] -> ShowS
Show, ARGrepOpts -> ARGrepOpts -> Bool
(ARGrepOpts -> ARGrepOpts -> Bool)
-> (ARGrepOpts -> ARGrepOpts -> Bool) -> Eq ARGrepOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ARGrepOpts -> ARGrepOpts -> Bool
== :: ARGrepOpts -> ARGrepOpts -> Bool
$c/= :: ARGrepOpts -> ARGrepOpts -> Bool
/= :: ARGrepOpts -> ARGrepOpts -> Bool
Eq)

-- |Redis default 'ARGrepOpts'. Equivalent to omitting all optional parameters.
defaultARGrepOpts :: ARGrepOpts
defaultARGrepOpts :: ARGrepOpts
defaultARGrepOpts = ARGrepOpts
    { arGrepCombine :: Maybe ARGrepCombine
arGrepCombine = Maybe ARGrepCombine
forall a. Maybe a
Nothing
    , arGrepLimit :: Maybe Integer
arGrepLimit = Maybe Integer
forall a. Maybe a
Nothing
    , arGrepNoCase :: Bool
arGrepNoCase = Bool
False
    }

data ARLastItemsOpts = ARLastItemsOpts
    { ARLastItemsOpts -> Bool
arLastItemsReverse :: Bool
    } deriving (Int -> ARLastItemsOpts -> ShowS
[ARLastItemsOpts] -> ShowS
ARLastItemsOpts -> String
(Int -> ARLastItemsOpts -> ShowS)
-> (ARLastItemsOpts -> String)
-> ([ARLastItemsOpts] -> ShowS)
-> Show ARLastItemsOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ARLastItemsOpts -> ShowS
showsPrec :: Int -> ARLastItemsOpts -> ShowS
$cshow :: ARLastItemsOpts -> String
show :: ARLastItemsOpts -> String
$cshowList :: [ARLastItemsOpts] -> ShowS
showList :: [ARLastItemsOpts] -> ShowS
Show, ARLastItemsOpts -> ARLastItemsOpts -> Bool
(ARLastItemsOpts -> ARLastItemsOpts -> Bool)
-> (ARLastItemsOpts -> ARLastItemsOpts -> Bool)
-> Eq ARLastItemsOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ARLastItemsOpts -> ARLastItemsOpts -> Bool
== :: ARLastItemsOpts -> ARLastItemsOpts -> Bool
$c/= :: ARLastItemsOpts -> ARLastItemsOpts -> Bool
/= :: ARLastItemsOpts -> ARLastItemsOpts -> Bool
Eq)

-- |Redis default 'ARLastItemsOpts'. Equivalent to omitting all optional parameters.
defaultARLastItemsOpts :: ARLastItemsOpts
defaultARLastItemsOpts :: ARLastItemsOpts
defaultARLastItemsOpts = ARLastItemsOpts
    { arLastItemsReverse :: Bool
arLastItemsReverse = Bool
False
    }

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

-- |Redis default 'ARScanOpts'. Equivalent to omitting all optional parameters.
defaultARScanOpts :: ARScanOpts
defaultARScanOpts :: ARScanOpts
defaultARScanOpts = ARScanOpts
    { arScanLimit :: Maybe Integer
arScanLimit = Maybe Integer
forall a. Maybe a
Nothing
    }

newtype ARIndexValuePairsResponse = ARIndexValuePairsResponse
    { ARIndexValuePairsResponse -> [(Integer, ByteString)]
arIndexValuePairs :: [(Integer, ByteString)]
    } deriving (Int -> ARIndexValuePairsResponse -> ShowS
[ARIndexValuePairsResponse] -> ShowS
ARIndexValuePairsResponse -> String
(Int -> ARIndexValuePairsResponse -> ShowS)
-> (ARIndexValuePairsResponse -> String)
-> ([ARIndexValuePairsResponse] -> ShowS)
-> Show ARIndexValuePairsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ARIndexValuePairsResponse -> ShowS
showsPrec :: Int -> ARIndexValuePairsResponse -> ShowS
$cshow :: ARIndexValuePairsResponse -> String
show :: ARIndexValuePairsResponse -> String
$cshowList :: [ARIndexValuePairsResponse] -> ShowS
showList :: [ARIndexValuePairsResponse] -> ShowS
Show, ARIndexValuePairsResponse -> ARIndexValuePairsResponse -> Bool
(ARIndexValuePairsResponse -> ARIndexValuePairsResponse -> Bool)
-> (ARIndexValuePairsResponse -> ARIndexValuePairsResponse -> Bool)
-> Eq ARIndexValuePairsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ARIndexValuePairsResponse -> ARIndexValuePairsResponse -> Bool
== :: ARIndexValuePairsResponse -> ARIndexValuePairsResponse -> Bool
$c/= :: ARIndexValuePairsResponse -> ARIndexValuePairsResponse -> Bool
/= :: ARIndexValuePairsResponse -> ARIndexValuePairsResponse -> Bool
Eq)

instance RedisResult ARIndexValuePairsResponse where
    decode :: Reply -> Either Reply ARIndexValuePairsResponse
decode r :: Reply
r@(MultiBulk (Just [Reply]
replies)) =
        [(Integer, ByteString)] -> ARIndexValuePairsResponse
ARIndexValuePairsResponse ([(Integer, ByteString)] -> ARIndexValuePairsResponse)
-> Either Reply [(Integer, ByteString)]
-> Either Reply ARIndexValuePairsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Reply] -> Either Reply [(Integer, ByteString)]
forall {a} {a}.
(RedisResult a, RedisResult a) =>
[Reply] -> Either Reply [(a, a)]
decodePairs [Reply]
replies
      where
        decodePairs :: [Reply] -> Either Reply [(a, a)]
decodePairs [] = [(a, a)] -> Either Reply [(a, a)]
forall a b. b -> Either a b
Right []
        decodePairs (MultiBulk (Just [Reply
indexReply, Reply
valueReply]):[Reply]
rest) =
            (:) ((a, a) -> [(a, a)] -> [(a, a)])
-> Either Reply (a, a) -> Either Reply ([(a, a)] -> [(a, a)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (a -> a -> (a, a)) -> Either Reply a -> Either Reply (a -> (a, a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
indexReply Either Reply (a -> (a, a)) -> Either Reply a -> Either Reply (a, a)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
valueReply) Either Reply ([(a, a)] -> [(a, a)])
-> Either Reply [(a, a)] -> Either Reply [(a, a)]
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Reply] -> Either Reply [(a, a)]
decodePairs [Reply]
rest
        decodePairs (Reply
indexReply:Reply
valueReply:[Reply]
rest) =
            (:) ((a, a) -> [(a, a)] -> [(a, a)])
-> Either Reply (a, a) -> Either Reply ([(a, a)] -> [(a, a)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (a -> a -> (a, a)) -> Either Reply a -> Either Reply (a -> (a, a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
indexReply Either Reply (a -> (a, a)) -> Either Reply a -> Either Reply (a, a)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
valueReply) Either Reply ([(a, a)] -> [(a, a)])
-> Either Reply [(a, a)] -> Either Reply [(a, a)]
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Reply] -> Either Reply [(a, a)]
decodePairs [Reply]
rest
        decodePairs [Reply]
_ = Reply -> Either Reply [(a, a)]
forall a b. a -> Either a b
Left Reply
r
    decode Reply
r = Reply -> Either Reply ARIndexValuePairsResponse
forall a b. a -> Either a b
Left Reply
r

data ARInfoResponse = ARInfoResponse
    { ARInfoResponse -> Integer
arInfoCount :: Integer
    , ARInfoResponse -> Integer
arInfoLength :: Integer
    , ARInfoResponse -> Integer
arInfoNextInsertIndex :: Integer
    , ARInfoResponse -> Integer
arInfoSlices :: Integer
    , ARInfoResponse -> Integer
arInfoDirectorySize :: Integer
    , ARInfoResponse -> Integer
arInfoSuperDirEntries :: Integer
    , ARInfoResponse -> Integer
arInfoSliceSize :: Integer
    , ARInfoResponse -> Maybe Integer
arInfoDenseSlices :: Maybe Integer
    , ARInfoResponse -> Maybe Integer
arInfoSparseSlices :: Maybe Integer
    , ARInfoResponse -> Maybe Double
arInfoAvgDenseSize :: Maybe Double
    , ARInfoResponse -> Maybe Double
arInfoAvgDenseFill :: Maybe Double
    , ARInfoResponse -> Maybe Double
arInfoAvgSparseSize :: Maybe Double
    } deriving (Int -> ARInfoResponse -> ShowS
[ARInfoResponse] -> ShowS
ARInfoResponse -> String
(Int -> ARInfoResponse -> ShowS)
-> (ARInfoResponse -> String)
-> ([ARInfoResponse] -> ShowS)
-> Show ARInfoResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ARInfoResponse -> ShowS
showsPrec :: Int -> ARInfoResponse -> ShowS
$cshow :: ARInfoResponse -> String
show :: ARInfoResponse -> String
$cshowList :: [ARInfoResponse] -> ShowS
showList :: [ARInfoResponse] -> ShowS
Show, ARInfoResponse -> ARInfoResponse -> Bool
(ARInfoResponse -> ARInfoResponse -> Bool)
-> (ARInfoResponse -> ARInfoResponse -> Bool) -> Eq ARInfoResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ARInfoResponse -> ARInfoResponse -> Bool
== :: ARInfoResponse -> ARInfoResponse -> Bool
$c/= :: ARInfoResponse -> ARInfoResponse -> Bool
/= :: ARInfoResponse -> ARInfoResponse -> Bool
Eq)

instance RedisResult ARInfoResponse where
    decode :: Reply -> Either Reply ARInfoResponse
decode r :: Reply
r@(MultiBulk (Just [Reply]
replies)) = do
        pairs <- [Reply] -> Either Reply [(ByteString, Reply)]
forall {a}. RedisResult a => [Reply] -> Either Reply [(a, Reply)]
parsePairs [Reply]
replies
        ARInfoResponse
            <$> required "count" pairs
            <*> required "len" pairs
            <*> required "next-insert-index" pairs
            <*> required "slices" pairs
            <*> required "directory-size" pairs
            <*> required "super-dir-entries" pairs
            <*> required "slice-size" pairs
            <*> pure (optional "dense-slices" pairs)
            <*> pure (optional "sparse-slices" pairs)
            <*> pure (optional "avg-dense-size" pairs)
            <*> pure (optional "avg-dense-fill" pairs)
            <*> pure (optional "avg-sparse-size" pairs)
      where
        parsePairs :: [Reply] -> Either Reply [(a, Reply)]
parsePairs [] = [(a, Reply)] -> Either Reply [(a, Reply)]
forall a b. b -> Either a b
Right []
        parsePairs (Reply
keyReply:Reply
valueReply:[Reply]
rest) =
            (:) ((a, Reply) -> [(a, Reply)] -> [(a, Reply)])
-> Either Reply (a, Reply)
-> Either Reply ([(a, Reply)] -> [(a, Reply)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (a -> Reply -> (a, Reply))
-> Either Reply a -> Either Reply (Reply -> (a, Reply))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
keyReply Either Reply (Reply -> (a, Reply))
-> Either Reply Reply -> Either Reply (a, Reply)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Reply
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Reply
valueReply) Either Reply ([(a, Reply)] -> [(a, Reply)])
-> Either Reply [(a, Reply)] -> Either Reply [(a, Reply)]
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Reply] -> Either Reply [(a, Reply)]
parsePairs [Reply]
rest
        parsePairs [Reply]
_ = Reply -> Either Reply [(a, Reply)]
forall a b. a -> Either a b
Left Reply
r

        required :: RedisResult a => ByteString -> [(ByteString, Reply)] -> Either Reply a
        required :: forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Either Reply a
required ByteString
key [(ByteString, Reply)]
pairs = Either Reply a
-> (Reply -> Either Reply a) -> Maybe Reply -> Either Reply a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Reply -> Either Reply a
forall a b. a -> Either a b
Left Reply
r) Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode (ByteString -> [(ByteString, Reply)] -> Maybe Reply
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
key [(ByteString, Reply)]
pairs)

        optional :: RedisResult a => ByteString -> [(ByteString, Reply)] -> Maybe a
        optional :: forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
key [(ByteString, Reply)]
pairs = ByteString -> [(ByteString, Reply)] -> Maybe Reply
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
key [(ByteString, Reply)]
pairs Maybe Reply -> (Reply -> Maybe a) -> Maybe a
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Reply -> Maybe a) -> (a -> Maybe a) -> Either Reply a -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe a -> Reply -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing) a -> Maybe a
forall a. a -> Maybe a
Just (Either Reply a -> Maybe a)
-> (Reply -> Either Reply a) -> Reply -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode
    decode Reply
r = Reply -> Either Reply ARInfoResponse
forall a b. a -> Either a b
Left Reply
r

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

data AROpCount
    = AROpAnd
    | AROpOr
    | AROpXor
    | AROpMatch ByteString
    | AROpUsed
    deriving (Int -> AROpCount -> ShowS
[AROpCount] -> ShowS
AROpCount -> String
(Int -> AROpCount -> ShowS)
-> (AROpCount -> String)
-> ([AROpCount] -> ShowS)
-> Show AROpCount
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AROpCount -> ShowS
showsPrec :: Int -> AROpCount -> ShowS
$cshow :: AROpCount -> String
show :: AROpCount -> String
$cshowList :: [AROpCount] -> ShowS
showList :: [AROpCount] -> ShowS
Show, AROpCount -> AROpCount -> Bool
(AROpCount -> AROpCount -> Bool)
-> (AROpCount -> AROpCount -> Bool) -> Eq AROpCount
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AROpCount -> AROpCount -> Bool
== :: AROpCount -> AROpCount -> Bool
$c/= :: AROpCount -> AROpCount -> Bool
/= :: AROpCount -> AROpCount -> Bool
Eq)

argrepPredicateArgs :: ARGrepPredicate -> [ByteString]
argrepPredicateArgs :: ARGrepPredicate -> [ByteString]
argrepPredicateArgs ARGrepPredicate
predicate =
    case ARGrepPredicate
predicate of
        ARGrepExact ByteString
value -> [ByteString
"EXACT", ByteString
value]
        ARGrepMatch ByteString
value -> [ByteString
"MATCH", ByteString
value]
        ARGrepGlob ByteString
pattern_ -> [ByteString
"GLOB", ByteString
pattern_]
        ARGrepRegex ByteString
pattern_ -> [ByteString
"RE", ByteString
pattern_]

argrepOptsArgs :: ARGrepOpts -> [ByteString]
argrepOptsArgs :: ARGrepOpts -> [ByteString]
argrepOptsArgs ARGrepOpts{Bool
Maybe Integer
Maybe ARGrepCombine
arGrepCombine :: ARGrepOpts -> Maybe ARGrepCombine
arGrepLimit :: ARGrepOpts -> Maybe Integer
arGrepNoCase :: ARGrepOpts -> Bool
arGrepCombine :: Maybe ARGrepCombine
arGrepLimit :: Maybe Integer
arGrepNoCase :: Bool
..} =
    [ByteString]
combineArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
limitArg [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
nocaseArg
  where
    combineArg :: [ByteString]
combineArg =
        case Maybe ARGrepCombine
arGrepCombine of
            Maybe ARGrepCombine
Nothing -> []
            Just ARGrepCombine
ARGrepAnd -> [ByteString
"AND"]
            Just ARGrepCombine
ARGrepOr -> [ByteString
"OR"]
    limitArg :: [ByteString]
limitArg = [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
limit -> [ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
limit]) Maybe Integer
arGrepLimit
    nocaseArg :: [ByteString]
nocaseArg = [ByteString
"NOCASE" | Bool
arGrepNoCase]

aropValueArg :: AROpValue -> ByteString
aropValueArg :: AROpValue -> ByteString
aropValueArg AROpValue
operation =
    case AROpValue
operation of
        AROpValue
AROpSum -> ByteString
"SUM"
        AROpValue
AROpMin -> ByteString
"MIN"
        AROpValue
AROpMax -> ByteString
"MAX"

aropCountArgs :: AROpCount -> [ByteString]
aropCountArgs :: AROpCount -> [ByteString]
aropCountArgs AROpCount
operation =
    case AROpCount
operation of
        AROpCount
AROpAnd -> [ByteString
"AND"]
        AROpCount
AROpOr -> [ByteString
"OR"]
        AROpCount
AROpXor -> [ByteString
"XOR"]
        AROpMatch ByteString
value -> [ByteString
"MATCH", ByteString
value]
        AROpCount
AROpUsed -> [ByteString
"USED"]

-- |Returns the number of non-empty elements in an array (<https://redis.io/commands/arcount>).
--
-- /O(1)/
--
-- Since Redis 8.8.0
arcount
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> m (f Integer)
arcount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
arcount ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ARCOUNT", ByteString
key]

-- |Deletes elements at the specified indices in an array (<https://redis.io/commands/ardel>).
--
-- /O(N)/ where /N/ is the number of indices to delete.
--
-- Since Redis 8.8.0
ardel
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> NonEmpty Integer -- ^ One or more zero-based indices to delete.
    -> m (f Integer)
ardel :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty Integer -> m (f Integer)
ardel ByteString
key NonEmpty Integer
indices =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"ARDEL", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (Integer -> ByteString) -> [Integer] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (NonEmpty Integer -> [Integer]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty Integer
indices)

-- |Gets values in a range of indices (<https://redis.io/commands/argetrange>).
--
-- /O(N)/ where /N/ is the range length.
--
-- Since Redis 8.8.0
argetrange
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Start index.
    -> Integer -- ^ End index, inclusive.
    -> m (f [Maybe ByteString])
argetrange :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> Integer -> m (f [Maybe ByteString])
argetrange ByteString
key Integer
start Integer
end =
    [ByteString] -> m (f [Maybe ByteString])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ARGETRANGE", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
end]

-- |Searches array elements in a range using textual predicates (<https://redis.io/commands/argrep>).
--
-- /O(P * C)/ where /P/ is the number of visited positions and /C/ is the cost of evaluating predicates.
--
-- Since Redis 8.8.0
argrep
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> ByteString -- ^ Start index or `-` for the first array index.
    -> ByteString -- ^ End index or `+` for the last array index.
    -> NonEmpty ARGrepPredicate -- ^ One or more predicates to apply.
    -> m (f [Integer])
argrep :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> NonEmpty ARGrepPredicate
-> m (f [Integer])
argrep ByteString
key ByteString
start ByteString
end NonEmpty ARGrepPredicate
predicates =
    ByteString
-> ByteString
-> ByteString
-> NonEmpty ARGrepPredicate
-> ARGrepOpts
-> m (f [Integer])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> NonEmpty ARGrepPredicate
-> ARGrepOpts
-> m (f [Integer])
argrepOpts ByteString
key ByteString
start ByteString
end NonEmpty ARGrepPredicate
predicates ARGrepOpts
defaultARGrepOpts

-- |Searches array elements in a range using textual predicates (<https://redis.io/commands/argrep>).
--
-- /O(P * C)/ where /P/ is the number of visited positions and /C/ is the cost of evaluating predicates.
--
-- Since Redis 8.8.0
argrepOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> ByteString -- ^ Start index or `-` for the first array index.
    -> ByteString -- ^ End index or `+` for the last array index.
    -> NonEmpty ARGrepPredicate -- ^ One or more predicates to apply.
    -> ARGrepOpts -- ^ Additional predicate options.
    -> m (f [Integer])
argrepOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> NonEmpty ARGrepPredicate
-> ARGrepOpts
-> m (f [Integer])
argrepOpts ByteString
key ByteString
start ByteString
end NonEmpty ARGrepPredicate
predicates ARGrepOpts
opts =
    [ByteString] -> m (f [Integer])
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f [Integer]))
-> [ByteString] -> m (f [Integer])
forall a b. (a -> b) -> a -> b
$
        [ByteString
"ARGREP", ByteString
key, ByteString
start, ByteString
end]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (ARGrepPredicate -> [ByteString])
-> [ARGrepPredicate] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ARGrepPredicate -> [ByteString]
argrepPredicateArgs (NonEmpty ARGrepPredicate -> [ARGrepPredicate]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ARGrepPredicate
predicates)
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ARGrepOpts -> [ByteString]
argrepOptsArgs ARGrepOpts
opts

-- |Searches array elements in a range and returns matching index-value pairs (<https://redis.io/commands/argrep>).
--
-- /O(P * C)/ where /P/ is the number of visited positions and /C/ is the cost of evaluating predicates.
--
-- Since Redis 8.8.0
argrepWithValues
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> ByteString -- ^ Start index or `-` for the first array index.
    -> ByteString -- ^ End index or `+` for the last array index.
    -> NonEmpty ARGrepPredicate -- ^ One or more predicates to apply.
    -> m (f ARIndexValuePairsResponse)
argrepWithValues :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> NonEmpty ARGrepPredicate
-> m (f ARIndexValuePairsResponse)
argrepWithValues ByteString
key ByteString
start ByteString
end NonEmpty ARGrepPredicate
predicates =
    ByteString
-> ByteString
-> ByteString
-> NonEmpty ARGrepPredicate
-> ARGrepOpts
-> m (f ARIndexValuePairsResponse)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> NonEmpty ARGrepPredicate
-> ARGrepOpts
-> m (f ARIndexValuePairsResponse)
argrepWithValuesOpts ByteString
key ByteString
start ByteString
end NonEmpty ARGrepPredicate
predicates ARGrepOpts
defaultARGrepOpts

-- |Searches array elements in a range and returns matching index-value pairs (<https://redis.io/commands/argrep>).
--
-- /O(P * C)/ where /P/ is the number of visited positions and /C/ is the cost of evaluating predicates.
--
-- Since Redis 8.8.0
argrepWithValuesOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> ByteString -- ^ Start index or `-` for the first array index.
    -> ByteString -- ^ End index or `+` for the last array index.
    -> NonEmpty ARGrepPredicate -- ^ One or more predicates to apply.
    -> ARGrepOpts -- ^ Additional predicate options.
    -> m (f ARIndexValuePairsResponse)
argrepWithValuesOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> ByteString
-> ByteString
-> NonEmpty ARGrepPredicate
-> ARGrepOpts
-> m (f ARIndexValuePairsResponse)
argrepWithValuesOpts ByteString
key ByteString
start ByteString
end NonEmpty ARGrepPredicate
predicates ARGrepOpts
opts =
    [ByteString] -> m (f ARIndexValuePairsResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f ARIndexValuePairsResponse))
-> [ByteString] -> m (f ARIndexValuePairsResponse)
forall a b. (a -> b) -> a -> b
$
        [ByteString
"ARGREP", ByteString
key, ByteString
start, ByteString
end]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (ARGrepPredicate -> [ByteString])
-> [ARGrepPredicate] -> [ByteString]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ARGrepPredicate -> [ByteString]
argrepPredicateArgs (NonEmpty ARGrepPredicate -> [ARGrepPredicate]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ARGrepPredicate
predicates)
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"WITHVALUES"]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ ARGrepOpts -> [ByteString]
argrepOptsArgs ARGrepOpts
opts

-- |Returns metadata about an array (<https://redis.io/commands/arinfo>).
--
-- /O(1)/, or /O(N)/ with `FULL` where /N/ is the number of slices.
--
-- Since Redis 8.8.0
arinfo
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> m (f ARInfoResponse)
arinfo :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f ARInfoResponse)
arinfo ByteString
key = [ByteString] -> m (f ARInfoResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ARINFO", ByteString
key]

-- |Returns extended metadata about an array (<https://redis.io/commands/arinfo>).
--
-- /O(N)/ where /N/ is the number of slices.
--
-- Since Redis 8.8.0
arinfoFull
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> m (f ARInfoResponse)
arinfoFull :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f ARInfoResponse)
arinfoFull ByteString
key = [ByteString] -> m (f ARInfoResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ARINFO", ByteString
key, ByteString
"FULL"]

-- |Inserts one or more values at consecutive indices (<https://redis.io/commands/arinsert>).
--
-- /O(N)/ where /N/ is the number of values.
--
-- Since Redis 8.8.0
arinsert
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> NonEmpty ByteString -- ^ Values to insert at the current insert cursor.
    -> m (f Integer)
arinsert :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty ByteString -> m (f Integer)
arinsert ByteString
key NonEmpty ByteString
values =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"ARINSERT", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ByteString
values

-- |Returns the most recently inserted elements (<https://redis.io/commands/arlastitems>).
--
-- /O(N)/ where /N/ is the count.
--
-- Since Redis 8.8.0
arlastitems
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Maximum number of most recently inserted elements to return.
    -> m (f [Maybe ByteString])
arlastitems :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f [Maybe ByteString])
arlastitems ByteString
key Integer
count =
    ByteString
-> Integer -> ARLastItemsOpts -> m (f [Maybe ByteString])
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer -> ARLastItemsOpts -> m (f [Maybe ByteString])
arlastitemsOpts ByteString
key Integer
count ARLastItemsOpts
defaultARLastItemsOpts

-- |Returns the most recently inserted elements (<https://redis.io/commands/arlastitems>).
--
-- /O(N)/ where /N/ is the count.
--
-- Since Redis 8.8.0
arlastitemsOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Maximum number of most recently inserted elements to return.
    -> ARLastItemsOpts -- ^ Additional options.
    -> m (f [Maybe ByteString])
arlastitemsOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer -> ARLastItemsOpts -> m (f [Maybe ByteString])
arlastitemsOpts ByteString
key Integer
count ARLastItemsOpts{Bool
arLastItemsReverse :: ARLastItemsOpts -> Bool
arLastItemsReverse :: Bool
..} =
    [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
"ARLASTITEMS", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString
"REV" | Bool
arLastItemsReverse]

-- |Returns the length of an array (max index + 1) (<https://redis.io/commands/arlen>).
--
-- /O(1)/
--
-- Since Redis 8.8.0
arlen
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> m (f Integer)
arlen :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f Integer)
arlen ByteString
key = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ARLEN", ByteString
key]

-- |Gets values at multiple indices in an array (<https://redis.io/commands/armget>).
--
-- /O(N)/ where /N/ is the number of indices.
--
-- Since Redis 8.8.0
armget
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> NonEmpty Integer -- ^ One or more zero-based indices.
    -> m (f [Maybe ByteString])
armget :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> NonEmpty Integer -> m (f [Maybe ByteString])
armget ByteString
key NonEmpty Integer
indices =
    [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
"ARMGET", ByteString
key] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (Integer -> ByteString) -> [Integer] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (NonEmpty Integer -> [Integer]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty Integer
indices)

-- |Returns the next index that `ARINSERT` would use (<https://redis.io/commands/arnext>).
--
-- /O(1)/
--
-- Since Redis 8.8.0
arnext
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> m (f (Maybe Integer))
arnext :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> m (f (Maybe Integer))
arnext ByteString
key = [ByteString] -> m (f (Maybe Integer))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ARNEXT", ByteString
key]

-- |Performs aggregate operations on array elements in a range and returns a string result (<https://redis.io/commands/arop>).
--
-- /O(P)/ where /P/ is the number of visited positions in touched slices.
--
-- Since Redis 8.8.0
aropValue
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Start index.
    -> Integer -- ^ End index.
    -> AROpValue -- ^ Aggregate operation.
    -> m (f (Maybe ByteString))
aropValue :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer -> Integer -> AROpValue -> m (f (Maybe ByteString))
aropValue ByteString
key Integer
start Integer
end AROpValue
operation =
    [ByteString] -> m (f (Maybe ByteString))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"AROP", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
end, AROpValue -> ByteString
aropValueArg AROpValue
operation]

-- |Performs aggregate operations on array elements in a range and returns an integer result (<https://redis.io/commands/arop>).
--
-- /O(P)/ where /P/ is the number of visited positions in touched slices.
--
-- Since Redis 8.8.0
aropCount
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Start index.
    -> Integer -- ^ End index.
    -> AROpCount -- ^ Aggregate operation.
    -> m (f (Maybe Integer))
aropCount :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer -> Integer -> AROpCount -> m (f (Maybe Integer))
aropCount ByteString
key Integer
start Integer
end AROpCount
operation =
    [ByteString] -> m (f (Maybe Integer))
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f (Maybe Integer)))
-> [ByteString] -> m (f (Maybe Integer))
forall a b. (a -> b) -> a -> b
$ [ByteString
"AROP", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
end] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ AROpCount -> [ByteString]
aropCountArgs AROpCount
operation

-- |Inserts values into a ring buffer of specified size, wrapping and truncating as needed (<https://redis.io/commands/arring>).
--
-- /O(M)/ normally, or /O(N+M)/ on ring resize.
--
-- Since Redis 8.8.0
arring
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Ring buffer size.
    -> NonEmpty ByteString -- ^ Values to insert.
    -> m (f Integer)
arring :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> NonEmpty ByteString -> m (f Integer)
arring ByteString
key Integer
size NonEmpty ByteString
values =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"ARRING", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
size] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ NonEmpty ByteString -> [ByteString]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty ByteString
values

-- |Iterates existing elements in a range, returning index-value pairs (<https://redis.io/commands/arscan>).
--
-- /O(P)/ where /P/ is the number of visited positions in touched slices.
--
-- Since Redis 8.8.0
arscan
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Start index.
    -> Integer -- ^ End index.
    -> m (f ARIndexValuePairsResponse)
arscan :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> Integer -> m (f ARIndexValuePairsResponse)
arscan ByteString
key Integer
start Integer
end =
    ByteString
-> Integer
-> Integer
-> ARScanOpts
-> m (f ARIndexValuePairsResponse)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> Integer
-> ARScanOpts
-> m (f ARIndexValuePairsResponse)
arscanOpts ByteString
key Integer
start Integer
end ARScanOpts
defaultARScanOpts

-- |Iterates existing elements in a range, returning index-value pairs (<https://redis.io/commands/arscan>).
--
-- /O(P)/ where /P/ is the number of visited positions in touched slices.
--
-- Since Redis 8.8.0
arscanOpts
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Start index.
    -> Integer -- ^ End index.
    -> ARScanOpts -- ^ Additional options.
    -> m (f ARIndexValuePairsResponse)
arscanOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString
-> Integer
-> Integer
-> ARScanOpts
-> m (f ARIndexValuePairsResponse)
arscanOpts ByteString
key Integer
start Integer
end ARScanOpts{Maybe Integer
arScanLimit :: ARScanOpts -> Maybe Integer
arScanLimit :: Maybe Integer
..} =
    [ByteString] -> m (f ARIndexValuePairsResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f ARIndexValuePairsResponse))
-> [ByteString] -> m (f ARIndexValuePairsResponse)
forall a b. (a -> b) -> a -> b
$
        [ByteString
"ARSCAN", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
end]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
limit -> [ByteString
"LIMIT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
limit]) Maybe Integer
arScanLimit

-- |Sets the `ARINSERT` / `ARRING` cursor to a specific index (<https://redis.io/commands/arseek>).
--
-- /O(1)/
--
-- Since Redis 8.8.0
arseek
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ The new insert cursor position.
    -> m (f Bool)
arseek :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> m (f Bool)
arseek ByteString
key Integer
index = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"ARSEEK", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
index]

-- |Sets one or more contiguous values starting at an index in an array (<https://redis.io/commands/arset>).
--
-- /O(N)/ where /N/ is the number of values.
--
-- Since Redis 8.8.0
arset
    :: (RedisCtx m f)
    => ByteString -- ^ Array key.
    -> Integer -- ^ Start index.
    -> NonEmpty ByteString -- ^ One or more values to store at consecutive indices.
    -> m (f Integer)
arset :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> NonEmpty ByteString -> m (f Integer)
arset ByteString
key Integer
index NonEmpty ByteString
values =
    [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest ([ByteString] -> m (f Integer)) -> [ByteString] -> m (f Integer)
forall a b. (a -> b) -> a -> b
$ [ByteString
"ARSET", ByteString
key, 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

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

instance RedisArg HotkeysMetric where
    encode :: HotkeysMetric -> ByteString
encode HotkeysMetric
HotkeysMetricCPU = ByteString
"CPU"
    encode HotkeysMetric
HotkeysMetricNET = ByteString
"NET"

data HotkeysStartOpts = HotkeysStartOpts
    { HotkeysStartOpts -> Maybe Integer
hotkeysStartTopKCount :: Maybe Integer
      -- ^ The value of K for the top-K hotkeys tracking.
    , HotkeysStartOpts -> Maybe Integer
hotkeysStartDurationSeconds :: Maybe Integer
      -- ^ The number of seconds to keep tracking before it stops automatically.
    , HotkeysStartOpts -> Maybe Integer
hotkeysStartSampleRatio :: Maybe Integer
      -- ^ The probabilistic sampling ratio. Each key is sampled with probability @1/ratio@.
    , HotkeysStartOpts -> Maybe (NonEmpty Integer)
hotkeysStartSlots :: Maybe (NonEmpty Integer)
      -- ^ The hash slots to track in cluster mode.
    } deriving (Int -> HotkeysStartOpts -> ShowS
[HotkeysStartOpts] -> ShowS
HotkeysStartOpts -> String
(Int -> HotkeysStartOpts -> ShowS)
-> (HotkeysStartOpts -> String)
-> ([HotkeysStartOpts] -> ShowS)
-> Show HotkeysStartOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HotkeysStartOpts -> ShowS
showsPrec :: Int -> HotkeysStartOpts -> ShowS
$cshow :: HotkeysStartOpts -> String
show :: HotkeysStartOpts -> String
$cshowList :: [HotkeysStartOpts] -> ShowS
showList :: [HotkeysStartOpts] -> ShowS
Show, HotkeysStartOpts -> HotkeysStartOpts -> Bool
(HotkeysStartOpts -> HotkeysStartOpts -> Bool)
-> (HotkeysStartOpts -> HotkeysStartOpts -> Bool)
-> Eq HotkeysStartOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HotkeysStartOpts -> HotkeysStartOpts -> Bool
== :: HotkeysStartOpts -> HotkeysStartOpts -> Bool
$c/= :: HotkeysStartOpts -> HotkeysStartOpts -> Bool
/= :: HotkeysStartOpts -> HotkeysStartOpts -> Bool
Eq)

-- |Redis default 'HotkeysStartOpts'. Equivalent to omitting all optional parameters.
defaultHotkeysStartOpts :: HotkeysStartOpts
defaultHotkeysStartOpts :: HotkeysStartOpts
defaultHotkeysStartOpts = HotkeysStartOpts
    { hotkeysStartTopKCount :: Maybe Integer
hotkeysStartTopKCount = Maybe Integer
forall a. Maybe a
Nothing
    , hotkeysStartDurationSeconds :: Maybe Integer
hotkeysStartDurationSeconds = Maybe Integer
forall a. Maybe a
Nothing
    , hotkeysStartSampleRatio :: Maybe Integer
hotkeysStartSampleRatio = Maybe Integer
forall a. Maybe a
Nothing
    , hotkeysStartSlots :: Maybe (NonEmpty Integer)
hotkeysStartSlots = Maybe (NonEmpty Integer)
forall a. Maybe a
Nothing
    }

data HotkeysSlotRange = HotkeysSlotRange
    { HotkeysSlotRange -> Integer
hotkeysSlotRangeStart :: Integer
    , HotkeysSlotRange -> Integer
hotkeysSlotRangeEnd :: Integer
    } deriving (Int -> HotkeysSlotRange -> ShowS
[HotkeysSlotRange] -> ShowS
HotkeysSlotRange -> String
(Int -> HotkeysSlotRange -> ShowS)
-> (HotkeysSlotRange -> String)
-> ([HotkeysSlotRange] -> ShowS)
-> Show HotkeysSlotRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HotkeysSlotRange -> ShowS
showsPrec :: Int -> HotkeysSlotRange -> ShowS
$cshow :: HotkeysSlotRange -> String
show :: HotkeysSlotRange -> String
$cshowList :: [HotkeysSlotRange] -> ShowS
showList :: [HotkeysSlotRange] -> ShowS
Show, HotkeysSlotRange -> HotkeysSlotRange -> Bool
(HotkeysSlotRange -> HotkeysSlotRange -> Bool)
-> (HotkeysSlotRange -> HotkeysSlotRange -> Bool)
-> Eq HotkeysSlotRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HotkeysSlotRange -> HotkeysSlotRange -> Bool
== :: HotkeysSlotRange -> HotkeysSlotRange -> Bool
$c/= :: HotkeysSlotRange -> HotkeysSlotRange -> Bool
/= :: HotkeysSlotRange -> HotkeysSlotRange -> Bool
Eq)

instance RedisResult HotkeysSlotRange where
    decode :: Reply -> Either Reply HotkeysSlotRange
decode (MultiBulk (Just [Integer Integer
slot])) =
        HotkeysSlotRange -> Either Reply HotkeysSlotRange
forall a b. b -> Either a b
Right HotkeysSlotRange
            { hotkeysSlotRangeStart :: Integer
hotkeysSlotRangeStart = Integer
slot
            , hotkeysSlotRangeEnd :: Integer
hotkeysSlotRangeEnd = Integer
slot
            }
    decode (MultiBulk (Just [Integer Integer
start, Integer Integer
end])) =
        HotkeysSlotRange -> Either Reply HotkeysSlotRange
forall a b. b -> Either a b
Right HotkeysSlotRange
            { hotkeysSlotRangeStart :: Integer
hotkeysSlotRangeStart = Integer
start
            , hotkeysSlotRangeEnd :: Integer
hotkeysSlotRangeEnd = Integer
end
            }
    decode Reply
r = Reply -> Either Reply HotkeysSlotRange
forall a b. a -> Either a b
Left Reply
r

data HotkeysGetResponse = HotkeysGetResponse
    { HotkeysGetResponse -> Bool
hotkeysGetTrackingActive :: Bool
    , HotkeysGetResponse -> Integer
hotkeysGetSampleRatio :: Integer
    , HotkeysGetResponse -> [HotkeysSlotRange]
hotkeysGetSelectedSlots :: [HotkeysSlotRange]
    , HotkeysGetResponse -> Integer
hotkeysGetAllCommandsAllSlotsUs :: Integer
    , HotkeysGetResponse -> Integer
hotkeysGetNetBytesAllCommandsAllSlots :: Integer
    , HotkeysGetResponse -> Integer
hotkeysGetCollectionStartTimeUnixMs :: Integer
    , HotkeysGetResponse -> Integer
hotkeysGetCollectionDurationMs :: Integer
    , HotkeysGetResponse -> Maybe Integer
hotkeysGetTotalCpuTimeUserMs :: Maybe Integer
    , HotkeysGetResponse -> Maybe Integer
hotkeysGetTotalCpuTimeSysMs :: Maybe Integer
    , HotkeysGetResponse -> Maybe Integer
hotkeysGetTotalNetBytes :: Maybe Integer
    , HotkeysGetResponse -> Maybe [(ByteString, Integer)]
hotkeysGetByCpuTimeUs :: Maybe [(ByteString, Integer)]
    , HotkeysGetResponse -> Maybe [(ByteString, Integer)]
hotkeysGetByNetBytes :: Maybe [(ByteString, Integer)]
    , HotkeysGetResponse -> Maybe Integer
hotkeysGetSampledCommandsSelectedSlotsUs :: Maybe Integer
    , HotkeysGetResponse -> Maybe Integer
hotkeysGetAllCommandsSelectedSlotsUs :: Maybe Integer
    , HotkeysGetResponse -> Maybe Integer
hotkeysGetNetBytesSampledCommandsSelectedSlots :: Maybe Integer
    , HotkeysGetResponse -> Maybe Integer
hotkeysGetNetBytesAllCommandsSelectedSlots :: Maybe Integer
    } deriving (Int -> HotkeysGetResponse -> ShowS
[HotkeysGetResponse] -> ShowS
HotkeysGetResponse -> String
(Int -> HotkeysGetResponse -> ShowS)
-> (HotkeysGetResponse -> String)
-> ([HotkeysGetResponse] -> ShowS)
-> Show HotkeysGetResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HotkeysGetResponse -> ShowS
showsPrec :: Int -> HotkeysGetResponse -> ShowS
$cshow :: HotkeysGetResponse -> String
show :: HotkeysGetResponse -> String
$cshowList :: [HotkeysGetResponse] -> ShowS
showList :: [HotkeysGetResponse] -> ShowS
Show, HotkeysGetResponse -> HotkeysGetResponse -> Bool
(HotkeysGetResponse -> HotkeysGetResponse -> Bool)
-> (HotkeysGetResponse -> HotkeysGetResponse -> Bool)
-> Eq HotkeysGetResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HotkeysGetResponse -> HotkeysGetResponse -> Bool
== :: HotkeysGetResponse -> HotkeysGetResponse -> Bool
$c/= :: HotkeysGetResponse -> HotkeysGetResponse -> Bool
/= :: HotkeysGetResponse -> HotkeysGetResponse -> Bool
Eq)

instance RedisResult HotkeysGetResponse where
    decode :: Reply -> Either Reply HotkeysGetResponse
decode (MultiBulk (Just [Reply
payload])) = Reply -> Either Reply HotkeysGetResponse
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
payload
    decode r :: Reply
r@(MultiBulk (Just [Reply]
replies)) = do
        pairs <- [Reply] -> Either Reply [(ByteString, Reply)]
forall {a}. RedisResult a => [Reply] -> Either Reply [(a, Reply)]
parsePairs [Reply]
replies
        hotkeysGetTrackingActive <- require "tracking-active" pairs
        hotkeysGetSampleRatio <- require "sample-ratio" pairs
        hotkeysGetSelectedSlots <- require "selected-slots" pairs
        hotkeysGetAllCommandsAllSlotsUs <- require "all-commands-all-slots-us" pairs
        hotkeysGetNetBytesAllCommandsAllSlots <- require "net-bytes-all-commands-all-slots" pairs
        hotkeysGetCollectionStartTimeUnixMs <- require "collection-start-time-unix-ms" pairs
        hotkeysGetCollectionDurationMs <- require "collection-duration-ms" pairs
        let hotkeysGetTotalCpuTimeUserMs = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"total-cpu-time-user-ms" [(ByteString, Reply)]
pairs
            hotkeysGetTotalCpuTimeSysMs = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"total-cpu-time-sys-ms" [(ByteString, Reply)]
pairs
            hotkeysGetTotalNetBytes = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"total-net-bytes" [(ByteString, Reply)]
pairs
            hotkeysGetByCpuTimeUs = ByteString
-> [(ByteString, Reply)] -> Maybe [(ByteString, Integer)]
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"by-cpu-time-us" [(ByteString, Reply)]
pairs
            hotkeysGetByNetBytes = ByteString
-> [(ByteString, Reply)] -> Maybe [(ByteString, Integer)]
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"by-net-bytes" [(ByteString, Reply)]
pairs
            hotkeysGetSampledCommandsSelectedSlotsUs = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"sampled-commands-selected-slots-us" [(ByteString, Reply)]
pairs
            hotkeysGetAllCommandsSelectedSlotsUs = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"all-commands-selected-slots-us" [(ByteString, Reply)]
pairs
            hotkeysGetNetBytesSampledCommandsSelectedSlots = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"net-bytes-sampled-commands-selected-slots" [(ByteString, Reply)]
pairs
            hotkeysGetNetBytesAllCommandsSelectedSlots = ByteString -> [(ByteString, Reply)] -> Maybe Integer
forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
"net-bytes-all-commands-selected-slots" [(ByteString, Reply)]
pairs
        pure HotkeysGetResponse{..}
      where
        parsePairs :: [Reply] -> Either Reply [(a, Reply)]
parsePairs [] = [(a, Reply)] -> Either Reply [(a, Reply)]
forall a b. b -> Either a b
Right []
        parsePairs (Reply
keyReply:Reply
valueReply:[Reply]
rest) =
            (:) ((a, Reply) -> [(a, Reply)] -> [(a, Reply)])
-> Either Reply (a, Reply)
-> Either Reply ([(a, Reply)] -> [(a, Reply)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,) (a -> Reply -> (a, Reply))
-> Either Reply a -> Either Reply (Reply -> (a, Reply))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode Reply
keyReply Either Reply (Reply -> (a, Reply))
-> Either Reply Reply -> Either Reply (a, Reply)
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Reply -> Either Reply Reply
forall a. a -> Either Reply a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Reply
valueReply) Either Reply ([(a, Reply)] -> [(a, Reply)])
-> Either Reply [(a, Reply)] -> Either Reply [(a, Reply)]
forall a b.
Either Reply (a -> b) -> Either Reply a -> Either Reply b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Reply] -> Either Reply [(a, Reply)]
parsePairs [Reply]
rest
        parsePairs [Reply]
_ = Reply -> Either Reply [(a, Reply)]
forall a b. a -> Either a b
Left Reply
r

        require :: RedisResult a => ByteString -> [(ByteString, Reply)] -> Either Reply a
        require :: forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Either Reply a
require ByteString
key [(ByteString, Reply)]
pairs =
            Either Reply a
-> (Reply -> Either Reply a) -> Maybe Reply -> Either Reply a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Reply -> Either Reply a
forall a b. a -> Either a b
Left Reply
r) Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode (ByteString -> [(ByteString, Reply)] -> Maybe Reply
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
key [(ByteString, Reply)]
pairs)

        optional :: RedisResult a => ByteString -> [(ByteString, Reply)] -> Maybe a
        optional :: forall a.
RedisResult a =>
ByteString -> [(ByteString, Reply)] -> Maybe a
optional ByteString
key [(ByteString, Reply)]
pairs = ByteString -> [(ByteString, Reply)] -> Maybe Reply
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ByteString
key [(ByteString, Reply)]
pairs Maybe Reply -> (Reply -> Maybe a) -> Maybe a
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Reply -> Maybe a) -> (a -> Maybe a) -> Either Reply a -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe a -> Reply -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing) a -> Maybe a
forall a. a -> Maybe a
Just (Either Reply a -> Maybe a)
-> (Reply -> Either Reply a) -> Reply -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Reply -> Either Reply a
forall a. RedisResult a => Reply -> Either Reply a
decode
    decode Reply
r = Reply -> Either Reply HotkeysGetResponse
forall a b. a -> Either a b
Left Reply
r

-- |Starts hotkeys tracking (<https://redis.io/commands/hotkeys-start>).
--
-- /O(1)/
--
-- Since Redis 8.6.0
hotkeysStart
    :: (RedisCtx m f)
    => NonEmpty HotkeysMetric
    {- ^ The metrics to track.

       The command automatically derives the `METRICS count` argument from the number of provided metrics.
       At least one metric must be specified.
     -}
    -> m (f Status)
hotkeysStart :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty HotkeysMetric -> m (f Status)
hotkeysStart NonEmpty HotkeysMetric
metrics = NonEmpty HotkeysMetric -> HotkeysStartOpts -> m (f Status)
forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty HotkeysMetric -> HotkeysStartOpts -> m (f Status)
hotkeysStartOpts NonEmpty HotkeysMetric
metrics HotkeysStartOpts
defaultHotkeysStartOpts

-- |Starts hotkeys tracking (<https://redis.io/commands/hotkeys-start>).
--
-- /O(1)/
--
-- Since Redis 8.6.0
hotkeysStartOpts
    :: (RedisCtx m f)
    => NonEmpty HotkeysMetric -- ^ The metrics to track.
    -> HotkeysStartOpts -- ^ Additional tracking options.
    -> m (f Status)
hotkeysStartOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
NonEmpty HotkeysMetric -> HotkeysStartOpts -> m (f Status)
hotkeysStartOpts NonEmpty HotkeysMetric
metrics HotkeysStartOpts{Maybe Integer
Maybe (NonEmpty Integer)
hotkeysStartTopKCount :: HotkeysStartOpts -> Maybe Integer
hotkeysStartDurationSeconds :: HotkeysStartOpts -> Maybe Integer
hotkeysStartSampleRatio :: HotkeysStartOpts -> Maybe Integer
hotkeysStartSlots :: HotkeysStartOpts -> Maybe (NonEmpty Integer)
hotkeysStartTopKCount :: Maybe Integer
hotkeysStartDurationSeconds :: Maybe Integer
hotkeysStartSampleRatio :: Maybe Integer
hotkeysStartSlots :: Maybe (NonEmpty Integer)
..} =
    [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
"HOTKEYS", ByteString
"START", ByteString
"METRICS", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty HotkeysMetric -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty HotkeysMetric
metrics)]
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (HotkeysMetric -> ByteString) -> [HotkeysMetric] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map HotkeysMetric -> ByteString
forall a. RedisArg a => a -> ByteString
encode (NonEmpty HotkeysMetric -> [HotkeysMetric]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty HotkeysMetric
metrics)
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
count -> [ByteString
"COUNT", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
count]) Maybe Integer
hotkeysStartTopKCount
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
duration -> [ByteString
"DURATION", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
duration]) Maybe Integer
hotkeysStartDurationSeconds
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (Integer -> [ByteString]) -> Maybe Integer -> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Integer
ratio -> [ByteString
"SAMPLE", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
ratio]) Maybe Integer
hotkeysStartSampleRatio
            [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ByteString]
-> (NonEmpty Integer -> [ByteString])
-> Maybe (NonEmpty Integer)
-> [ByteString]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] NonEmpty Integer -> [ByteString]
forall {a}. RedisArg a => NonEmpty a -> [ByteString]
slotsArgs Maybe (NonEmpty Integer)
hotkeysStartSlots
  where
    slotsArgs :: NonEmpty a -> [ByteString]
slotsArgs NonEmpty a
slots = [ByteString
"SLOTS", Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ NonEmpty a -> Int
forall a. NonEmpty a -> Int
NE.length NonEmpty a
slots)] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ (a -> ByteString) -> [a] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map a -> ByteString
forall a. RedisArg a => a -> ByteString
encode (NonEmpty a -> [a]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty a
slots)

-- |Returns tracking results and metadata from the current or most recent hotkeys tracking session (<https://redis.io/commands/hotkeys-get>).
--
-- /O(K)/ where /K/ is the number of hotkeys returned.
--
-- Since Redis 8.6.0
hotkeysGet
    :: (RedisCtx m f)
    => m (f HotkeysGetResponse)
hotkeysGet :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
m (f HotkeysGetResponse)
hotkeysGet = [ByteString] -> m (f HotkeysGetResponse)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"HOTKEYS", ByteString
"GET"]

-- |Stops hotkeys tracking (<https://redis.io/commands/hotkeys-stop>).
--
-- /O(1)/
--
-- Since Redis 8.6.0
hotkeysStop
    :: (RedisCtx m f)
    => m (f Status)
hotkeysStop :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Status)
hotkeysStop = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"HOTKEYS", ByteString
"STOP"]

-- |Release the resources used for hotkey tracking (<https://redis.io/commands/hotkeys-reset>).
--
-- /O(1)/
--
-- Since Redis 8.6.0
hotkeysReset
    :: (RedisCtx m f)
    => m (f Status)
hotkeysReset :: forall (m :: * -> *) (f :: * -> *). RedisCtx m f => m (f Status)
hotkeysReset = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"HOTKEYS", ByteString
"RESET"]


data ExpireOpts
  = ExpireOptsTime Condition
  | ExpireOptsValue SizeCondition

instance RedisArg ExpireOpts where
  encode :: ExpireOpts -> ByteString
encode (ExpireOptsTime Condition
c)  = Condition -> ByteString
forall a. RedisArg a => a -> ByteString
encode Condition
c
  encode (ExpireOptsValue SizeCondition
c) = SizeCondition -> ByteString
forall a. RedisArg a => a -> ByteString
encode SizeCondition
c

-- |Set the expiration for a key as a UNIX timestamp specified in milliseconds (<http://redis.io/commands/pexpireat>).
-- Since Redis 7.0
pexpireatOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ millisecondsTimestamp
    -> ExpireOpts
    -> m (f Bool)
pexpireatOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> ExpireOpts -> m (f Bool)
pexpireatOpts ByteString
key Integer
millisecondsTimestamp ExpireOpts
opts =
  [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"PEXPIREAT", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
millisecondsTimestamp, ExpireOpts -> ByteString
forall a. RedisArg a => a -> ByteString
encode ExpireOpts
opts]

expireOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ seconds
    -> ExpireOpts
    -> m (f Bool)
expireOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> ExpireOpts -> m (f Bool)
expireOpts ByteString
key Integer
seconds ExpireOpts
opts = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"EXPIRE", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
seconds, ExpireOpts -> ByteString
forall a. RedisArg a => a -> ByteString
encode ExpireOpts
opts]

-- | Set the expiration for a key as a UNIX timestamp (<http://redis.io/commands/expireat>).
-- Since Redis 1.2.0
expireatOpts
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ timestamp
    -> ExpireOpts
    -> m (f Bool)
expireatOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> ExpireOpts -> m (f Bool)
expireatOpts ByteString
key Integer
timestamp ExpireOpts
opts = [ByteString] -> m (f Bool)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"EXPIREAT", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
timestamp, ExpireOpts -> ByteString
forall a. RedisArg a => a -> ByteString
encode ExpireOpts
opts]

data FlushOpts
  = FlushOptsSync
  | FlushOptsAsync

instance RedisArg FlushOpts where
  encode :: FlushOpts -> ByteString
encode FlushOpts
FlushOptsSync = ByteString
"SYNC"
  encode FlushOpts
FlushOptsAsync = ByteString
"ASYNC"

-- |Remove all keys from the current database (<http://redis.io/commands/flushdb>).
-- Since Redis 6.2
flushdbOpts
    :: (RedisCtx m f)
    => FlushOpts
    -> m (f Status)
flushdbOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
FlushOpts -> m (f Status)
flushdbOpts FlushOpts
opts = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FLUSHDB", FlushOpts -> ByteString
forall a. RedisArg a => a -> ByteString
encode FlushOpts
opts]

-- |Remove all keys from the current database (<http://redis.io/commands/flushdb>).
-- Since Redis 6.2
flushallOpts
    :: (RedisCtx m f)
    => FlushOpts
    -> m (f Status)
flushallOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
FlushOpts -> m (f Status)
flushallOpts FlushOpts
opts = [ByteString] -> m (f Status)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"FLUSHALL", FlushOpts -> ByteString
forall a. RedisArg a => a -> ByteString
encode FlushOpts
opts]

data BitposType = Byte | Bit

instance RedisArg BitposType where
  encode :: BitposType -> ByteString
encode BitposType
Byte = ByteString
"BYTE"
  encode BitposType
Bit = ByteString
"BIT"

data BitposOpts
  = BitposOptsStart Integer
  | BitposOptsStartEnd Integer Integer (Maybe BitposType)

bitposOpts
    :: (RedisCtx m f)
    => ByteString
    -> Integer
    -> BitposOpts
    -> m (f Integer)
bitposOpts :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> BitposOpts -> m (f Integer)
bitposOpts ByteString
key_ Integer
bit BitposOpts
opts = [ByteString] -> m (f Integer)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest (ByteString
"BITPOS"ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: ByteString
key_ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
bitByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
: [ByteString]
rest) where
  rest :: [ByteString]
rest  = case BitposOpts
opts of
    BitposOptsStart Integer
s -> [Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
s]
    BitposOptsStartEnd Integer
start Integer
end Maybe BitposType
bits ->
      [Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
end] [ByteString] -> [ByteString] -> [ByteString]
forall a. [a] -> [a] -> [a]
++ [ BitposType -> ByteString
forall a. RedisArg a => a -> ByteString
encode BitposType
bits_ | Just BitposType
bits_ <- Maybe BitposType -> [Maybe BitposType]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe BitposType
bits]

-- |Get a substring of the string stored at a key (<http://redis.io/commands/substr>).
--
-- Deprecated in Redis. Use 'getrange' instead.
--
-- Since Redis 1.0.0
substr
    :: (RedisCtx m f)
    => ByteString -- ^ key
    -> Integer -- ^ start
    -> Integer -- ^ end
    -> m (f ByteString)
substr :: forall (m :: * -> *) (f :: * -> *).
RedisCtx m f =>
ByteString -> Integer -> Integer -> m (f ByteString)
substr ByteString
key Integer
start Integer
end = [ByteString] -> m (f ByteString)
forall (m :: * -> *) (f :: * -> *) a.
(RedisCtx m f, RedisResult a) =>
[ByteString] -> m (f a)
sendRequest [ByteString
"SUBSTR", ByteString
key, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
start, Integer -> ByteString
forall a. RedisArg a => a -> ByteString
encode Integer
end]