Created
June 19, 2016 17:27
-
-
Save banacorn/087159a36adfb27a7f10a8e59b879571 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{-# LANGUAGE OverloadedStrings, DataKinds, DeriveGeneric #-} | |
module MQ where | |
import Database.Edis | |
import Data.ByteString | |
import Data.Serialize | |
import GHC.Generics | |
data Message = Msg ByteString Integer deriving (Show, Generic) | |
instance Serialize Message where | |
fromRight :: Either a b -> b | |
fromRight (Right x) = x | |
fromRight (Left _) = error "Left" | |
push msg = unEdis $ start | |
>>> declare (Proxy :: Proxy "id") (Proxy :: Proxy Integer) | |
>>> declare (Proxy :: Proxy "queue") (Proxy :: Proxy (ListOf Message)) | |
>>> incr (Proxy :: Proxy "id") | |
`bind` \i -> lpush (Proxy :: Proxy "queue") (Msg msg (fromRight i)) | |
pop = unEdis $ start | |
>>> declare (Proxy :: Proxy "queue") (Proxy :: Proxy (ListOf Message)) | |
>>> lpop (Proxy :: Proxy "queue") | |
main :: IO () | |
main = do | |
conn <- connect defaultConnectInfo | |
result <- runRedis conn $ do | |
push "hello" | |
pop | |
print $ result | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment