-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.

{-# LANGUAGE GADTs                      #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE UndecidableInstances       #-}

module Database.Redis.IO.Client where

import Control.Applicative
import Control.Exception (throw, throwIO)
import Control.Monad.Base (MonadBase (..))
import Control.Monad.Catch
import Control.Monad.IO.Class
import Control.Monad.Operational
import Control.Monad.Reader (ReaderT (..), runReaderT, MonadReader, ask, asks)
import Control.Monad.Trans.Class
import Control.Monad.Trans.Control (MonadBaseControl (..))
import Control.Monad.Trans.Except
import Data.ByteString.Lazy (ByteString)
import Data.Int
import Data.IORef
import Data.Redis
import Data.Pool hiding (Pool)
import Database.Redis.IO.Connection (Connection)
import Database.Redis.IO.Settings
import Database.Redis.IO.Timeouts (TimeoutManager)
import Database.Redis.IO.Types (ConnectionError (..))
import Prelude hiding (readList)
import System.Logger.Class hiding (Settings, settings, eval)
import System.IO.Unsafe (unsafeInterleaveIO)

import qualified Control.Monad.State.Strict   as S
import qualified Control.Monad.State.Lazy     as L
import qualified Data.List.NonEmpty           as NE
import qualified Data.Pool                    as P
import qualified Data.Sequence                as Seq
import qualified Database.Redis.IO.Connection as C
import qualified System.Logger                as Logger
import qualified Database.Redis.IO.Timeouts   as TM

-- | Connection pool.
data Pool = Pool
    { Pool -> Settings
settings :: !Settings
    , Pool -> Pool Connection
connPool :: !(P.Pool Connection)
    , Pool -> Logger
logger   :: !Logger.Logger
    , Pool -> TimeoutManager
timeouts :: !TimeoutManager
    }

-- | Redis client monad.
newtype Client a = Client
    { Client a -> ReaderT Pool IO a
client :: ReaderT Pool IO a
    } deriving ( a -> Client b -> Client a
(a -> b) -> Client a -> Client b
(forall a b. (a -> b) -> Client a -> Client b)
-> (forall a b. a -> Client b -> Client a) -> Functor Client
forall a b. a -> Client b -> Client a
forall a b. (a -> b) -> Client a -> Client b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Client b -> Client a
$c<$ :: forall a b. a -> Client b -> Client a
fmap :: (a -> b) -> Client a -> Client b
$cfmap :: forall a b. (a -> b) -> Client a -> Client b
Functor
               , Functor Client
a -> Client a
Functor Client
-> (forall a. a -> Client a)
-> (forall a b. Client (a -> b) -> Client a -> Client b)
-> (forall a b c.
    (a -> b -> c) -> Client a -> Client b -> Client c)
-> (forall a b. Client a -> Client b -> Client b)
-> (forall a b. Client a -> Client b -> Client a)
-> Applicative Client
Client a -> Client b -> Client b
Client a -> Client b -> Client a
Client (a -> b) -> Client a -> Client b
(a -> b -> c) -> Client a -> Client b -> Client c
forall a. a -> Client a
forall a b. Client a -> Client b -> Client a
forall a b. Client a -> Client b -> Client b
forall a b. Client (a -> b) -> Client a -> Client b
forall a b c. (a -> b -> c) -> Client a -> Client b -> Client c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: Client a -> Client b -> Client a
$c<* :: forall a b. Client a -> Client b -> Client a
*> :: Client a -> Client b -> Client b
$c*> :: forall a b. Client a -> Client b -> Client b
liftA2 :: (a -> b -> c) -> Client a -> Client b -> Client c
$cliftA2 :: forall a b c. (a -> b -> c) -> Client a -> Client b -> Client c
<*> :: Client (a -> b) -> Client a -> Client b
$c<*> :: forall a b. Client (a -> b) -> Client a -> Client b
pure :: a -> Client a
$cpure :: forall a. a -> Client a
$cp1Applicative :: Functor Client
Applicative
               , Applicative Client
a -> Client a
Applicative Client
-> (forall a b. Client a -> (a -> Client b) -> Client b)
-> (forall a b. Client a -> Client b -> Client b)
-> (forall a. a -> Client a)
-> Monad Client
Client a -> (a -> Client b) -> Client b
Client a -> Client b -> Client b
forall a. a -> Client a
forall a b. Client a -> Client b -> Client b
forall a b. Client a -> (a -> Client b) -> Client b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> Client a
$creturn :: forall a. a -> Client a
>> :: Client a -> Client b -> Client b
$c>> :: forall a b. Client a -> Client b -> Client b
>>= :: Client a -> (a -> Client b) -> Client b
$c>>= :: forall a b. Client a -> (a -> Client b) -> Client b
$cp1Monad :: Applicative Client
Monad
               , Monad Client
Monad Client -> (forall a. IO a -> Client a) -> MonadIO Client
IO a -> Client a
forall a. IO a -> Client a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> Client a
$cliftIO :: forall a. IO a -> Client a
$cp1MonadIO :: Monad Client
MonadIO
               , Monad Client
e -> Client a
Monad Client
-> (forall e a. Exception e => e -> Client a) -> MonadThrow Client
forall e a. Exception e => e -> Client a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
throwM :: e -> Client a
$cthrowM :: forall e a. Exception e => e -> Client a
$cp1MonadThrow :: Monad Client
MonadThrow
               , MonadCatch Client
MonadCatch Client
-> (forall b.
    ((forall a. Client a -> Client a) -> Client b) -> Client b)
-> (forall b.
    ((forall a. Client a -> Client a) -> Client b) -> Client b)
-> (forall a b c.
    Client a
    -> (a -> ExitCase b -> Client c)
    -> (a -> Client b)
    -> Client (b, c))
-> MonadMask Client
Client a
-> (a -> ExitCase b -> Client c)
-> (a -> Client b)
-> Client (b, c)
((forall a. Client a -> Client a) -> Client b) -> Client b
((forall a. Client a -> Client a) -> Client b) -> Client b
forall b.
((forall a. Client a -> Client a) -> Client b) -> Client b
forall a b c.
Client a
-> (a -> ExitCase b -> Client c)
-> (a -> Client b)
-> Client (b, c)
forall (m :: * -> *).
MonadCatch m
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b. ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
generalBracket :: Client a
-> (a -> ExitCase b -> Client c)
-> (a -> Client b)
-> Client (b, c)
$cgeneralBracket :: forall a b c.
Client a
-> (a -> ExitCase b -> Client c)
-> (a -> Client b)
-> Client (b, c)
uninterruptibleMask :: ((forall a. Client a -> Client a) -> Client b) -> Client b
$cuninterruptibleMask :: forall b.
((forall a. Client a -> Client a) -> Client b) -> Client b
mask :: ((forall a. Client a -> Client a) -> Client b) -> Client b
$cmask :: forall b.
((forall a. Client a -> Client a) -> Client b) -> Client b
$cp1MonadMask :: MonadCatch Client
MonadMask
               , MonadThrow Client
MonadThrow Client
-> (forall e a.
    Exception e =>
    Client a -> (e -> Client a) -> Client a)
-> MonadCatch Client
Client a -> (e -> Client a) -> Client a
forall e a. Exception e => Client a -> (e -> Client a) -> Client a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
catch :: Client a -> (e -> Client a) -> Client a
$ccatch :: forall e a. Exception e => Client a -> (e -> Client a) -> Client a
$cp1MonadCatch :: MonadThrow Client
MonadCatch
               , MonadReader Pool
               , MonadBase IO
               )

instance MonadLogger Client where
    log :: Level -> (Msg -> Msg) -> Client ()
log Level
l Msg -> Msg
m = (Pool -> Logger) -> Client Logger
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Pool -> Logger
logger Client Logger -> (Logger -> Client ()) -> Client ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Logger
g -> Logger -> Level -> (Msg -> Msg) -> Client ()
forall (m :: * -> *).
MonadIO m =>
Logger -> Level -> (Msg -> Msg) -> m ()
Logger.log Logger
g Level
l Msg -> Msg
m

instance MonadBaseControl IO Client where
    type StM Client a = StM (ReaderT Pool IO) a
    liftBaseWith :: (RunInBase Client IO -> IO a) -> Client a
liftBaseWith RunInBase Client IO -> IO a
f = ReaderT Pool IO a -> Client a
forall a. ReaderT Pool IO a -> Client a
Client (ReaderT Pool IO a -> Client a) -> ReaderT Pool IO a -> Client a
forall a b. (a -> b) -> a -> b
$ (RunInBase (ReaderT Pool IO) IO -> IO a) -> ReaderT Pool IO a
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith ((RunInBase (ReaderT Pool IO) IO -> IO a) -> ReaderT Pool IO a)
-> (RunInBase (ReaderT Pool IO) IO -> IO a) -> ReaderT Pool IO a
forall a b. (a -> b) -> a -> b
$ \RunInBase (ReaderT Pool IO) IO
run -> RunInBase Client IO -> IO a
f (ReaderT Pool IO a -> IO a
RunInBase (ReaderT Pool IO) IO
run (ReaderT Pool IO a -> IO a)
-> (Client a -> ReaderT Pool IO a) -> Client a -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Client a -> ReaderT Pool IO a
forall a. Client a -> ReaderT Pool IO a
client)
    restoreM :: StM Client a -> Client a
restoreM = ReaderT Pool IO a -> Client a
forall a. ReaderT Pool IO a -> Client a
Client (ReaderT Pool IO a -> Client a)
-> (a -> ReaderT Pool IO a) -> a -> Client a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ReaderT Pool IO a
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
StM m a -> m a
restoreM

-- | Monads in which 'Client' actions may be embedded.
class (Functor m, Applicative m, Monad m, MonadIO m, MonadCatch m) => MonadClient m
  where
    -- | Lift a computation to the 'Client' monad.
    liftClient :: Client a -> m a

instance MonadClient Client where
    liftClient :: Client a -> Client a
liftClient = Client a -> Client a
forall a. a -> a
id

instance MonadClient m => MonadClient (ReaderT r m) where
    liftClient :: Client a -> ReaderT r m a
liftClient = m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a)
-> (Client a -> m a) -> Client a -> ReaderT r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Client a -> m a
forall (m :: * -> *) a. MonadClient m => Client a -> m a
liftClient

