PubSubMessage
is the decoded form of a reply pushed to a subscribed
connection. After subscribe or
psubscribe, read the stream of pushed replies with
next-message, which turns each raw RESP value
into one of these variants using decode-message.
(match (Redis.subscribe &r @"news")
(Result.Success _)
(match (Redis.next-message &r)
(Result.Success msg)
(match msg
(PubSubMessage.Message channel payload)
(println* "got " &payload " on " &channel)
(PubSubMessage.Subscribe channel count)
(println* "subscribed to " &channel)
_ (println* "other pub/sub reply"))
(Result.Error e) (IO.errorln &e))
(Result.Error e) (IO.errorln &e))
decode-message
(Fn [(Ref RESP a)] (Result PubSubMessage String))
(decode-message r)
decodes a pushed pub/sub reply r into a PubSubMessage.
The reply is expected to be a RESP.Arr whose first element is a bulk string
naming the kind (message, pmessage, subscribe, unsubscribe,
psubscribe or punsubscribe). Returns an Error for any other RESP shape,
an unknown kind, a wrong element count, or a field of the wrong type.
delete
(Fn [PubSubMessage] ())
deletes a PubSubMessage. This should usually not be called manually.