-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from kakkun61/hooks
Introducing hooks
- Loading branch information
Showing
10 changed files
with
204 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Database.Redis.Hooks where | ||
|
||
import Data.ByteString (ByteString) | ||
import Database.Redis.Protocol (Reply) | ||
import {-# SOURCE #-} Database.Redis.PubSub (Message, PubSub) | ||
|
||
data Hooks = | ||
Hooks | ||
{ sendRequestHook :: SendRequestHook | ||
, sendPubSubHook :: SendPubSubHook | ||
, callbackHook :: CallbackHook | ||
, sendHook :: SendHook | ||
, receiveHook :: ReceiveHook | ||
} | ||
|
||
-- | A hook for sending commands to the server and receiving replys from the server. | ||
type SendRequestHook = ([ByteString] -> IO Reply) -> [ByteString] -> IO Reply | ||
|
||
-- | A hook for sending pub/sub messages to the server. | ||
type SendPubSubHook = ([ByteString] -> IO ()) -> [ByteString] -> IO () | ||
|
||
-- | A hook for invoking callbacks with pub/sub messages. | ||
type CallbackHook = (Message -> IO PubSub) -> Message -> IO PubSub | ||
|
||
-- | A hook for just sending raw data to the server. | ||
type SendHook = (ByteString -> IO ()) -> ByteString -> IO () | ||
|
||
-- | A hook for receiving raw data from the server. | ||
type ReceiveHook = IO Reply -> IO Reply | ||
|
||
-- | The default hooks. | ||
-- Every hook is the identity function. | ||
defaultHooks :: Hooks | ||
defaultHooks = | ||
Hooks | ||
{ sendRequestHook = id | ||
, sendPubSubHook = id | ||
, callbackHook = id | ||
, sendHook = id | ||
, receiveHook = id | ||
} | ||
|
||
instance Show Hooks where | ||
show _ = "Hooks {sendRequestHook = _, sendPubSubHook = _, callbackHook = _, sendHook = _, receiveHook = _}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.