instance MonadClient m => MonadClient (S.StateT s m) where
    liftClient :: Client a -> StateT s m a
liftClient = m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a)
-> (Client a -> m a) -> Client a -> StateT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Client a -> m a
forall (m :: * -> *) a. MonadClient m => Client a -> m a
liftClient

instance MonadClient m => MonadClient (L.StateT s m) where
    liftClient :: Client a -> StateT s m a
liftClient = m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a)
-> (Client a -> m a) -> Client a -> StateT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Client a -> m a
forall (m :: * -> *) a. MonadClient m => Client a -> m a
liftClient

instance MonadClient m => MonadClient (ExceptT e m) where
    liftClient :: Client a -> ExceptT e m a
liftClient = m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT e m a)
-> (Client a -> m a) -> Client a -> ExceptT e m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Client a -> m a
forall (m :: * -> *) a. MonadClient m => Client a -> m a
liftClient

mkPool :: MonadIO m => Logger -> Settings -> m Pool
mkPool :: Logger -> Settings -> m Pool
mkPool Logger
g Settings
s = IO Pool -> m Pool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Pool -> m Pool) -> IO Pool -> m Pool
forall a b. (a -> b) -> a -> b
$ do
    TimeoutManager
t <- Milliseconds -> IO TimeoutManager
TM.create Milliseconds
250
    [InetAddr]
a <- String -> Word16 -> IO [InetAddr]
C.resolve (Settings -> String
sHost Settings
s) (Settings -> Word16
sPort Settings
s)
    Settings -> Pool Connection -> Logger -> TimeoutManager -> Pool
