Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multithreaded Pub/Sub message processing #77

Merged
merged 3 commits into from
Aug 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion hedis.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ library
ghc-prof-options: -auto-all
exposed-modules: Database.Redis
build-depends: scanner >= 0.2,
async >= 2.1,
base >= 4.6 && < 5,
bytestring >= 0.9,
bytestring-lexing >= 0.5,
unordered-containers,
text,
deepseq,
mtl >= 2,
network >= 2,
resource-pool >= 0.2,
stm,
time,
vector >= 0.9

Expand Down Expand Up @@ -100,12 +103,17 @@ benchmark hedis-benchmark

test-suite hedis-test
type: exitcode-stdio-1.0
main-is: test/Test.hs
hs-source-dirs: test
main-is: Test.hs
other-modules: PubSubTest
build-depends:
base == 4.*,
bytestring >= 0.10,
hedis,
HUnit,
async,
stm,
text,
mtl == 2.*,
slave-thread,
test-framework,
Expand Down
3 changes: 1 addition & 2 deletions src/Database/Redis/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, CPP #-}

module Database.Redis.Core (
Connection, connect,
Connection(..), connect,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose keeping this type abstract, while providing unConnection deconstructor which would be explicitly said to be internal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kept internal to hedis, the Core module is never exported so this isn't leaking out anywhere in the public API. I just needed it in PubSub.hs. Now if you are talking about protecting Core.hs from the rest of hedis itself I guess we can use a unConnection destructor.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, then we don't need this, sorry.

ConnectInfo(..), defaultConnectInfo,
Redis(), runRedis, unRedis, reRedis,
RedisCtx(..), MonadRedis(..),
Expand Down Expand Up @@ -40,7 +40,6 @@ newtype Redis a = Redis (ReaderT RedisEnv IO a)

data RedisEnv = Env { envConn :: PP.Connection, envLastReply :: IORef Reply }


-- |This class captures the following behaviour: In a context @m@, a command
-- will return it's result wrapped in a \"container\" of type @f@.
--
Expand Down
8 changes: 7 additions & 1 deletion src/Database/Redis/ProtocolPipelining.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
--
module Database.Redis.ProtocolPipelining (
Connection,
connect, disconnect, request, send, recv,
connect, disconnect, request, send, recv, flush,
ConnectionLostException(..),
HostName, PortID(..)
) where
Expand Down Expand Up @@ -92,6 +92,12 @@ recv Conn{..} = do
writeIORef connReplies rs
return r

-- | Flush the socket. Normally, the socket is flushed in 'recv' (actually 'conGetReplies'), but
-- for the multithreaded pub/sub code, the sending thread needs to explicitly flush the subscription
-- change requests.
flush :: Connection -> IO ()
flush Conn{..} = hFlush connHandle

-- |Send a request and receive the corresponding reply
request :: Connection -> S.ByteString -> IO Reply
request conn req = send conn req >> recv conn
Expand Down
Loading