HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Modulehedis-0.16.4Haskell2010

Database.Redis.Hooks

Hooks for observing or wrapping Redis I/O.

Hooks are installed through connect defaultConnectInfo { connectHooks = ... } and wrap the low-level actions used by hedis:

The common pattern is to start from defaultHooks and override only the hook(s) you need. Each hook receives the original action and is expected to call it after performing any extra work such as logging, tracing, metrics, or timing.

Hooks can be used to alter existing behavior, or used to add metrics or telemetry to the redis application.

Example:

import Data.IORef
import Database.Redis

data Counts = Counts
  { sendRequestCount :: Word
  , sendCount :: Word
  , receiveCount :: Word
  }

hooks :: IORef Counts -> Hooks
hooks ref =
  defaultHooks
    { sendRequestHook = \run argv -> do
        modifyIORef ref $ \c -> c { sendRequestCount = sendRequestCount c + 1 }
        run argv
    , sendHook = \sendBytes bytes -> do
        modifyIORef ref $ \c -> c { sendCount = sendCount c + 1 }
        sendBytes bytes
    , receiveHook = \recvReply -> do
        modifyIORef ref $ \c -> c { receiveCount = receiveCount c + 1 }
        recvReply
    }

main :: IO ()
main = do
  ref <- newIORef (Counts 0 0 0)
  conn <- connect defaultConnectInfo { connectHooks = hooks ref }
  _ <- runRedis conn $ set "key" "value"
  readIORef ref >>= print
  • 6 types
  • 1 value
  • Packagehedis-0.16.4
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceHooks.hs
typetype SendHook = (ByteString -> IO ()) -> ByteString -> IO ()
#

A hook for sending raw bytes to the server.

This sits below request rendering and can be used to observe the exact wire payload sent on the socket.