Pool Settings
s (Pool Connection -> Logger -> TimeoutManager -> Pool)
-> IO (Pool Connection) -> IO (Logger -> TimeoutManager -> Pool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO Connection
-> (Connection -> IO ())
-> Int
-> NominalDiffTime
-> Int
-> IO (Pool Connection)
forall a.
IO a
-> (a -> IO ()) -> Int -> NominalDiffTime -> Int -> IO (Pool a)
createPool (TimeoutManager -> [InetAddr] -> IO Connection
connOpen TimeoutManager
t [InetAddr]
a)
                          Connection -> IO ()
connClose
                          (Settings -> Int
sPoolStripes Settings
s)
                          (Settings -> NominalDiffTime
sIdleTimeout Settings
s)
                          (Settings -> Int
sMaxConnections Settings
s)
           IO (Logger -> TimeoutManager -> Pool)
-> IO Logger -> IO (TimeoutManager -> Pool)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Logger -> IO Logger
forall (f :: * -> *) a. Applicative f => a -> f a
pure Logger
g
           IO (TimeoutManager -> Pool) -> IO TimeoutManager -> IO Pool
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TimeoutManager -> IO TimeoutManager
forall (f :: * -> *) a. Applicative f => a -> f a
pure TimeoutManager
t
  where
    connOpen :: TimeoutManager -> [InetAddr] -> IO Connection
connOpen TimeoutManager
t [InetAddr]
aa = NonEmpty InetAddr -> (InetAddr -> IO Connection) -> IO Connection
forall a b. NonEmpty a -> (a -> IO b) -> IO b
tryAll ([InetAddr] -> NonEmpty InetAddr
forall a. [a] -> NonEmpty a
NE.fromList [InetAddr]
aa) ((InetAddr -> IO Connection) -> IO Connection)
-> (InetAddr -> IO Connection) -> IO Connection
forall a b. (a -> b) -> a -> b
$ \InetAddr
a -> do
        Connection
c <- Settings -> Logger -> TimeoutManager -> InetAddr -> IO Connection
C.connect Settings
s Logger
g TimeoutManager
t InetAddr
a
        Logger -> (Msg -> Msg) -> IO ()
forall (m :: * -> *). MonadIO m => Logger -> (Msg -> Msg) -> m ()
Logger.debug Logger
g ((Msg -> Msg) -> IO ()) -> (Msg -> Msg) -> IO ()
forall a b. (a -> b) -> a -> b
$ ByteString
"client.connect" ByteString -> String -> Msg -> Msg
forall a. ToBytes a => ByteString -> a -> Msg -> Msg
.= Settings -> String
sHost Settings
s (Msg -> Msg) -> (Msg -> Msg) -> Msg -> Msg
forall b c a. (b -> c) -> (a -> b) -> a -> c
~~ String -> Msg -> Msg
forall a. ToBytes a => a -> Msg -> Msg
msg (Connection -> String
forall a. Show a => a -> String
show Connection
c)
        Connection -> IO Connection
forall (m :: * -> *) a. Monad m => a -> m a
return Connection
c

    connClose :: Connection -> IO ()
connClose Connection
c = do
        Logger -> (Msg -> Msg) -> IO ()
forall (m :: * -> *). MonadIO m => Logger -> (Msg -> Msg) -> m ()
Logger.debug Logger
g ((Msg -> Msg) -> IO ()) -> (Msg -> Msg) -> IO ()
forall a b. (a -> b) -> a -> b
$ ByteString
"client.close" ByteString -> String -> Msg -> Msg
forall a. ToBytes a => ByteString -> a -> Msg -> Msg
.= Settings -> String
sHost Settings
s (Msg -> Msg) -> (Msg -> Msg) -> Msg -> Msg
forall b c a. (b -> c) -> (a -> b) -> a -> c
~~ String -> Msg -> Msg
forall a. ToBytes a => a -> Msg -> Msg
msg (Connection -> String
forall a. Show a => a -> String
show Connection
c)
        Connection -> IO ()
C.close Connection
c

shutdown :: MonadIO m => Pool -> m ()
shutdown :: Pool -> m ()
shutdown Pool
p = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Pool Connection -> IO ()
forall a. Pool a -> IO ()
P.destroyAllResources (Pool -> Pool Connection
connPool Pool
p)

runRedis :: MonadIO m => Pool -> Client a -> m a
runRedis :: Pool -> Client a -> m a
runRedis Pool
p Client a
a = IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> IO a -> m a
forall a b. (a -> b) -> a -> b
$ ReaderT Pool IO a -> Pool -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (Client a -> ReaderT Pool IO a
forall a. Client a -> ReaderT Pool IO a
client Client a
a) Pool
p

-- | Execute the given redis commands pipelined, i.e. commands are send in
-- batches to the server and the responses are fetched and parsed after
-- a full batch has been sent. A failing command which produces
-- a 'RedisError' will /not/ prevent subsequent commands from being
-- executed by the redis server. However the first error will be thrown as
-- an exception. To force sending see 'sync'.
commands :: MonadClient m => Redis IO a -> m a
commands :: Redis IO a -> m a
commands Redis IO a
a = Client a -> m a
forall (m :: * -> *) a. MonadClient m => Client a -> m a
liftClient (Client a -> m a) -> Client a -> m a
forall a b. (a -> b) -> a -> b
$ (Connection -> IO (a, [IO ()])) -> Client a
forall a. (Connection -> IO (a, [IO ()])) -> Client a
withConnection ((Connection -> Redis IO a -> IO (a, [IO ()]))
-> Redis IO a -> Connection -> IO (a, [IO ()])
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((forall a.
 Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ()))
-> Connection -> Redis IO a -> IO (a, [IO ()])
forall b.
(forall a.
 Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ()))
-> Connection -> Redis IO b -> IO (b, [IO ()])
eval forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getLazy) Redis IO a
a)

