nri-redis-0.1.0.4: An intuitive hedis wrapper library.
Safe HaskellNone
LanguageHaskell2010

Redis.List

Description

A simple Redis library providing high level access to Redis features we use here at NoRedInk

As with our Ruby Redis access, we enforce working within a "namespace".

Synopsis

Creating a redis handler

handler :: Text -> Settings -> Acquire Handler Source #

Produce a namespaced handler for Redis access.

data Handler Source #

The redis handler allows applications to run scoped IO

data Settings Source #

Settings required to initiate a redis connection.

Constructors

Settings 

Fields

  • connectionInfo :: ConnectInfo

    Full redis connection string.

    Default env var name is REDIS_CONNECTION_STRING default is "redis://localhost:6379"

  • clusterMode :: ClusterMode

    Set to 1 for cluster, everything else is not.

    Default env var name is REDIS_CLUSTER Default is 0

  • defaultExpiry :: DefaultExpiry

    Set a default amount of seconds after which all keys touched by this handler will expire. The expire time of a key is reset every time it is read or written. A value of 0 means no default expiry.

    Default env var name is REDIS_DEFAULT_EXPIRY_SECONDS default is 0

  • queryTimeout :: QueryTimeout

    0 means no timeout, every other value is a timeout in milliseconds.

    Default env var name is REDIS_QUERY_TIMEOUT_MILLISECONDS default is 1000

  • maxKeySize :: MaxKeySize
     

decoder :: Decoder Settings Source #

decodes Settings from environmental variables

Creating a redis API

jsonApi :: forall a key. (ToJSON a, FromJSON a) => (key -> Text) -> Api key a Source #

Creates a json API mapping a key to a json-encodable-decodable type

data Key = Key { fieldA: Text, fieldB: Text }
data Val = Val { ... }

myJsonApi :: Redis.Api Key Val
myJsonApi = Redis.jsonApi (\Key {fieldA,

textApi :: (key -> Text) -> Api key Text Source #

Creates a Redis API mapping a key to Text

byteStringApi :: (key -> Text) -> Api key ByteString Source #

Creates a Redis API mapping a key to a ByteString

data Api key a Source #

a API type can be used to enforce a mapping of keys to values. without an API type, it can be easy to naiively serialize the wrong type into a redis key.

Out of the box, we have helpers to support - jsonApi for json-encodable and decodable values - textApi for Text values - byteStringApi for ByteString values

Creating redis queries

del :: Api key a -> NonEmpty key -> Query Int Source #

Removes the specified keys. A key is ignored if it does not exist.

https://redis.io/commands/del

exists :: Api key a -> key -> Query Bool Source #

Returns if key exists.

https://redis.io/commands/exists

expire :: Api key a -> key -> Int -> Query () Source #

Set a timeout on key. After the timeout has expired, the key will automatically be deleted. A key with an associated timeout is often said to be volatile in Redis terminology.

https://redis.io/commands/expire

ping :: Api key a -> Query () Source #

Returns PONG if no argument is provided, otherwise return a copy of the argument as a bulk. This command is often used to test if a connection is still alive, or to measure latency.

https://redis.io/commands/ping

lrange :: Api key a -> key -> Int -> Int -> Query [a] Source #

Returns the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on.

These offsets can also be negative numbers indicating offsets starting at the end of the list. For example, -1 is the last element of the list, -2 the penultimate, and so on.

rpush :: Api key a -> key -> NonEmpty a -> Query Int Source #

Insert all the specified values at the tail of the list stored at key. If key does not exist, it is created as empty list before performing the push operation. When key holds a value that is not a list, an error is returned.

https://redis.io/commands/rpush

Running Redis queries

query :: HasCallStack => Handler -> Query a -> Task Error a Source #

Run a Query. Note: A Query in this library can consist of one or more queries in sequence. if a Query contains multiple queries, it may make more sense, if possible to run them using transaction

transaction :: HasCallStack => Handler -> Query a -> Task Error a Source #

Run a redis Query in a transaction. If the query contains several Redis commands they're all executed together, and Redis will guarantee other requests won't be able change values in between.

In redis terms, this is wrappping the Query in MULTI and `EXEC see redis transaction semantics here: https://redis.io/topics/transactions

data Query a Source #

A Redis query

Instances

Instances details
Functor Query Source # 
Instance details

Defined in Redis.Internal

Methods

fmap :: (a -> b) -> Query a -> Query b #

(<$) :: a -> Query b -> Query a #

Show (Query a) Source # 
Instance details

Defined in Redis.Internal

Methods

showsPrec :: Int -> Query a -> ShowS #

show :: Query a -> String #

showList :: [Query a] -> ShowS #

data Error Source #

Redis Errors, scoped by where they originate.

Instances

Instances details
Show Error Source # 
Instance details

Defined in Redis.Internal

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

ToJSON Error Source # 
Instance details

Defined in Redis.Internal

map :: (a -> b) -> Query a -> Query b Source #

Used to map the type of a query to another type useful in combination with transaction

map2 :: (a -> b -> c) -> Query a -> Query b -> Query c Source #

Used to combine two queries Useful to combine two queries. Redis.map2 (Maybe.map2 (,)) (Redis.get api1 key) (Redis.get api2 key) |> Redis.query redis

map3 :: (a -> b -> c -> d) -> Query a -> Query b -> Query c -> Query d Source #

Used to combine three queries Useful to combine three queries.

sequence :: List (Query a) -> Query (List a) Source #

Used to run a series of queries in sequence. Useful to run a list of queries in sequence. queries |> Redis.sequence |> Redis.query redis