Redis - 5. Debugging
Redis - 5. Debugging
Debugging
5.1 Identify the type of data structure pointed to by an unknown key. https://redis.io/commands/type
Determine which operations are being sent to a Redis server using the https://redis.io/commands/
5.2
MONITOR command. MONITOR
Understand that the protocol uses prefixed lengths to indicate the size of
a response. For example, a response beginning with *275 indicates a
response containing an array having 275 elements.
https://redis.io/commands/
Understand the OBJECT command.
object
Redis Protocol specification Redis clients communicate with the Redis server using a protocol called RESP
(REdis Serialization Protocol). While the protocol was designed specifically for Redis, it can be used for other
client-server software projects.
RESP is a compromise between the following things:
Simple to implement.
Fast to parse.
Human readable.
RESP can serialize different data types like integers, strings, arrays. There is also a specific type for errors.
Requests are sent from the client to the Redis server as arrays of strings representing the arguments of the
command to execute. Redis replies with a command-specific data type.
RESP is binary-safe and does not require processing of bulk data transferred from one process to another,
because it uses prefixed-length to transfer bulk data.
Note: the protocol outlined here is only used for client-server communication. Redis Cluster uses a different
binary protocol in order to exchange messages between nodes.
Networking layer A client connects to a Redis server creating a TCP connection to the port 6379.
While RESP is technically non-TCP specific, in the context of Redis the protocol is only used with TCP
connections (or equivalent stream oriented connections like Unix sockets).
Request-Response model Redis accepts commands composed of different arguments. Once a command is
received, it is processed and a reply is sent back to the client.
This is the simplest model possible, however there are two exceptions:
Redis supports pipelining (covered later in this document). So it is possible for clients to send multiple
commands at once, and wait for replies later.
When a Redis client subscribes to a Pub/Sub channel, the protocol changes semantics and becomes a push
protocol, that is, the client no longer requires sending commands, because the server will automatically send to
the client new messages (for the channels the client is subscribed to) as soon as they are received.
Excluding the above two exceptions, the Redis protocol is a simple request-response protocol.
RESP protocol description
The RESP protocol was introduced in Redis 1.2, but it became the standard way for talking with the Redis server
in Redis 2.0. This is the protocol you should implement in your Redis client.
RESP is actually a serialization protocol that supports the following data types: Simple Strings, Errors, Integers,
Bulk Strings and Arrays.
The way RESP is used in Redis as a request-response protocol is the following:
Clients send commands to a Redis server as a RESP Array of Bulk Strings.
The server replies with one of the RESP types according to the command implementation.
In RESP, the type of some data depends on the first byte:
For Simple Strings the first byte of the reply is "+"
For Errors the first byte of the reply is "-"
For Integers the first byte of the reply is ":"
For Bulk Strings the first byte of the reply is "$"
For Arrays the first byte of the reply is "*"
Additionally RESP is able to represent a Null value using a special variation of Bulk Strings or Array as
specified later.
In RESP different parts of the protocol are always terminated with "\r\n" (CRLF).
As you can see after the *<count>CRLF part prefixing the array, the other data types composing the
array are just concatenated one after the other. For example an Array of three integers is encoded as
follows:
"*3\r\n:1\r\n:2\r\n:3\r\n"
The protocol uses prefixed lengths to indicate the size of a response. For example, a response beginning
with *275 indicates a response containing an array having 275 elements.
Similarly, a response beginning with $10 indicates a string with a length of ten.