-- Force synchronisation after the given command. This will ensure all commands
-- given so far will be sent to the server.
sync :: Redis IO a -> Redis IO a
sync :: Redis IO a -> Redis IO a
sync Redis IO a
cmd = Redis IO a
cmd Redis IO a -> (a -> Redis IO a) -> Redis IO a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
x -> a
x a -> Redis IO a -> Redis IO a
`seq` a -> Redis IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x

-- | Execute the given publish\/subscribe commands.
-- The first parameter is the callback function which will be invoked with
-- a possible pattern (if @PSUBSCRIBE@ was used), channel, and message,
-- once messages arrive.
pubSub :: MonadClient m
       => (Maybe ByteString -> ByteString -> ByteString -> PubSub IO ())
       -> PubSub IO ()
       -> m ()
pubSub :: (Maybe ByteString -> ByteString -> ByteString -> PubSub IO ())
-> PubSub IO () -> m ()
pubSub Maybe ByteString -> ByteString -> ByteString -> PubSub IO ()
f PubSub IO ()
a = Client () -> m ()
forall (m :: * -> *) a. MonadClient m => Client a -> m a
liftClient (Client () -> m ()) -> Client () -> m ()
forall a b. (a -> b) -> a -> b
$ (Connection -> IO ((), [IO ()])) -> Client ()
forall a. (Connection -> IO (a, [IO ()])) -> Client a
withConnection (PubSub IO () -> Connection -> IO ((), [IO ()])
loop PubSub IO ()
a)
  where
    loop :: PubSub IO () -> Connection -> IO ((), [IO ()])
    loop :: PubSub IO () -> Connection -> IO ((), [IO ()])
loop PubSub IO ()
p Connection
h = do
        Connection -> PubSub IO () -> IO ()
cmds Connection
h PubSub IO ()
p
        Maybe (PubSub IO ())
r <- Connection -> IO (Maybe (PubSub IO ()))
responses Connection
h
        case Maybe (PubSub IO ())
r of
            Maybe (PubSub IO ())
Nothing -> ((), [IO ()]) -> IO ((), [IO ()])
forall (m :: * -> *) a. Monad m => a -> m a
return ((), [])
            Just  PubSub IO ()
k -> PubSub IO () -> Connection -> IO ((), [IO ()])
loop PubSub IO ()
k Connection
h

    cmds :: Connection -> PubSub IO () -> IO ()
    cmds :: Connection -> PubSub IO () -> IO ()
cmds Connection
h PubSub IO ()
c = do
        ProgramViewT PubSubCommand IO ()
r <- PubSub IO () -> IO (ProgramViewT PubSubCommand IO ())
forall (m :: * -> *) (instr :: * -> *) a.
Monad m =>
ProgramT instr m a -> m (ProgramViewT instr m a)
viewT PubSub IO ()
c
        case ProgramViewT PubSubCommand IO ()
r of
            Return              ()
x -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
x
            Subscribe    Resp
x :>>= b -> PubSub IO ()
k -> Connection -> Seq Resp -> IO ()
C.send Connection
h (Resp -> Seq Resp
forall a. a -> Seq a
Seq.singleton Resp
x) IO () -> (() -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Connection -> PubSub IO () -> IO ()
cmds Connection
h (PubSub IO () -> IO ()) -> (b -> PubSub IO ()) -> b -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> PubSub IO ()
k
            Unsubscribe  Resp
x :>>= b -> PubSub IO ()
k -> Connection -> Seq Resp -> IO ()
C.send Connection
h (Resp -> Seq Resp
forall a. a -> Seq a
Seq.singleton Resp
x) IO () -> (() -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Connection -> PubSub IO () -> IO ()
cmds Connection
h (PubSub IO () -> IO ()) -> (b -> PubSub IO ()) -> b -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> PubSub IO ()
k
            PSubscribe   Resp
x :>>= b -> PubSub IO ()
k -> Connection -> Seq Resp -> IO ()
C.send Connection
h (Resp -> Seq Resp
forall a. a -> Seq a
Seq.singleton Resp
x) IO () -> (() -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Connection -> PubSub IO () -> IO ()
cmds Connection
h (PubSub IO () -> IO ()) -> (b -> PubSub IO ()) -> b -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> PubSub IO ()
k
            PUnsubscribe Resp
x :>>= b -> PubSub IO ()
k -> Connection -> Seq Resp -> IO ()
C.send Connection
h (Resp -> Seq Resp
forall a. a -> Seq a
Seq.singleton Resp
x) IO () -> (() -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Connection -> PubSub IO () -> IO ()
cmds Connection
h (PubSub IO () -> IO ()) -> (b -> PubSub IO ()) -> b -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> PubSub IO ()
k

    responses :: Connection -> IO (Maybe (PubSub IO ()))
    responses :: Connection -> IO (Maybe (PubSub IO ()))
responses Connection
h = do
        Result PushMessage
m <- Resp -> Result PushMessage
readPushMessage (Resp -> Result PushMessage) -> IO Resp -> IO (Result PushMessage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Connection -> IO Resp
C.receive Connection
h
        case Result PushMessage
m of
            Right (Message      ByteString
ch ByteString
ms)     -> Maybe (PubSub IO ()) -> IO (Maybe (PubSub IO ()))
forall (m :: * -> *) a. Monad m => a -> m a
return (PubSub IO () -> Maybe (PubSub IO ())
forall a. a -> Maybe a
Just (PubSub IO () -> Maybe (PubSub IO ()))
-> PubSub IO () -> Maybe (PubSub IO ())
forall a b. (a -> b) -> a -> b
$ Maybe ByteString -> ByteString -> ByteString -> PubSub IO ()
f Maybe ByteString
forall a. Maybe a
Nothing    ByteString
ch ByteString
ms)
            Right (PMessage ByteString
pat ByteString
ch ByteString
ms)     -> Maybe (PubSub IO ()) -> IO (Maybe (PubSub IO ()))
forall (m :: * -> *) a. Monad m => a -> m a
return (PubSub IO () -> Maybe (PubSub IO ())
forall a. a -> Maybe a
Just (PubSub IO () -> Maybe (PubSub IO ()))
-> PubSub IO () -> Maybe (PubSub IO ())
forall a b. (a -> b) -> a -> b
$ Maybe ByteString -> ByteString -> ByteString -> PubSub IO ()
f (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
pat) ByteString
ch ByteString
ms)
            Right (UnsubscribeMessage ByteString
_ Int64
0) -> Maybe (PubSub IO ()) -> IO (Maybe (PubSub IO ()))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (PubSub IO ())
forall a. Maybe a
Nothing
            Right UnsubscribeMessage {}    -> Connection -> IO (Maybe (PubSub IO ()))
responses Connection
h
            Right SubscribeMessage   {}    -> Connection -> IO (Maybe (PubSub IO ()))
responses Connection
h
            Left  RedisError
e                        -> RedisError -> IO (Maybe (PubSub IO ()))
forall e a. Exception e => e -> IO a
throwIO RedisError
e

eval :: (forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ()))
     -> Connection
     -> Redis IO b
     -> IO (b, [IO ()])
eval :: (forall a.
 Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ()))
-> Connection -> Redis IO b -> IO (b, [IO ()])
eval forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
conn Redis IO b
red = Connection -> [IO ()] -> Redis IO b -> IO (b, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
conn [] Redis IO b
red
  where
    run :: Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
    run :: Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h [IO ()]
ii Redis IO a
c = do
        ProgramViewT Command IO a
r <- Redis IO a -> IO (ProgramViewT Command IO a)
forall (m :: * -> *) (instr :: * -> *) a.
Monad m =>
ProgramT instr m a -> m (ProgramViewT instr m a)
viewT Redis IO a
c
        case ProgramViewT Command IO a
r of
            Return a
a -> (a, [IO ()]) -> IO (a, [IO ()])
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, [IO ()]
ii)

            -- Connection
            Ping   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"PING" ByteString
"PONG") IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            Echo   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result b) -> IO (b, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result b
forall a. FromByteString a => String -> Resp -> Result a
readBulk String
"ECHO")        IO (b, IO ()) -> ((b, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(b
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
a
            Auth   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"AUTH" ByteString
"OK")   IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            Quit   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"QUIT" ByteString
"OK")   IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            Select Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"SELECT" ByteString
"OK") IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a

            -- Server
            BgRewriteAOF Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result ()
anyStr String
"BGREWRITEAOF")    IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            BgSave       Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result ()
anyStr String
"BGSAVE")          IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            Save         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"SAVE" ByteString
"OK")     IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            FlushAll     Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"FLUSHALL" ByteString
"OK") IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            FlushDb      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"FLUSHDB" ByteString
"OK")  IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            DbSize       Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"DBSIZE")         IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            LastSave     Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"LASTSAVE")       IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a

            -- Transactions
            Multi   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"MULTI" ByteString
