# Replication (#YG4) Unclear that multiple commands can be received at once

**URL:** <https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [April 5, 2024, 10:42am UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46 "2024-04-05T10:42:27Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![codesbyayush](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/codesbyayush/32/36_2.png) [@codesbyayush](https://forum.codecrafters.io/u/codesbyayush)\
**Post date:** [April 5, 2024, 10:42am UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/1 "2024-04-05T10:42:27Z")

</div>

I’m stuck on Replication 13.

In level 12, I forward set request from Master to the slaves but only one request reaches slave and sometimes not even one request reaches slave. The get request afterward throw error as their is no value available because of the set request not yet processed.

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 5, 2024, 11:13am UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/2 "2024-04-05T11:13:01Z")

</div>

Hi there!

Mind sharing logs, and some sample code? (You can use the “Publish to GitHub” button in the top-left dropdown to easily publish to github).

We do retry the GET request multiple times to account for propagation delays, and you should see this in the logs.

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 5, 2024, 11:14am UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/3 "2024-04-05T11:14:31Z")

</div>

And just in case you haven’t already, I’d recommend turning on debug mode (instructions [here](https://docs.codecrafters.io/challenges/debug-test-failures)). That should surface more useful logs.

---

<div class="post-metadata">

**Author:** ![codesbyayush](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/codesbyayush/32/36_2.png) [@codesbyayush](https://forum.codecrafters.io/u/codesbyayush)\
**Post date:** [April 5, 2024, 12:54pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/4 "2024-04-05T12:54:51Z")

</div>

I have published the code to github. Please help me here I don’t understand what is going wrong. Below are some of the logs i get

```auto
remote: [replication-13] Sent RDB file.
remote: [replication-13] master: $ redis-cli SET foo 123
remote: [replication-13] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
remote: [replication-13] master: $ redis-cli SET bar 456
remote: [replication-13] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n"
remote: [replication-13] master: $ redis-cli SET baz 789
remote: [replication-13] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbaz\r\n$3\r\n789\r\n"
remote: [replication-13] Getting key foo
remote: [replication-13] client: $ redis-cli GET foo
remote: [replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
remote: [replication-13] client: Received bytes: "$-1\r\n"
remote: [replication-13] client: Received RESP value: NIL
remote: [replication-13] Retrying... (1/5 attempts)
remote: [replication-13] client: $ redis-cli GET foo
remote: [replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
remote: [replication-13] client: Received bytes: "+123\r\n"
remote: [replication-13] client: Received RESP value: "123"
remote: [replication-13] Received "123"
remote: [replication-13] Getting key bar
remote: [replication-13] client: $ redis-cli GET bar
remote: [replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbar\r\n"
remote: [replication-13] client: Received bytes: "$-1\r\n"
remote: [replication-13] client: Received RESP value: NIL
remote: [replication-13] Retrying... (1/5 attempts)
remote: [replication-13] client: $ redis-cli GET bar
remote: [replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbar\r\n"
remote: [replication-13] client: Received bytes: "$-1\r\n"
remote: [replication-13] client: Received RESP value: NIL
remote: [replication-13] Retrying... (2/5 attempts)

```

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 5, 2024, 1:05pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/5 "2024-04-05T13:05:02Z")

</div>

Can you share the GitHub link too please?

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 5, 2024, 1:05pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/6 "2024-04-05T13:05:50Z")

</div>

Looking at the logs, it looks like your program is responding with NIL instead of the expected value (123)?

---

<div class="post-metadata">

**Author:** ![codesbyayush](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/codesbyayush/32/36_2.png) [@codesbyayush](https://forum.codecrafters.io/u/codesbyayush)\
**Post date:** [April 5, 2024, 1:42pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/7 "2024-04-05T13:42:17Z")

</div>

> **[GitHub - codesbyayush/codecrafters-redis-typescript](https://github.com/codesbyayush/codecrafters-redis-typescript)**
>
> Contribute to codesbyayush/codecrafters-redis-typescript development by creating an account on GitHub.

Link of the github repo

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 5, 2024, 11:18pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/10 "2024-04-05T23:18:18Z")

</div>

@codesbyayush the issue seems so be with how the requests propagated by the master are handled.

There are 3 separate SET commands which are propagated (i.e. all the bytes will be received at once).

In main.ts:46, the code that parses these requests assumes that there’s just one command:

```auto
  masterConn.on("data", (data) => {
    const req = data.toString().toLowerCase();
    const parsedReq = RESP2parser(req.split("\r\n"));
    ...
  };

```

(i.e. the first command is parsed, and the other 2 commands are ignored).

The fix here would be to change the way these messages are parsed so that your code handles multiple messages in the `data` string.

Hope this helps! We’ll see if we can update our instructions to make this behaviour more clear.

---

<div class="post-metadata">

**Author:** ![Rshep3087](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rshep3087/32/44_2.png) [@Rshep3087](https://forum.codecrafters.io/u/Rshep3087)\
**Post date:** [April 6, 2024, 9:10pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/11 "2024-04-06T21:10:53Z")

</div>

An update would be helpful here, I have same issue. Saw the commands and could tell it was sending multiple. But looked through instructions, including previous ones and didn’t see anything that made it clear that was possible. But it’s obvious now.

---

<div class="post-metadata">

**Author:** ![abhiy13](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/abhiy13/32/49_2.png) [@abhiy13](https://forum.codecrafters.io/u/abhiy13)\
**Post date:** [April 7, 2024, 6:41pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/12 "2024-04-07T18:41:47Z")

</div>

Facing a similar issue, my instance is not receiving some bytes from the server

 ![Screenshot 2024-04-08 at 12.11.21 AM](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/1X/099c0b6d09c9c2bee2784fe5b6fa733204c155f6.jpeg)

The RDB file bytes are never received

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 8, 2024, 8:50pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/13 "2024-04-08T20:50:35Z")

</div>

Updated the instructions now!

> <https://github.com/codecrafters-io/build-your-own-redis/commit/f8571a34b17b2a8cb44d5fc2a7053f190e48b198>

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 8, 2024, 8:52pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/14 "2024-04-08T20:52:01Z")

</div>

@abhiy13 this looks like a different issue, would suggest starting another topic with details so that we can take a proper look!

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 30, 2024, 10:59pm UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/15 "2024-04-30T22:59:40Z")

</div>

Closed on April 30, 2024, 10:59pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [June 4, 2024, 5:53am UTC](https://forum.codecrafters.io/t/replication-yg4-unclear-that-multiple-commands-can-be-received-at-once/46/16 "2024-06-04T05:53:23Z")

</div>

Note: I’ve updated the title of this post to include the stage ID (#YG4). You can learn about the stages rename here: [Upcoming change: Stages overhaul](https://forum.codecrafters.io/t/upcoming-change-stages-overhaul/375)
