RESP2 vs RESP3: The Bytes Don't Name the Version
Why identical Redis payloads can be valid in RESP2 and RESP3, what RESP3 markers prove, and how DevKit handles ambiguity, attributes, pushes and streams.
A RESP decoder can consume every byte correctly and still not know which version the connection negotiated. Consider five bytes:
hex: 2b 4f 4b 0d 0a
escaped: +OK\r\n
That is a simple string in both RESP2 and RESP3. There is no version bit, magic number or envelope naming the grammar. Labeling it “RESP3” chooses a display convention; it does not recover a fact. That missing context breaks reply-only captures, exported buffers and mixed-connection logs.
The handshake is the missing metadata
RESP3 is mostly a superset of RESP2. Simple strings (+), simple errors (-), integers (:), bulk strings ($) and arrays (*) retain their basic syntax. A valid RESP2 buffer can therefore be valid RESP3.
Connections start in RESP2. A client requests RESP3 with HELLO 3; success changes the connection's version and returns a map reply. The request is an ordinary RESP array, so bytes spelling HELLO 3 do not prove success. Authentication failure, an unsupported version or another error can leave the connection in RESP2. The observed exchange is the evidence.
A capture that keeps only the final reply loses that context. An RESP3-only marker proves RESP3 syntax, not the negotiation history; its absence proves nothing about the version.
One buffer, two complete candidates
DevKit's Auto mode parses the complete input as RESP3 and as RESP2. For the five-byte +OK\r\n vector, the project's test suite verifies that both candidates are complete, each consumes 5 bytes, each produces one item and each has zero errors. Auto reports version ambiguity rather than inventing certainty.
The same ambiguity survives a plausible “map-like” shape:
hex: 2a 32 0d 0a 24 31 0d 0a 61 0d 0a 24 31 0d 0a 62 0d 0a
escaped: *2\r\n$1\r\na\r\n$1\r\nb\r\n
Both grammars produce a two-element array, ["a", "b"]. It could be a list, or it could be a command whose arguments happen to look like a key and value. The bytes do not decide.
Redis's RESP2 convention represents a map as a flat array of alternating keys and values. RESP3 adds an explicit % map marker. That does not authorize a schemaless tool to promote every even-length RESP2 array into a map. Doing so would require guessing command semantics. DevKit preserves the array and its order; it does not pair commands with replies or infer that a particular Redis command returned it.
What RESP3 adds
RESP3's extra markers carry information RESP2 cannot express. They are structural evidence, not alternative spellings.
| Marker | Type | Exact example | Meaning |
|---|---|---|---|
_ |
Null | _\r\n |
Dedicated null; empty payload required |
# |
Boolean | #t\r\n, #f\r\n |
Explicit true or false |
, |
Double | ,1.25\r\n, ,inf\r\n |
Float, including -inf and nan |
( |
Big number | (3492890328409238509324850943850943825024385\r\n |
Integer outside signed 64-bit range |
! |
Blob error | !3\r\nERR\r\n |
Length-delimited error |
= |
Verbatim string | =15\r\ntxt:Some string\r\n |
Encoding hint, colon, payload |
% |
Map | %1\r\n+a\r\n:1\r\n |
Explicit key/value pairs |
~ |
Set | ~2\r\n+x\r\n+y\r\n |
Explicit set aggregate |
| |
Attribute | |1\r\n+ttl\r\n:3600\r\n:3\r\n |
Metadata for the following value |
> |
Push | >2\r\n+message\r\n+news\r\n |
Out-of-band value |
Maps preserve arbitrary typed keys and values instead of forcing JavaScript object properties. Sets and arrays keep distinct types. Exported JSON wraps big numbers as $bigint to preserve precision and binary as Base64 $binary rather than mislabeling it as text.
RESP3 null is exactly 5f 0d 0a; _garbage\r\n is malformed. RESP2's $-1\r\n and *-1\r\n are null forms; $0\r\n\r\n is empty, not null. The suite's 31-byte vector verifies null bulk, null array, empty bulk and a valid -ERR expected\r\n reply. A protocol error reply is a valid decoded value, not a parser failure.
Attributes belong to exactly one following value
An attribute map is auxiliary data, not another element to append to the result. It augments the value that immediately follows it. The bundled example is:
hex: 2a 33 0d 0a 3a 31 0d 0a 3a 32 0d 0a 7c 31 0d 0a
2b 74 74 6c 0d 0a 3a 33 36 30 30 0d 0a 3a 33 0d 0a
escaped: *3\r\n:1\r\n:2\r\n|1\r\n+ttl\r\n:3600\r\n:3\r\n
The result is [1, 2, 3], with {ttl: 3600} attached to the third value. The test asserts the exact typed JSON wrapper and three child nodes: attribute key, attribute value and the value being described.
Pushes are not nested replies
RESP3 pushes may appear before or after ordinary values and may arrive without a command. They are out-of-band, so the parser rejects a push inside an aggregate. The suite's *1\r\n>0\r\n fails at byte offset 4. DevKit displays push structure but does not reconstruct Pub/Sub subscriptions or decide which command, if any, a push relates to.
Streaming needs a terminator, not a total length
A streamed string replaces the bulk length with ?, then sends length-prefixed chunks and a zero-length final chunk:
$?\r\n;5\r\nHello\r\n;6\r\n world\r\n;0\r\n
The suite verifies concatenation to Hello world, and a separate binary vector verifies that chunk bytes 00 ff 61 and bc become a five-byte value with Base64 AP9hYmM=. The decoded value is text only when the concatenated bytes are valid UTF-8; otherwise it remains explicitly binary.
Streamed arrays, sets and maps similarly replace their count with ? and end with .CRLF. A streamed map must contain an even number of values. Redis's documentation states that Redis itself does not emit streamed strings or streamed aggregates because its RESP3 support excludes streamed types. RESP3 permits modules to use the encoding, with the documentation explicitly noting this for streamed strings. Supporting the grammar is therefore useful, but a streamed vector must not be presented as something Redis core normally sends.
The project's 17 empirical test groups
I ran the exact command npx tsx scripts/test-resp-wire.ts. All 17 groups passed, ending with 1..17. These are DevKit's own specification vectors and regression assertions—not an independent comparison against a running Redis server. No Redis connection was made for this article.
| # | Test group | Asserted result |
|---|---|---|
| 1 | RESP2 command array | LLEN, mylist; one item; spans [4,14) and [14,26) |
| 2 | RESP2 nulls and errors | Four valid items; empty bulk stays "" |
| 3 | Integer boundaries | Signed 64-bit maximum and minimum retained exactly |
| 4 | RESP3 scalars | Eight items covering null, booleans, doubles, bignum and verbatim |
| 5 | Map, set and push | Three typed aggregates; arbitrary keys preserved |
| 6 | Attributes | ttl: 3600 attaches only to the following 3 |
| 7 | Streamed binary string | Five bytes, three children, $binary: "AP9hYmM=" |
| 8 | Streamed aggregates | String, nested array/set and map all terminate correctly |
| 9 | Blob error and binary | ERR error plus Base64 /wA= binary |
| 10 | Manual RESP2 mode | #t\r\n rejected as RESP3-only |
| 11 | Auto ambiguity | +OK\r\n ambiguous; #t\r\n uniquely RESP3 |
| 12 | Malformed CRLF and lengths | Seven invalid inputs produce located errors |
| 13 | Output budget | A 1,700,000-byte text payload is partial, not falsely complete |
| 14 | Stream failures | Truncated chunk and unpaired streamed-map key diagnosed |
| 15 | Nested push | Rejected at offset 4 |
| 16 | Count and depth limits | 50,001 children and excessive nesting fail safely |
| 17 | Bundled samples | Four valid samples complete; malformed sample is partial |
The bundled RESP3 sample decodes to 176 bytes, seven top-level items and zero errors. That agrees with the previously recorded browser regression. The same earlier browser run, not repeated here, verified that 125 items paginate as 120 + 5, while 900 items occupying 5,400 bytes render 800 + 100 tree rows and 4,096 + 1,304 hex bytes. Those are UI regression counts, not production traffic measurements.
Truncation is not the same as an error reply
The malformed sample is exactly 15 bytes:
hex: 2a 32 0d 0a 24 35 0d 0a 68 65 6c 6c 6f 0d 0a
escaped: *2\r\n$5\r\nhello\r\n
It declares two array elements but supplies only one. Both version candidates stop at offset 15 with unexpected end of input, and the result is partial. By contrast, -ERR expected\r\n is a complete, valid error value.
Other real failure vectors show why diagnostics need to name the rule:
| Input | Result |
|---|---|
+OK\n |
Partial: simple string is not terminated by CRLF |
*-2\r\n |
Partial: aggregate length must not be negative |
$-2\r\n |
Partial: blob length must not be negative |
#x\r\n |
Partial: boolean must be t or f |
,1.2.3\r\n |
Partial: invalid RESP3 double |
:9223372036854775808\r\n |
Partial: exceeds signed 64-bit range |
_garbage\r\n |
Partial: RESP3 null requires an empty payload |
$?\r\n;5\r\nhi\r\n |
Partial at offset 8: chunk length 5 overruns input by one byte |
%?\r\n+k\r\n.\r\n |
Partial: streamed map contains an unpaired key |
*1\r\n>0\r\n |
Partial at offset 4: push cannot be nested |
A clean parse means the selected grammar consumed the supplied buffer without errors. It does not mean the bytes came from Redis, that a command/reply relationship is known, or that a transport capture has been reconstructed.
A decision procedure for ambiguous captures
- If you observed a successful
HELLOexchange, keep that context. Pin the negotiated version. This is stronger evidence than the shape of an ordinary reply. - If you see a valid RESP3-only marker, record “RESP3 syntax present.” That includes
%,#,_, pushes and streamed framing. It still does not identify the server implementation. - If both grammars consume everything, preserve the ambiguity. Do not turn a convenient default into a claim about the connection.
- If no candidate completes, inspect the first diagnostic offset. Check CRLF, declared lengths, missing terminators and whether you pasted transport framing instead of raw RESP.
- Keep semantics separate from syntax. An array is not a map merely because its length is even; a push is not a reply merely because it follows one.
For hands-on inspection, use the RESP2/RESP3 Decoder. It accepts hex or Base64, decodes consecutive top-level values locally, exposes candidate results and byte offsets, and exports typed JSON. It does not connect to Redis, pair commands and replies, reconstruct Pub/Sub or parse PCAP files. Remove transport framing before pasting; share links contain the original bytes, so use non-sensitive samples.
Checked implementation limits
The current code caps input at 2,000,000 bytes and charges a separate 20,000,000-unit estimated output budget for text and retained bytes. It allows at most 50,000 decoded nodes, 50,000 child values in a fixed container, 20,000 top-level items and 1,000 diagnostics. Nesting starts at depth 0 and rejects depth greater than 256. Streamed strings have a 2 MB total cap; streamed aggregates allow up to 100,000 child values plus their terminator. Integer lines allow at most 4,096 digits, with ordinary : integers additionally restricted to signed 64-bit range.
The interface paginates rather than rendering everything at once: 120 top-level items, 800 tree rows and 4,096 hex bytes per page. The selected item's on-screen JSON preview stops at 65,536 characters, while copy and download retain the complete JSON. Exceeding a limit produces a partial result with a diagnostic; it is not reported as successful completion.
References:
Environment: Node.js v24.22.0 on Windows x64, verified 2026-11-27. The 17-group suite was rerun with npx tsx scripts/test-resp-wire.ts; byte constants and decoder outputs were checked directly against lib/resp-wire.ts. The browser pagination figures are previously recorded regression results and were not rerun for this article.