"OK")   IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            Watch   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"WATCH" ByteString
"OK")   IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            Unwatch Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"UNWATCH" ByteString
"OK") IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            Discard Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"DISCARD" ByteString
"OK") IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            Exec    Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (Result () -> Resp -> Result ()
forall a b. a -> b -> a
const (Result () -> Resp -> Result ()) -> Result () -> Resp -> Result ()
forall a b. (a -> b) -> a -> b
$ () -> Result ()
forall a b. b -> Either a b
Right ())        IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a

            -- Keys
            Del       Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"DEL")             IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            Dump      Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Maybe ByteString))
-> IO (Maybe ByteString, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe ByteString)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"DUMP")      IO (Maybe ByteString, IO ())
-> ((Maybe ByteString, IO ()) -> IO (a, [IO ()]))
-> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe ByteString
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe ByteString
a
            Exists    Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"EXISTS")         IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            Expire    Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"EXPIRE")         IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            ExpireAt  Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"EXPIREAT")       IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            Persist   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"PERSIST")        IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            Keys      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [Key]) -> IO ([Key], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [Key]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"KEYS")           IO ([Key], IO ())
-> (([Key], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([Key]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[Key]
a
            RandomKey Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe Key)) -> IO (Maybe Key, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe Key)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"RANDOMKEY") IO (Maybe Key, IO ())
-> ((Maybe Key, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe Key
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe Key
a
            Rename    Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"RENAME" ByteString
"OK")    IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            RenameNx  Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"RENAMENX")       IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            Ttl       Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe TTL)) -> IO (Maybe TTL, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe TTL)
readTTL String
"TTL")             IO (Maybe TTL, IO ())
-> ((Maybe TTL, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe TTL
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe TTL
a
            Type      Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Maybe RedisType))
-> IO (Maybe RedisType, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe RedisType)
readType String
"TYPE")           IO (Maybe RedisType, IO ())
-> ((Maybe RedisType, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe RedisType
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe RedisType
a
            Scan      Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Cursor, [a1]))
