Skip to content

Instantly share code, notes, and snippets.

@banacorn
Created Jun 19, 2016
Embed
What would you like to do?
{-# 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