You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this stage, you'll add support for receiving the [`PSYNC`](https://redis.io/commands/psync/) command from the replica.
2
2
3
-
### Handshake (continued from previous stage)
3
+
### Handshake (Recap)
4
4
5
-
As a recap, there are three parts to the handshake:
5
+
As a recap, the master receives the following for the handshake:
6
6
7
-
- The master receives a `PING` from the replica (You've already implemented this)
8
-
- The master receives `REPLCONF` twice from the replica (You've already implemented this)
9
-
- The master receives `PSYNC` from the replica (**This stage**)
7
+
1. A `PING` from the replica
8
+
2.`REPLCONF` twice from the replica
9
+
3.`PSYNC` from the replica
10
10
11
-
After the replica sends `REPLCONF` twice, it'll send a `PSYNC? -1`command to the master.
11
+
After the replica sends `REPLCONF` twice, it will send a `PSYNC` command with the arguments `? -1` to the master:
12
12
13
-
- The first argument is `?`
14
-
- This is the replication ID of the master, it is `?` because this is the first time the replica is connecting to the master.
15
-
- The second argument is `-1`
16
-
- This is the replication offset, it is `-1` because this is the first time the replica is connecting to the master.
13
+
- The replication ID is `?` because the replica doesn't know the master's ID yet.
14
+
- The offset is `-1` since the replica has no data from the master yet.
17
15
18
-
The final command you receive will look something like this:
16
+
The final command you'll receive will look something like this:
19
17
20
18
```
21
19
*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n
22
20
```
23
21
24
-
(That's `["PSYNC", "?", "-1"]` encoded as a RESP Array)
22
+
That's `["PSYNC", "?", "-1"]` encoded as a RESP array.
25
23
26
-
The master needs to respond with `+FULLRESYNC <REPL_ID> 0\r\n` ("FULLRESYNC <REPL_ID> 0" encoded as a RESP Simple String). Here's what
27
-
the response means:
24
+
The master needs to respond with `+FULLRESYNC <REPL_ID> 0\r\n`, which is `FULLRESYNC <REPL_ID> 0` encoded as a simple string. Here's what the response means:
28
25
29
-
-`FULLRESYNC` means that the master cannot perform incremental replication with the replica, and will thus start a "full" resynchronization.
30
-
-`<REPL_ID>` is the replication ID of the master. You've already set this in the "Replication ID & Offset" stage.
31
-
- As an example, you can hardcode `8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb` as the replication ID.
32
-
-`0` is the replication offset of the master. You've already set this in the "Replication ID & Offset" stage.
26
+
-`FULLRESYNC` means that the master cannot perform an incremental update to the replica, and will start a full resynchronization.
27
+
-`<REPL_ID>` is the replication ID of the master (the 40-character string you initialized in a previous stage).
28
+
-`0` is the replication offset of the master (which you initialized in a previous stage).
29
+
30
+
For example, if your replication ID is `8371b4fb1155b71f4a04d3e1bc3e18c4a990aeeb`, you'd respond with:
0 commit comments