-> IO ((Cursor, [a1]), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Cursor, [a1])
forall a.
FromByteString a =>
String -> Resp -> Result (Cursor, [a])
readScan String
"SCAN")           IO ((Cursor, [a1]), IO ())
-> (((Cursor, [a1]), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \((Cursor, [a1])
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
(Cursor, [a1])
a

            -- Strings
            Append   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"APPEND")        IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            Get      Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"GET")     IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            GetRange Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result b) -> IO (b, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result b
forall a. FromByteString a => String -> Resp -> Result a
readBulk String
"GETRANGE")     IO (b, IO ()) -> ((b, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(b
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
a
            GetSet   Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"GETSET")  IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            MGet     Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result [Maybe a1]) -> IO ([Maybe a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [Maybe a1]
forall a. FromByteString a => String -> Resp -> Result [Maybe a]
readListOfMaybes String
"MGET") IO ([Maybe a1], IO ())
-> (([Maybe a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([Maybe a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[Maybe a1]
a
            MSet     Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"MSET" ByteString
"OK")    IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            MSetNx   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"MSETNX")       IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            Set      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x Resp -> Result Bool
fromSet                   IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            SetRange Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"SETRANGE")      IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            StrLen   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"STRLEN")        IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a

            -- Bits
            BitAnd   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"BITOP")    IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            BitCount Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"BITCOUNT") IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            BitNot   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"BITOP")    IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            BitOr    Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"BITOP")    IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            BitPos   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"BITPOS")   IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            BitXOr   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"BITOP")    IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            GetBit   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"GETBIT")   IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            SetBit   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"SETBIT")   IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a

            -- Numeric
            Decr        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"DECR")         IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            DecrBy      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"DECRBY")       IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            Incr        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"INCR")         IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            IncrBy      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"INCRBY")       IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            IncrByFloat Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result b) -> IO (b, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result b
forall a. FromByteString a => String -> Resp -> Result a
readBulk String
"INCRBYFLOAT") IO (b, IO ()) -> ((b, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(b
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
a

            -- Hashes
            HDel         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"HDEL")           IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            HExists      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"HEXISTS")       IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            HGet         Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"HGET")     IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            HGetAll      Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result [(ByteString, a1)])
-> IO ([(ByteString, a1)], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [(ByteString, a1)]
forall a.
FromByteString a =>
String -> Resp -> Result [(ByteString, a)]
readFields String
"HGETALL")     IO ([(ByteString, a1)], IO ())
-> (([(ByteString, a1)], IO ()) -> IO (a, [IO ()]))
-> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([(ByteString, a1)]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[(ByteString, a1)]
a
            HIncrBy      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"HINCRBY")        IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            HIncrByFloat Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result b) -> IO (b, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result b
forall a. FromByteString a => String -> Resp -> Result a
readBulk String
"HINCRBYFLOAT")  IO (b, IO ()) -> ((b, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(b
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
a
            HKeys        Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result [ByteString])
-> IO ([ByteString], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [ByteString]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"HKEYS")         IO ([ByteString], IO ())
-> (([ByteString], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([ByteString]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[ByteString]
a
            HLen         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"HLEN")           IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            HMGet        Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result [Maybe a1]) -> IO ([Maybe a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [Maybe a1]
forall a. FromByteString a => String -> Resp -> Result [Maybe a]
readListOfMaybes String
"HMGET") IO ([Maybe a1], IO ())
-> (([Maybe a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([Maybe a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[Maybe a1]
a
            HMSet        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"HMSET" ByteString
"OK")    IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            HSet         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"HSET")          IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            HSetNx       Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"HSETNX")        IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            HVals        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [a1]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"HVALS")         IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a
            HScan        Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Cursor, [a1]))
-> IO ((Cursor, [a1]), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Cursor, [a1])
forall a.
FromByteString a =>
String -> Resp -> Result (Cursor, [a])
readScan String
"HSCAN")         IO ((Cursor, [a1]), IO ())
-> (((Cursor, [a1]), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \((Cursor, [a1])
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
(Cursor, [a1])
a

            -- Lists
            BLPop      Int64
t Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Maybe (Key, a1)))
-> IO (Maybe (Key, a1), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getNow (Int64 -> Connection -> Connection
withTimeout Int64
t Connection
h) Resp
x (String -> Resp -> Result (Maybe (Key, a1))
forall a.
FromByteString a =>
String -> Resp -> Result (Maybe (Key, a))
readKeyValue String
"BLPOP")       IO (Maybe (Key, a1), IO ())
-> ((Maybe (Key, a1), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe (Key, a1)
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe (Key, a1)
a
            BRPop      Int64
t Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Maybe (Key, a1)))
-> IO (Maybe (Key, a1), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getNow (Int64 -> Connection -> Connection
withTimeout Int64
t Connection
h) Resp
x (String -> Resp -> Result (Maybe (Key, a1))
forall a.
FromByteString a =>
String -> Resp -> Result (Maybe (Key, a))
readKeyValue String
"BRPOP")       IO (Maybe (Key, a1), IO ())
-> ((Maybe (Key, a1), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe (Key, a1)
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe (Key, a1)
a
            BRPopLPush Int64
t Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getNow (Int64 -> Connection -> Connection
withTimeout Int64
t Connection
h) Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"BRPOPLPUSH") IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            LIndex       Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"LINDEX")    IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            LInsert      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"LINSERT")         IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            LLen         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"LLEN")            IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            LPop         Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"LPOP")      IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            LPush        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"LPUSH")           IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            LPushX       Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"LPUSHX")          IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            LRange       Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [a1]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"LRANGE")         IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a
            LRem         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"LREM")            IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            LSet         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"LSET" ByteString
"OK")      IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            LTrim        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"LTRIM" ByteString
"OK")     IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a
            RPop         Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"RPOP")      IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            RPopLPush    Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"RPOPLPUSH") IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            RPush        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"RPUSH")           IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            RPushX       Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"RPUSHX")          IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a

            -- Sets
            SAdd          Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"SADD")                 IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            SCard         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"SCARD")                IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            SDiff         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [a1]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"SDIFF")               IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a
            SDiffStore    Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"SDIFFSTORE")           IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            SInter        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [a1]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"SINTER")              IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a
            SInterStore   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"SINTERSTORE")          IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            SIsMember     Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"SISMEMBER")           IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            SMembers      Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [a1]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"SMEMBERS")            IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a
            SMove         Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"SMOVE")               IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            SPop          Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp -> (Resp -> Result (Maybe a1)) -> IO (Maybe a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe a1)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"SPOP")           IO (Maybe a1, IO ())
-> ((Maybe a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe a1
a
            SRandMember Choose
y Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Choose -> Resp -> Result [a1]
forall a.
FromByteString a =>
String -> Choose -> Resp -> Result [a]
readBulk'Array String
"SRANDMEMBER" Choose
y) IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a
            SRem          Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"SREM")                 IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            SScan         Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Cursor, [a1]))
