RESP3 protocol encoder and decoder.
Pure functions — no processes, no side effects. Encodes commands to iodata and decodes binary wire data to Elixir terms.
RESP3 Type Mapping
| Wire prefix | RESP3 Type | Elixir Type |
|---|---|---|
+ | Simple string | String.t() |
$ | Blob string | String.t() |
- | Simple error | %Redis.Error{} |
! | Blob error | %Redis.Error{} |
: | Number | integer() |
, | Double | float() |
# | Boolean | boolean() |
_ | Null | nil |
* | Array | list() |
% | Map | map() |
~ | Set | MapSet.t() |
> | Push | {:push, list()} |
= | Verbatim string | String.t() (encoding stripped) |
( | Big number | integer() |
Summary
Functions
Decodes a RESP3 response from binary data.
Returns {:ok, term, rest} or {:continuation, fun} if more data is needed.
Encodes a command (list of strings/binaries) into RESP3 wire format. Returns iodata for efficient socket writing.
Encodes multiple commands for pipelining. Returns iodata.
Functions
Decodes a RESP3 response from binary data.
Returns {:ok, term, rest} or {:continuation, fun} if more data is needed.
Encodes a command (list of strings/binaries) into RESP3 wire format. Returns iodata for efficient socket writing.
iex> Redis.Protocol.RESP3.encode(["SET", "key", "value"]) |> IO.iodata_to_binary()
"*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n"
Encodes multiple commands for pipelining. Returns iodata.