Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
RESP is the wire protocol that Redis uses. The latest version is RESP3, which at time of writing seems relatively complete, but may still be evolving.
This module parses the entire RESP3 spec (as of 2024-01-26), but also parses some invalid RESP forms that Redis may return, eg `-nan`, and parses RESP2 forms that have been removed from the spec (eg `$-1\r\n`).
Synopsis
- data RespMessage
- = RespPush !ByteString ![RespExpr]
- | RespReply !RespExpr
- data RespExpr
- = RespString !ByteString
- | RespBlob !ByteString
- | RespStreamingBlob !ByteString
- | RespStringError !ByteString
- | RespBlobError !ByteString
- | RespArray ![RespExpr]
- | RespInteger !Int64
- | RespNull
- | RespBool !Bool
- | RespDouble !Double
- | RespVerbatimString !ByteString
- | RespVerbatimMarkdown !ByteString
- | RespBigInteger !Integer
- | RespMap ![(RespExpr, RespExpr)]
- | RespSet ![RespExpr]
- | RespAttribute ![(RespExpr, RespExpr)] RespExpr
- parseMessage :: Scanner RespMessage
- parseExpression :: Scanner RespExpr
Documentation
data RespMessage Source #
A message from the server (eg. Redis) to the client. This can be a push message (for pub/sub), or a reply to a command issued by the client.
Instances
RESP3 Expression.
This descriminates the difference between RespString and RespBlob, even though both contain bytestrings, in order to not throw away information. A caller might care whether the response was delivered with "+", or "$".
We do not, however descriminate between the different encodings of null. As far as I can tell, these are considered a mistake in the previous versions of the RESP spec, and clients should treat the different encodings the same.
Why don't we parse RespString
into Text
? Well, the caller might
not actually need to decode it into text, and so we let the caller
decide. This way, we don't have to deal with encoding errors.
Similarly, we don't parse a RespMap
into a HashMap
,
because that would involve imposing our choice of data structure on
the caller. The caller might want to use HashMap
,
Map
, iterate over the elements, or just use the lookup
function.
Instances
parseMessage :: Scanner RespMessage Source #
Parse a RESP3 message
parseExpression :: Scanner RespExpr Source #
Parse a RESP3 expression