Protocol

Protocol layer #

The engine speaks RESP — the Redis serialization protocol — so any Redis client works without a shim. This page covers what the protocol layer does beyond parsing bytes.

One socket, two protocols #

There is exactly one TCP listener (tcp4, address from -a). On it arrive:

  1. Client connections: RESP from applications.
  2. Peer connections: the Raft transport between nodes.

They are told apart by a sniffing listener: a peer opens the connection by writing a fixed magic marker followed by the cluster auth token (transportMarker in vendor/github.com/tidwall/uhaha), and anything that does not start with that marker is treated as a RESP client. This is why TLS, the port and --advertise are shared between data and replication traffic — and why --advertise must name the address peers can reach.

Request handling #

StepBehaviour
ParsingRESP arrays, plus inline (telnet-style) commands
Command nameLowercased before dispatch — commands are case-insensitive
PipeliningSupported: requests are executed in order, replies are written in order
Connection stateOnly AUTH state per connection; no per-connection database, no SELECT
Built-insPING, ECHO, QUIT, AUTH, SHUTDOWN are answered by the server before dispatch
Everything elseDispatched to the command table (110 data commands + RAFT/CLUSTER/MACHINE/BARRIER/VERSION)

Unknown commands answer ERR unknown command '<name>'.

Reply mapping #

Handlers return Go values; the RESP writer maps them mechanically:

Go valueRESP
nilnull bulk $-1
[]byte / stringbulk string $n
[][]byte / []string / []interface{}array *n
redcon.SimpleStringsimple string +…
redcon.SimpleInt, int64, intinteger :n
errorerror -…

Values are never returned as simple strings: a simple string cannot carry \r\n, and a value with a CRLF in it would corrupt the stream.

Cluster semantics on the wire #

SituationReply
Write or leader-only read sent to a follower-MOVED 0 <advertised-addr>
Same, with --try-errors-TRY <advertised-addr>
No leader (no quorum)-CLUSTERDOWN …
Cluster-aware client asks for topologyCLUSTER SLOTS → one range 0-16383 on the leader; CLUSTER NODES/INFO

The MOVED slot is always 0: there is no sharding, so every key “belongs” to the single master. A client that follows MOVED redirects ends up on the leader, which is exactly the intended behaviour.

Errors #

All errors are RESP errors, and they use Redis’ prefixes where a client library looks for them:

PrefixMeaning
-ERR …Bad arguments, bad syntax, failed validation
-MOVED … / -TRY …Redirect to the leader
-CLUSTERDOWN …No leader / no quorum
-unauthorizedAUTH missing or wrong
-ERR invalid key size / invalid value sizeledis limits: key ≤ 1024 B, value ≤ 1 GiB

WRONGTYPE is never produced — see Compatibility.

Not in the protocol layer #

No MULTI/EXEC, no SUBSCRIBE, no WATCH, no inline SELECT. Pub/sub lives in a different binary ( IceFireDB-PubSub).