{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
module Redis.List
(
Real.handler,
Internal.Handler,
Settings.Settings (..),
Settings.decoder,
jsonApi,
textApi,
byteStringApi,
Api,
del,
exists,
expire,
ping,
lrange,
rpush,
Internal.query,
Internal.transaction,
Internal.Query,
Internal.Error (..),
Internal.map,
Internal.map2,
Internal.map3,
Internal.sequence,
)
where
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as ByteString
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NonEmpty
import qualified Redis.Codec as Codec
import qualified Redis.Internal as Internal
import qualified Redis.Real as Real
import qualified Redis.Settings as Settings
import qualified Prelude
data Api key a = Api
{
Api key a -> NonEmpty key -> Query Int
del :: NonEmpty key -> Internal.Query Int,
Api key a -> key -> Query Bool
exists :: key -> Internal.Query Bool,
Api key a -> key -> Int -> Query ()
expire :: key -> Int -> Internal.Query (),
Api key a -> Query ()
ping :: Internal.Query (),
Api key a -> key -> Int -> Int -> Query [a]
lrange :: key -> Int -> Int -> Internal.Query [a],
Api key a -> key -> NonEmpty a -> Query Int
rpush :: key -> NonEmpty a -> Internal.Query Int
}
jsonApi ::
forall a key.
(Aeson.ToJSON a, Aeson.FromJSON a) =>
(key -> Text) ->
Api key a
jsonApi :: (key -> Text) -> Api key a
jsonApi = Codec a -> (key -> Text) -> Api key a
forall a key. Codec a -> (key -> Text) -> Api key a
makeApi Codec a
forall a. (FromJSON a, ToJSON a) => Codec a
Codec.jsonCodec
textApi :: (key -> Text) -> Api key Text
textApi :: (key -> Text) -> Api key Text
textApi = Codec Text -> (key -> Text) -> Api key Text
forall a key. Codec a -> (key -> Text) -> Api key a
makeApi Codec Text
Codec.textCodec
byteStringApi :: (key -> Text) -> Api key ByteString.ByteString
byteStringApi :: (key -> Text) -> Api key ByteString
byteStringApi = Codec ByteString -> (key -> Text) -> Api key ByteString
forall a key. Codec a -> (key -> Text) -> Api key a
makeApi Codec ByteString
Codec.byteStringCodec
makeApi ::
Codec.Codec a ->
(key -> Text) ->
Api key a
makeApi :: Codec a -> (key -> Text) -> Api key a
makeApi Codec.Codec {Encoder a
codecEncoder :: forall a. Codec a -> Encoder a
codecEncoder :: Encoder a
Codec.codecEncoder, Decoder a
codecDecoder :: forall a. Codec a -> Decoder a
codecDecoder :: Decoder a
Codec.codecDecoder} key -> Text
toKey =
Api :: forall key a.
(NonEmpty key -> Query Int)
-> (key -> Query Bool)
-> (key -> Int -> Query ())
-> Query ()
-> (key -> Int -> Int -> Query [a])
-> (key -> NonEmpty a -> Query Int)
-> Api key a
Api
{ del :: NonEmpty key -> Query Int
del = NonEmpty Text -> Query Int
Internal.Del (NonEmpty Text -> Query Int)
-> (NonEmpty key -> NonEmpty Text) -> NonEmpty key -> Query Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
<< (key -> Text) -> NonEmpty key -> NonEmpty Text
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NonEmpty.map key -> Text
toKey,
exists :: key -> Query Bool
exists = Text -> Query Bool
Internal.Exists (Text -> Query Bool) -> (key -> Text) -> key -> Query Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
<< key -> Text
toKey,
expire :: key -> Int -> Query ()
expire = \key
key Int
secs -> Text -> Int -> Query ()
Internal.Expire (key -> Text
toKey key
key) Int
secs,
ping :: Query ()
ping = Query Status
Internal.Ping Query Status -> (Query Status -> Query ()) -> Query ()
forall a b. a -> (a -> b) -> b
|> (Status -> ()) -> Query Status -> Query ()
forall (m :: * -> *) a value.
Functor m =>
(a -> value) -> m a -> m value
map (\Status
_ -> ()),
lrange :: key -> Int -> Int -> Query [a]
lrange = \key
key Int
lower Int
upper ->
Text -> Int -> Int -> Query [ByteString]
Internal.Lrange (key -> Text
toKey key
key) Int
lower Int
upper
Query [ByteString]
-> (Query [ByteString] -> Query [a]) -> Query [a]
forall a b. a -> (a -> b) -> b
|> ([ByteString] -> Result Error [a])
-> Query [ByteString] -> Query [a]
forall a b. (a -> Result Error b) -> Query a -> Query b
Internal.WithResult (Decoder a -> [ByteString] -> Result Error [a]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
Prelude.traverse Decoder a
codecDecoder),
rpush :: key -> NonEmpty a -> Query Int
rpush = \key
key NonEmpty a
vals ->
Text -> NonEmpty ByteString -> Query Int
Internal.Rpush (key -> Text
toKey key
key) (Encoder a -> NonEmpty a -> NonEmpty ByteString
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NonEmpty.map Encoder a
codecEncoder NonEmpty a
vals)
}