Expand description
RESP2: the Redis serialization protocol, encoder and decoder.
RESP is five type-tagged, CRLF-terminated forms:
+OK\r\n simple string
-ERR unknown command\r\n error
:42\r\n integer
$5\r\nhello\r\n bulk string (a length, then exactly that many bytes)
$-1\r\n the null bulk string — "no such key"
*2\r\n:1\r\n:2\r\n array, which may nestCommands go the other way as an array of bulk strings, which is the only form a Redis server accepts from a client and the only one that is safe: because every argument carries its own byte length, a value containing a newline, a space, or a quote cannot be read as a second argument. That is this module’s answer to command injection, and it is why nothing here ever builds a command by formatting a string.
The decoder is incremental: decode returns Ok(None) when the buffer
holds only part of a reply, so the connection can read more bytes and try
again without any framing state of its own.
Enums§
- Value
- One decoded RESP value.
Functions§
- decode
- Decode one value from the front of
input. - encode_
command - Encode a command as an array of bulk strings.