wire / wire-format / redis-resp
Redis uses RESP (REdis Serialization Protocol), a text-based protocol. RESP3 (Redis 6+) adds new types. Types: Simple String (+...\r\n), Error (-...\r\n), Integer (:...\r\n), Bulk String ($len\r\n data \r\n), Array (*count\r\n ...), Null (_\r\n), Boolean (#t/f\r\n), Double (,...\r\n), Big Number (,...\r\n), Bulk Error (!len\r\n ...), Verbatim String (=len\r\n fmt:...), Map (%count\r\n), Set (~count\r\n), Attribute (|count\r\n), Push (>count\r\n).
aka: Redis RESP (REdis Serialization Protocol)
spec: Redis protocol specification
Redis uses RESP (REdis Serialization Protocol), a text-based protocol. RESP3 (Redis 6+) adds new types. Types: Simple String (+...\r\n), Error (-...\r\n), Integer (:...\r\n), Bulk String ($len\r\n data \r\n), Array (*count\r\n ...), Null (_\r\n), Boolean (#t/f\r\n), Double (,...\r\n), Big Number (,...\r\n), Bulk Error (!len\r\n ...), Verbatim String (=len\r\n fmt:...), Map (%count\r\n), Set (~count\r\n), Attribute (|count\r\n), Push (>count\r\n).
| field | size | meaning |
|---|---|---|
| Simple String | variable | '+' + string + '\r\n'. No binary data, no newlines. |
| Error | variable | '-' + error message + '\r\n'. |
| Integer | variable | ':' + integer + '\r\n'. |
| Bulk String | variable | '$' + length + '\r\n' + data + '\r\n'. Length -1 = null. |
| Array | variable | '*' + count + '\r\n' + elements. Count -1 = null. |
| Null (RESP3) | 3 bytes | '_\r\n'. |
| Boolean (RESP3) | 4 bytes | '#t\r\n' or '#f\r\n'. |
| Double (RESP3) | variable | ',' + double + '\r\n' (e.g. ',3.14159\r\n' or ',inf\r\n'). |
| Map (RESP3) | variable | '%' + count + '\r\n' + key-value pairs. |
| Set (RESP3) | variable | '~' + count + '\r\n' + elements. |
| Push (RESP3) | variable | '>' + count + '\r\n' + elements (for pub/sub messages). |
example:
2a 32 0d 0a 24 34 0d 0a 50 49 4e 47 0d 0a 24 34 0d 0a 70 6f 6e 67 0d 0a
RESP Array: *2\r\n $4\r\n PING\r\n $4\r\n pong\r\n
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/redis-resp
or /wire-format/redis-resp.json