Skip to content

Instantly share code, notes, and snippets.

@banacorn
Created June 19, 2016 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banacorn/087159a36adfb27a7f10a8e59b879571 to your computer and use it in GitHub Desktop.
Save banacorn/087159a36adfb27a7f10a8e59b879571 to your computer and use it in GitHub Desktop.
{-# 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