Unlike many web services that use HTTP, Redis uses a custom protocol known as the Redis Serialization Protocol (RESP) for communication between clients and servers.
What is RESP?
RESP, or Redis Serialization Protocol, is the wire protocol used by Redis clients (including redis-cli
) to communicate with the Redis server. It defines the way data is serialized and transmitted over the network.
A wire protocol is the formal specification of how data is formatted and exchanged between two systems over a network connection. — Wikipedia
RESP is lightweight, efficient, and designed specifically for Redis — but it can be reused in any client-server software.
RESP vs HTTP
Redis does not use HTTP. Instead, it defines its own set of commands and responses via RESP. Here’s how RESP equivalents map to typical HTTP operations:
HTTP Feature | Redis Equivalent |
---|---|
GET /resource | GET key |
POST /resource | SET key value |
PUT /resource | SET key value , or HSET , JSON.SET (module) |
DELETE /resource | DEL key |
200 OK | +OK |
404 Not Found | (nil) |
500 Internal Error | -ERR <message> |
403 Forbidden | -NOAUTH Authentication required. |
Unlike HTTP, RESP is not based on request methods or status codes. Instead, Redis commands and responses follow a minimal and efficient format optimized for performance.
RESP Characteristics
Feature | Description |
---|---|
Text-based | Commands and responses are human-readable (but binary-safe for values). |
Persistent TCP | Communication happens over a persistent TCP connection (default port: 6379 ). |
Request/Response Model | Clients issue commands (e.g. SET key value ) and Redis replies with a response. |
RESP works over TCP or Unix sockets, not HTTP. You can even telnet into Redis and type RESP commands manually.
RESP Data Types
RESP supports the following basic data types:
Type | Prefix | Description |
---|---|---|
Simple String | + | Usually used for status replies. |
Error | - | Used to signal errors. |
Integer | : | Used to return numeric values (e.g. result of INCR ). |
Bulk String | $ | String with specified length, can include binary-safe data. |
Null Bulk | $-1 | Used to represent a null value. |
Array | * | List of other RESP types. |
Null Array | *-1 | Used to represent a null array (RESP3). |
Map (RESP3) | % | Key-value pairs (available in RESP3). |
Set (RESP3) | ~ | Unordered collection of unique elements (RESP3). |
Boolean (RESP3) | # | true or false in RESP3. |
Double (RESP3) | , | Floating point number in RESP3. |
Security in RESP
Security in RESP is minimal by default, because Redis was designed for trusted local environments. Here’s what that means:
- RESP is plaintext, meaning commands and data are sent unencrypted.
- Optional password authentication via
requirepass
. - No user roles (before Redis 6).
- Redis will accept any client connection if the port is reachable.
- From Redis 6 onward, SSL/TLS support is available (needs to be compiled in), enabling encrypted RESP communication over TLS — just like HTTPS vs HTTP.
More on Redis TLS support
RESP Versions
Version | Introduced In | Features |
---|---|---|
RESP2 | Redis 2.x | Basic protocol used by most clients today. Fast and text-based. |
RESP3 | Redis 6.0 | Supports richer data types, attribute metadata, and introspection. |
Introspection in RESP3 allows clients to query metadata about the server or connection, improving diagnostics and tooling.
Summary
Redis’s RESP protocol is a prime example of designing a protocol specifically for performance, simplicity, and predictability. While it lacks the verbosity and feature set of HTTP, it excels in its intended domain — powering fast, efficient key-value operations over a lightweight protocol.
- Official RESP Spec: redis.io/docs/latest/develop/reference/protocol-spec
- Build Your Own Redis (CodeCrafters): codecrafters.io