Skip to main content

Redis

The Redis Serialization Protocol (RESP) carries client-server communication. Each element opens with a single byte identifying its type, and every element ends with a CRLF.

DataStream negotiates RESP3, the protocol introduced with Redis 6, by issuing HELLO 3 on connection. A server that does not understand HELLO falls back to RESP2.

Request Format

A client sends a command as an array of bulk strings—the command name followed by its arguments. PSUBSCRIBE logs.* travels as:

*2\r\n$10\r\nPSUBSCRIBE\r\n$6\r\nlogs.*\r\n

RESP2 Types

These five types exist in both versions of the protocol.

TypeIndicatorFormatExample
Simple String++<string>\r\n+OK\r\n
Error--<error>\r\n-ERR unknown command\r\n
Integer::<number>\r\n:1000\r\n
Bulk String$$<length>\r\n<string>\r\n$5\r\nhello\r\n
Array**<count>\r\n<elements>*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n

RESP3 Types

RESP3 adds the following.

TypeIndicatorFormat
Null__\r\n
Boolean##t\r\n or #f\r\n
Double,,<number>\r\n
Big Number((<number>\r\n
Bulk Error!!<length>\r\n<error>\r\n
Verbatim String==<length>\r\n<encoding>:<string>\r\n
Map%%<pairs>\r\n<key-value elements>
Set~~<count>\r\n<elements>
Push>><count>\r\n<elements>
Attribute||<pairs>\r\n<key-value elements>

Push Messages

Push (>) is the type that carries every event DataStream ingests. In RESP2 a subscription delivery arrives as an ordinary array; in RESP3 it arrives as a push so a client can distinguish server-initiated data from command replies on the same connection.

The device subscribes by pattern, so deliveries are pmessage rather than message and carry four elements:

>4\r\n$8\r\npmessage\r\n$6\r\nlogs.*\r\n$9\r\nlogs.auth\r\n$15\r\n{"event":"..."}\r\n

In order: the kind, the pattern that matched, the channel the message was published to, and the payload.

Authentication

Credentials are sent with HELLO 3 AUTH <username> <password>, or with AUTH on a connection that has already been established.

A password with no username authenticates against the server's requirepass setting, which Redis treats as the default user. Supplying both a username and a password authenticates against an ACL user.