ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
redis_resp.h File Reference

RESP, the Redis serialization protocol: the command encoder and the reply parser (PROTOCORE_ENABLE_REDIS). More...

#include "protocore_config.h"

Go to the source code of this file.

Detailed Description

RESP, the Redis serialization protocol: the command encoder and the reply parser (PROTOCORE_ENABLE_REDIS).

The governing specification is not an IETF document and carries no RFC number. It is the Redis project's "Redis serialization protocol specification" (https://redis.io/docs/latest/develop/reference/protocol-spec), whose RESP3 half is also specified in redis/redis-specifications, protocol/RESP3.md. Section names below are that document's headings.

"Sending commands to a Redis server": a client sends the server "an array consisting of only bulk strings", the first bulk string being the command's name and the rest its arguments, so LLEN mylist goes out as *2\r\n$4\r\nLLEN\r\n$6\r\nmylist\r\n. An encode builds that array.

"RESP protocol description" gives the first byte of every type. RESP2 (Redis 2.0): Simple strings +, Simple errors -, Integers :, Bulk strings $ with Null bulk strings $-1\r\n, and Arrays * with Null arrays *-1\r\n. RESP3 (Redis 6.0, negotiated by the HELLO command of "Client handshake") adds Nulls _, Booleans #, Doubles ,, Big numbers (, Bulk errors !, Verbatim strings =, Maps %, Sets ~ and Pushes >. Any other first byte, the Attributes type | included, fails the parse.

The parser is a cursor. One call decodes the value at the head of the buffered octets and reports how many octets that value occupied. An aggregate header (Arrays, Sets, Pushes, Maps) reports the header alone and the count of children that follow, and the caller parses each child from the remaining octets: a map of N entries reports 2*N children, one per key and one per value. Nothing recurses and nothing is allocated.

A decoded string points into the buffer that was parsed and is never copied, so a caller walking an aggregate takes what it needs from RespNs::reply before the next parse overwrites it.

The module exports one symbol, Resp. Everything in redis_resp.c has internal linkage.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file redis_resp.h.