| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.Redis.Connection
Synopsis
- data Connection
- data ConnectInfo = ConnInfo {
- connectAddr :: !ConnectAddr
- connectAuth :: !(Maybe ByteString)
- connectUsername :: !(Maybe ByteString)
- connectDatabase :: !Integer
- connectMaxConnections :: !Int
- connectNumStripes :: !(Maybe Int)
- connectMaxIdleTime :: !NominalDiffTime
- connectTimeout :: !(Maybe NominalDiffTime)
- connectTLSParams :: !(Maybe ClientParams)
- connectHooks :: !Hooks
- connectPoolLabel :: !Text
- data ConnectError
- defaultConnectInfo :: ConnectInfo
- createConnection :: ConnectInfo -> IO Connection
- connect :: ConnectInfo -> IO Connection
- checkedConnect :: ConnectInfo -> IO Connection
- checkedConnectCluster :: ConnectInfo -> IO Connection
- newtype ClusterDownError = ClusterDownError ClusterInfoResponse
- disconnect :: Connection -> IO ()
- withConnect :: (MonadMask m, MonadIO m) => ConnectInfo -> (Connection -> m c) -> m c
- withCheckedConnect :: ConnectInfo -> (Connection -> IO c) -> IO c
- runRedis :: Connection -> Redis a -> IO a
- runRedisNonBlocking :: Connection -> Redis a -> IO (Maybe a)
- newtype ClusterConnectError = ClusterConnectError Reply
- connectCluster :: ConnectInfo -> IO Connection
- shardMapFromClusterSlotsResponse :: ClusterSlotsResponse -> IO ShardMap
- refreshShardMap :: Connection -> IO ShardMap
Documentation
data Connection Source #
A threadsafe pool of network connections to a Redis server. Use the
connect function to create one.
Constructors
| NonClusteredConnection (Pool Connection) | |
| ClusteredConnection (MVar ShardMap) (Pool Connection) |
data ConnectInfo Source #
Information for connnecting to a Redis server.
It is recommended to not use the ConnInfo data constructor directly.
Instead use defaultConnectInfo and update it with record syntax. For
example to connect to a password protected Redis server running on localhost
and listening to the default port:
myConnectInfo :: ConnectInfo
myConnectInfo = defaultConnectInfo {connectAuth = Just "secret"}
Or better yet, use parseConnectInfo to parse a URL.
Constructors
| ConnInfo | |
Fields
| |
Instances
| Show ConnectInfo Source # | |
Defined in Database.Redis.Connection Methods showsPrec :: Int -> ConnectInfo -> ShowS # show :: ConnectInfo -> String # showList :: [ConnectInfo] -> ShowS # | |
data ConnectError Source #
Constructors
| ConnectAuthError Reply | |
| ConnectSelectError Reply |
Instances
| Exception ConnectError Source # | |
Defined in Database.Redis.Connection Methods toException :: ConnectError -> SomeException # fromException :: SomeException -> Maybe ConnectError # displayException :: ConnectError -> String # backtraceDesired :: ConnectError -> Bool # | |
| Show ConnectError Source # | |
Defined in Database.Redis.Connection Methods showsPrec :: Int -> ConnectError -> ShowS # show :: ConnectError -> String # showList :: [ConnectError] -> ShowS # | |
| Eq ConnectError Source # | |
Defined in Database.Redis.Connection | |
defaultConnectInfo :: ConnectInfo Source #
Default information for connecting:
connectAddr = ConnectAddrHostPort "localhost" 6379 -- Redis default port connectAuth = Nothing -- No password connectUsername = Nothing -- No user connectDatabase = 0 -- SELECT database 0 connectMaxConnections = 50 -- Up to 50 connections connectNumStripes = Just 1 -- A single stripe connectMaxIdleTime = 30 -- Keep open for 30 seconds connectTimeout = Nothing -- Don't add timeout logic connectTLSParams = Nothing -- Do not use TLS connectHooks = defaultHooks -- Do nothing connectPoolLabel = "" -- no label
connect :: ConnectInfo -> IO Connection Source #
Constructs a Connection pool to a Redis server designated by the
given ConnectInfo.
The function always succeeds, because the first connection is not actually established until the first call to the server.
checkedConnect :: ConnectInfo -> IO Connection Source #
Constructs a Connection pool to a Redis server designated by the
given ConnectInfo, then tests if the server is actually there.
Throws an ConnectError exception if the connection to the Redis server can't be
established.
checkedConnectCluster :: ConnectInfo -> IO Connection Source #
Constructs a Connection pool to a Redis cluster designated by the
given ConnectInfo, then tests if the server is actually there.
Throws an ClusterConnectError exception if the connection to the Redis server can't be
established.
newtype ClusterDownError Source #
Constructors
| ClusterDownError ClusterInfoResponse |
Instances
| Exception ClusterDownError Source # | |
Defined in Database.Redis.Connection Methods toException :: ClusterDownError -> SomeException # fromException :: SomeException -> Maybe ClusterDownError # | |
| Show ClusterDownError Source # | |
Defined in Database.Redis.Connection Methods showsPrec :: Int -> ClusterDownError -> ShowS # show :: ClusterDownError -> String # showList :: [ClusterDownError] -> ShowS # | |
| Eq ClusterDownError Source # | |
Defined in Database.Redis.Connection Methods (==) :: ClusterDownError -> ClusterDownError -> Bool # (/=) :: ClusterDownError -> ClusterDownError -> Bool # | |
disconnect :: Connection -> IO () Source #
Destroy all idle resources in the pool, works for all types of the connection.
withConnect :: (MonadMask m, MonadIO m) => ConnectInfo -> (Connection -> m c) -> m c Source #
Memory bracket around connect and disconnect.
withCheckedConnect :: ConnectInfo -> (Connection -> IO c) -> IO c Source #
Memory bracket around checkedConnect and disconnect
runRedis :: Connection -> Redis a -> IO a Source #
Interact with a Redis datastore specified by the given Connection.
Each call of runRedis takes a network connection from the Connection
pool and runs the given Redis action. Calls to runRedis may thus block
while all connections from the pool are in use.
runRedisNonBlocking :: Connection -> Redis a -> IO (Maybe a) Source #
Interact with a Redis datastore specified by the given Connection, but return early
if acquiring from the connection pool would block.
Like runRedis, but if all connections in the Connection pool are used, it
immediately returns Nothing. This can be useful for logging purposes.
newtype ClusterConnectError Source #
Constructors
| ClusterConnectError Reply |
Instances
| Exception ClusterConnectError Source # | |
Defined in Database.Redis.Connection | |
| Show ClusterConnectError Source # | |
Defined in Database.Redis.Connection Methods showsPrec :: Int -> ClusterConnectError -> ShowS # show :: ClusterConnectError -> String # showList :: [ClusterConnectError] -> ShowS # | |
| Eq ClusterConnectError Source # | |
Defined in Database.Redis.Connection Methods (==) :: ClusterConnectError -> ClusterConnectError -> Bool # (/=) :: ClusterConnectError -> ClusterConnectError -> Bool # | |
connectCluster :: ConnectInfo -> IO Connection Source #
Constructs a ShardMap of connections to clustered nodes. The argument is
a ConnectInfo for any node in the cluster
Some Redis commands are currently not supported in cluster mode - CONFIG, AUTH - SCAN - MOVE, SELECT - RESET
refreshShardMap :: Connection -> IO ShardMap Source #