-> IO ((Cursor, [a1]), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Cursor, [a1])
forall a.
FromByteString a =>
String -> Resp -> Result (Cursor, [a])
readScan String
"SSCAN")               IO ((Cursor, [a1]), IO ())
-> (((Cursor, [a1]), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \((Cursor, [a1])
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
(Cursor, [a1])
a
            SUnion        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [a1]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"SUNION")              IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a
            SUnionStore   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"SUNIONSTORE")          IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a

            -- Sorted Sets
            ZAdd               Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZADD")                     IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZCard              Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZCARD")                    IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZCount             Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZCOUNT")                   IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZIncrBy            Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result b) -> IO (b, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result b
forall a. FromByteString a => String -> Resp -> Result a
readBulk String
"ZINCRBY")                 IO (b, IO ()) -> ((b, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(b
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
a
            ZInterStore        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZINTERSTORE")              IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZLexCount          Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZLEXCOUNT")                IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZRange           Bool
y Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (ScoreList a1))
-> IO (ScoreList a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Bool -> Resp -> Result (ScoreList a1)
forall a.
FromByteString a =>
String -> Bool -> Resp -> Result (ScoreList a)
readScoreList String
"ZRANGE" Bool
y)           IO (ScoreList a1, IO ())
-> ((ScoreList a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(ScoreList a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
ScoreList a1
a
            ZRangeByLex        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [a1]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"ZRANGEBYLEX")             IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a
            ZRangeByScore    Bool
y Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (ScoreList a1))
-> IO (ScoreList a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Bool -> Resp -> Result (ScoreList a1)
forall a.
FromByteString a =>
String -> Bool -> Resp -> Result (ScoreList a)
readScoreList String
"ZRANGEBYSCORE" Bool
y)    IO (ScoreList a1, IO ())
-> ((ScoreList a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(ScoreList a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
ScoreList a1
a
            ZRank              Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Maybe Int64))
-> IO (Maybe Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe Int64)
readInt'Null  String
"ZRANK")              IO (Maybe Int64, IO ())
-> ((Maybe Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe Int64
a
            ZRem               Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZREM")                     IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZRemRangeByLex     Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZREMRANGEBYLEX")           IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZRemRangeByRank    Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZREMRANGEBYRANK")          IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZRemRangeByScore   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZREMRANGEBYSCORE")         IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            ZRevRange        Bool
y Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (ScoreList a1))
-> IO (ScoreList a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Bool -> Resp -> Result (ScoreList a1)
forall a.
FromByteString a =>
String -> Bool -> Resp -> Result (ScoreList a)
readScoreList String
"ZREVRANGE" Bool
y)        IO (ScoreList a1, IO ())
-> ((ScoreList a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(ScoreList a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
ScoreList a1
a
            ZRevRangeByScore Bool
y Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (ScoreList a1))
-> IO (ScoreList a1, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Bool -> Resp -> Result (ScoreList a1)
forall a.
FromByteString a =>
String -> Bool -> Resp -> Result (ScoreList a)
readScoreList String
"ZREVRANGEBYSCORE" Bool
y) IO (ScoreList a1, IO ())
-> ((ScoreList a1, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(ScoreList a1
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
ScoreList a1
a
            ZRevRank           Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Maybe Int64))
-> IO (Maybe Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe Int64)
readInt'Null  String
"ZREVRANK")           IO (Maybe Int64, IO ())
-> ((Maybe Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe Int64
a
            ZScan              Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Cursor, [a1]))
-> IO ((Cursor, [a1]), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Cursor, [a1])
forall a.
FromByteString a =>
String -> Resp -> Result (Cursor, [a])
readScan String
"ZSCAN")                   IO ((Cursor, [a1]), IO ())
-> (((Cursor, [a1]), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \((Cursor, [a1])
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
(Cursor, [a1])
a
            ZScore             Resp
x :>>= b -> Redis IO a
k -> Connection
-> Resp
-> (Resp -> Result (Maybe Double))
-> IO (Maybe Double, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result (Maybe Double)
forall a. FromByteString a => String -> Resp -> Result (Maybe a)
readBulk'Null String
"ZSCORE")             IO (Maybe Double, IO ())
-> ((Maybe Double, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Maybe Double
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Maybe Double
a
            ZUnionStore        Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"ZUNIONSTORE")              IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a

            -- Sort
            Sort Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result [a1]) -> IO ([a1], IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result [a1]
forall a. FromByteString a => String -> Resp -> Result [a]
readList String
"SORT") IO ([a1], IO ())
-> (([a1], IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a1]
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
[a1]
a

            -- HyperLogLog
            PfAdd   Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Bool) -> IO (Bool, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Bool
readBool String
"PFADD")        IO (Bool, IO ())
-> ((Bool, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Bool
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Bool
a
            PfCount Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"PFCOUNT")       IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a
            PfMerge Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result ()) -> IO ((), IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
f Connection
h Resp
x (String -> ByteString -> Resp -> Result ()
matchStr String
"PFMERGE" ByteString
"OK") IO ((), IO ())
-> (((), IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(()
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
()
a

            -- Pub/Sub
            Publish Resp
x :>>= b -> Redis IO a
k -> Connection -> Resp -> (Resp -> Result Int64) -> IO (Int64, IO ())
forall a. Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getNow Connection
h Resp
x (String -> Resp -> Result Int64
readInt String
"PUBLISH") IO (Int64, IO ())
-> ((Int64, IO ()) -> IO (a, [IO ()])) -> IO (a, [IO ()])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Int64
a, IO ()
i) -> Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
forall a. Connection -> [IO ()] -> Redis IO a -> IO (a, [IO ()])
run Connection
h (IO ()
iIO () -> [IO ()] -> [IO ()]
forall a. a -> [a] -> [a]
:[IO ()]
ii) (Redis IO a -> IO (a, [IO ()])) -> Redis IO a -> IO (a, [IO ()])
forall a b. (a -> b) -> a -> b
$ b -> Redis IO a
k b
Int64
a

withConnection :: (Connection -> IO (a, [IO ()])) -> Client a
withConnection :: (Connection -> IO (a, [IO ()])) -> Client a
withConnection Connection -> IO (a, [IO ()])
f = do
    Pool
p <- Client Pool
forall r (m :: * -> *). MonadReader r m => m r
ask
    let c :: Pool Connection
c = Pool -> Pool Connection
connPool Pool
p
    Maybe a
x <- IO (Maybe a) -> Client (Maybe a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe a) -> Client (Maybe a))
-> IO (Maybe a) -> Client (Maybe a)
forall a b. (a -> b) -> a -> b
$ Pool Connection -> (Connection -> IO a) -> IO (Maybe a)
forall (m :: * -> *) a b.
MonadBaseControl IO m =>
Pool a -> (a -> m b) -> m (Maybe b)
tryWithResource Pool Connection
c ((Connection -> IO a) -> IO (Maybe a))
-> (Connection -> IO a) -> IO (Maybe a)
forall a b. (a -> b) -> a -> b
$ \Connection
h -> Connection -> IO (a, [IO ()])
f Connection
h IO (a, [IO ()]) -> ((a, [IO ()]) -> IO a) -> IO a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(a
a, [IO ()]
i) -> [IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [IO ()]
i IO () -> IO a -> IO a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
    Client a -> (a -> Client a) -> Maybe a -> Client a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ConnectionError -> Client a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM ConnectionError
ConnectionsBusy) a -> Client a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
x

getLazy :: Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getLazy :: Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getLazy Connection
h Resp
x Resp -> Result a
g = do
    IORef Resp
r <- Resp -> IO (IORef Resp)
forall a. a -> IO (IORef a)
newIORef (RedisError -> Resp
forall a e. Exception e => e -> a
throw (RedisError -> Resp) -> RedisError -> Resp
forall a b. (a -> b) -> a -> b
$ ByteString -> RedisError
RedisError ByteString
"missing response")
    Resp -> IORef Resp -> Connection -> IO ()
C.request Resp
x IORef Resp
r Connection
h
    a
a <- IO a -> IO a
forall a. IO a -> IO a
unsafeInterleaveIO (IO a -> IO a) -> IO a -> IO a
forall a b. (a -> b) -> a -> b
$ do
        Connection -> IO ()
C.sync Connection
h
        (RedisError -> IO a) -> (a -> IO a) -> Result a -> IO a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either RedisError -> IO a
forall e a. Exception e => e -> IO a
throwIO a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result a -> IO a) -> IO (Result a) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Resp -> Result a
g (Resp -> Result a) -> IO Resp -> IO (Result a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IORef Resp -> IO Resp
forall a. IORef a -> IO a
readIORef IORef Resp
r
    (a, IO ()) -> IO (a, IO ())
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, a
a a -> IO () -> IO ()
`seq` () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
{-# INLINE getLazy #-}

getNow :: Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getNow :: Connection -> Resp -> (Resp -> Result a) -> IO (a, IO ())
getNow Connection
h Resp
x Resp -> Result a
g = do
    IORef Resp
r <- Resp -> IO (IORef Resp)
forall a. a -> IO (IORef a)
newIORef (RedisError -> Resp
forall a e. Exception e => e -> a
throw (RedisError -> Resp) -> RedisError -> Resp
forall a b. (a -> b) -> a -> b
$ ByteString -> RedisError
RedisError ByteString
"missing response")
    Resp -> IORef Resp -> Connection -> IO ()
C.request Resp
x IORef Resp
r Connection
h
    Connection -> IO ()
C.sync Connection
h
    a
a <- (RedisError -> IO a) -> (a -> IO a) -> Result a -> IO a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either RedisError -> IO a
forall e a. Exception e => e -> IO a
throwIO a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result a -> IO a) -> IO (Result a) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Resp -> Result a
g (Resp -> Result a) -> IO Resp -> IO (Result a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IORef Resp -> IO Resp
forall a. IORef a -> IO a
readIORef IORef Resp
r
    (a, IO ()) -> IO (a, IO ())
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
{-# INLINE getNow #-}

-- Update a 'Connection's send/recv timeout. Values > 0 get an additional
-- 10s grace period added to give redis enough time to finish first.
withTimeout :: Int64 -> Connection -> Connection
withTimeout :: Int64 -> Connection -> Connection
withTimeout Int64
0 Connection
c = Connection
c { settings :: Settings
C.settings = NominalDiffTime -> Settings -> Settings
setSendRecvTimeout NominalDiffTime
0                     (Connection -> Settings
C.settings Connection
c) }
withTimeout Int64
t Connection
c = Connection
c { settings :: Settings
C.settings = NominalDiffTime -> Settings -> Settings
setSendRecvTimeout (NominalDiffTime
10 NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall a. Num a => a -> a -> a
+ Int64 -> NominalDiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
t) (Connection -> Settings
C.settings Connection
c) }
{-# INLINE withTimeout #-}

tryAll :: NonEmpty a -> (a -> IO b) -> IO b
tryAll :: NonEmpty a -> (a -> IO b) -> IO b
tryAll (a
a :| []) a -> IO b
f = a -> IO b
f a
a
tryAll (a
a :| [a]
aa) a -> IO b
f = a -> IO b
f a
a IO b -> (SomeException -> IO b) -> IO b
forall (m :: * -> *) a.
MonadCatch m =>
m a -> (SomeException -> m a) -> m a
`catchAll` (IO b -> SomeException -> IO b
forall a b. a -> b -> a
const (IO b -> SomeException -> IO b) -> IO b -> SomeException -> IO b
forall a b. (a -> b) -> a -> b
$ NonEmpty a -> (a -> IO b) -> IO b
forall a b. NonEmpty a -> (a -> IO b) -> IO b
tryAll ([a] -> NonEmpty a
forall a. [a] -> NonEmpty a
NE.fromList [a]
aa) a -> IO b
f)
{-# INLINE tryAll #-}