在Hedis 的文档中,给出了使用该pubSub
函数的示例:
pubSub :: PubSub -> (Message -> IO PubSub) -> Redis ()
pubSub (subscribe ["chat"]) $ \msg -> do
putStrLn $ "Message from " ++ show (msgChannel msg)
return $ unsubscribe ["chat"]
鉴于pubSub
返回 a ,是否可以从回调外部在代码中进一步Redis ()
重用此消息?msg
我pubSub
从一个在 monad 中运行的 Scotty 端点打电话ScottyM
,应该返回(长话短说)json msg
myEndpoint :: ScottyM ()
myEndpoint =
post "/hello/world" $ do
data :: MyData <- jsonData
runRedis redisConn $ do
pubSub (subscribe ["channel"]) $ \msg -> do
doSomethingWith msg
return $ unsubscribe ["channel"]
-- how is it possible to retrieve `msg` from here?
json $ somethingBuiltFromMsg
或者,有没有办法json
在回调中使用 Scotty's?到目前为止,我还无法做到这一点。