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:
- Client connections: RESP from applications.
- 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 #
| Step | Behaviour |
|---|---|
| Parsing | RESP arrays, plus inline (telnet-style) commands |
| Command name | Lowercased before dispatch — commands are case-insensitive |
| Pipelining | Supported: requests are executed in order, replies are written in order |
| Connection state | Only AUTH state per connection; no per-connection database, no SELECT |
| Built-ins | PING, ECHO, QUIT, AUTH, SHUTDOWN are answered by the server before dispatch |
| Everything else | Dispatched 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 value | RESP |
|---|---|
nil | null bulk $-1 |
[]byte / string | bulk string $n |
[][]byte / []string / []interface{} | array *n |
redcon.SimpleString | simple string +… |
redcon.SimpleInt, int64, int | integer :n |
error | error -… |
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 #
| Situation | Reply |
|---|---|
| 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 topology | CLUSTER 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:
| Prefix | Meaning |
|---|---|
-ERR … | Bad arguments, bad syntax, failed validation |
-MOVED … / -TRY … | Redirect to the leader |
-CLUSTERDOWN … | No leader / no quorum |
-unauthorized | AUTH missing or wrong |
-ERR invalid key size / invalid value size | ledis 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).