snaplet-redis-0.1.6.1: Redis support for Snap Framework
Safe HaskellNone
LanguageHaskell2010

Snap.Snaplet.RedisDB

Description

Redis DB snaplet.

Synopsis

Documentation

newtype RedisDB Source #

Snaplet's state data type

Constructors

RedisDB 

Fields

runRedisDB :: (MonadIO m, MonadState app m) => Lens' app (Snaplet RedisDB) -> Redis a -> m a Source #

Perform action using Redis connection from RedisDB snaplet pool (wrapper for runRedis).

runRedisDB database $ do set "hello" "world"

redisConnection :: Lens' RedisDB Connection Source #

A lens to retrieve the connection to Redis from the RedisDB wrapper.

redisDBInit Source #

Arguments

:: ConnectInfo

Information for connnecting to a Redis server.

-> SnapletInit b RedisDB 

Make RedisDB snaplet and initialize database connection.

appInit :: SnapletInit MyApp MyApp appInit = makeSnaplet "app" "App with Redis child snaplet" Nothing $ do d <- nestSnaplet "" database $ redisDBInit defaultConnectInfo return $ MyApp d

redisDBInitConf :: SnapletInit b RedisDB Source #

Make RedisDB snaplet and initialize database connection from snaplet config file. Options are read from the "redis" section of the application config (e.g. ./devel.cfg) or from the main section of the Redis snaplet config (e.g. .snapletsredis/devel.cfg).

Every field is optional and defaults to defaultConnectInfo values.

redis { host = "192.168.0.42" port = 31415 auth = "i am so secret" max_connections = 1 max_idle_time = 0.5 }

Alternately, you can configure it to connect via a socket, for example:

redis { port = "/var/run/redis/redis.sock" }

This corresponds to setting:

connectPort = UnixSocket "/var/run/redis/redis.sock"

in ConnectInfo. In this case, the host setting, if anything, is ignored.

appInit :: SnapletInit MyApp MyApp appInit = makeSnaplet "app" "App with Redis child snaplet" Nothing $ do d <- nestSnaplet "redis" database redisDBInitConf return $ MyApp d