|
1 | | -In this stage, you'll implement support for the [PING](https://redis.io/commands/ping) command. |
| 1 | +In this stage, you'll implement the Redis `PING` command. |
2 | 2 |
|
3 | | -### TCP (Transmission Control Protocol) |
| 3 | +### What is `PING`? |
4 | 4 |
|
5 | | -[TCP](https://en.wikipedia.org/wiki/Transmission_Control_Protocol) is the underlying protocol used by protocols like HTTP, SSH, and others you're probably familiar with. Redis also uses TCP for communication between its clients and servers. |
6 | | - |
7 | | -Don't worry if you're unfamiliar with the TCP protocol, or what Redis clients & servers are. You'll learn more about this in the next stages. |
8 | | - |
9 | | -### Redis Commands |
10 | | - |
11 | | -Redis clients communicate with Redis servers by sending [commands](https://redis.io/commands/). For each command, a Redis server sends a response back to the client. |
| 5 | +Redis clients talk to Redis servers by sending **commands** and receiving **responses**. |
12 | 6 |
|
13 | 7 | For example: |
14 | 8 |
|
15 | 9 | ```bash |
16 | | -$ redis-cli SET name Alice |
17 | | -OK |
18 | | -``` |
19 | | - |
20 | | -Here, the client sends a [`SET`](https://redis.io/docs/latest/commands/set/) command to store the key `name` with the value `Alice`. The server responds with `OK`, confirming that the action was successful. |
| 10 | +redis> PING # client sends a PING command |
| 11 | +"PONG" # server replies with PONG |
21 | 12 |
|
22 | | -Both commands and responses are encoded using the [Redis serialization protocol (RESP)](https://redis.io/docs/latest/develop/reference/protocol-spec/). We'll learn more about this in later stages. |
23 | | - |
24 | | -### The `PING` Command |
25 | | - |
26 | | -[PING](https://redis.io/commands/ping/) is one of the simplest Redis commands. It's used to check whether a Redis server is healthy. |
27 | | - |
28 | | -```bash |
29 | | -$ redis-cli PING |
30 | | -PONG |
| 13 | +redis> SET name Alice # store the value "Alice" under the key "name" |
| 14 | +OK # server confirms success |
31 | 15 | ``` |
32 | 16 |
|
33 | | -The response for the `PING` command is `+PONG\r\n`. This is the string "PONG" encoded as a [RESP simple string](https://redis.io/docs/latest/develop/reference/protocol-spec/#simple-strings). |
| 17 | +`PING` is the simplest Redis command. It’s used to check whether a Redis server is alive and responding. |
34 | 18 |
|
35 | | -In this stage, you can ignore the client input and simply hardcode `+PONG\r\n` as a response. We'll get to parsing the client's input in later stages. |
| 19 | +When a Redis server replies to `PING`, the raw response it sends over the network is actually `+PONG\r\n`, which is the string `PONG` encoded using RESP, a format Redis uses to exchange messages between clients and servers. |
36 | 20 |
|
37 | | -### Tests |
38 | | - |
39 | | -The tester will execute your program like this: |
40 | | - |
41 | | -```bash |
42 | | -$ ./your_program.sh |
43 | | -``` |
44 | | - |
45 | | -It'll then send a `PING` command to your server. |
46 | | - |
47 | | -```bash |
48 | | -$ redis-cli PING |
49 | | -``` |
| 21 | +For this stage, your task is to simply hardcode a `+PONG\r\n` response, regardless of the incoming command. |
50 | 22 |
|
51 | | -Your server should respond with `+PONG\r\n`, which is `PONG` encoded as a [simple string](https://redis.io/docs/latest/develop/reference/protocol-spec/#simple-strings). |
| 23 | +You’ll learn more about RESP and how input command parsing works in future stages. |
52 | 24 |
|
53 | 25 | ### Notes |
54 | 26 |
|
55 | | -- You can ignore the data that the tester sends you for this stage. We'll get to parsing |
56 | | - client input in later stages. For now, you can just hardcode `+PONG\r\n` as the response. |
57 | | -- You can also ignore handling multiple clients and handling multiple PING commands in this stage—we'll get to that in later stages. |
58 | | -- The exact bytes your program will receive won't just be `PING`. Instead, you'll receive something like this: `*1\r\n$4\r\nPING\r\n`, |
59 | | - which is the Redis protocol encoding of the `PING` command. We'll learn more about this in later stages. |
| 27 | +- You can ignore handling multiple clients and handling multiple PING commands in this stage. We'll get to that later. |
| 28 | +- The exact bytes your program will receive won't just be `PING`. Instead, you'll receive: `*1\r\n$4\r\nPING\r\n`, |
| 29 | + which is the RESP encoding of `PING`. |
0 commit comments