# Stuck at Read Multiple Keys

**URL:** https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989
**Category:** Challenges
**Tags:** challenge:redis
**Created:** [November 18, 2024, 7:09am UTC](https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989 "2024-11-18T07:09:31Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![rafterjob1](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rafterjob1/32/2652_2.png) [@rafterjob1](https://forum.codecrafters.io/u/rafterjob1)
#### Post date: [November 18, 2024, 7:09am UTC](https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989/1 "2024-11-18T07:09:31Z")

</div>

heres the git hub repo

> **[GitHub - aneel-56/MinRedis](https://github.com/aneel-56/MinRedis)**
>
> Contribute to aneel-56/MinRedis development by creating an account on GitHub.

the error message is

```auto
 Keys
[your_program] ['apple']
[your_program] KEYS * Response: *1
[your_program] $5
[your_program] apple
[your_program] 
[tester::#JW4] Received: "*1\r\n$2\r\napple,apple\r\n*1\r\n$5\r\na"
[tester::#JW4] ^ error
[tester::#JW4] Error: Expected \r\n after 2 bytes of data in bulk string
[tester::#JW4] Test failed

```

the code block

```auto
      if (commands[2] === "KEYS" && commands[4] === "*") {
        console.log(" ********Handling KEYS * Command********");

        // Get all keys, excluding config entries
        const keys = Array.from(dataStore.keys()).filter(
          (key) => key !== "dir" && key !== "dbfilename"
        );

        console.log("Keys");
        console.log(keys);
        let response = `*${keys.length}\r\n`; // RESP array of keys
        keys.forEach((key) => {
          // Properly format each key as a bulk string
          console.log("Key are");
          console.log(key);
          response += `$${key.length}\r\n${key}\r\n`; // Each key is a bulk string
          console.log("Key: " + key);
        });
        

        console.log("KEYS * Response:", response);
        connection.write(response); // Send the response to the connection
      }
    }

```

---

<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: [November 18, 2024, 7:14am UTC](https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989/2 "2024-11-18T07:14:10Z")

</div>

@rafterjob1 what part of the error message do you find confusing?

---

<div class="post-metadata">

### Author: ![rafterjob1](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rafterjob1/32/2652_2.png) [@rafterjob1](https://forum.codecrafters.io/u/rafterjob1)
#### Post date: [November 18, 2024, 7:21am UTC](https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989/3 "2024-11-18T07:21:53Z")

</div>

I am just iterating the array , how did i get the comma in between  
can you help me solve it , i have stuck in this stage for very longtime

---

<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: [November 18, 2024, 7:25am UTC](https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989/4 "2024-11-18T07:25:32Z")

</div>

Looks like you’ve got two `connection.write` calls - are both required?

 ![Screenshot 2024-11-18 at 12.55.14](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/1/1f1b66d0843e5685f544e9d159095a1aae1bd3fe.png)

Line 96 and line 121.

---

<div class="post-metadata">

### Author: ![shreyasganesh0](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/shreyasganesh0/32/2559_2.png) [@shreyasganesh0](https://forum.codecrafters.io/u/shreyasganesh0)
#### Post date: [November 18, 2024, 6:12pm UTC](https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989/5 "2024-11-18T18:12:12Z")

</div>

looks like you have two $ signs in this line  
`response += `$${key.length}\r\n${key}\r\n`;` you might need to escape the character

---

<div class="post-metadata">

### Author: ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)
#### Post date: [November 24, 2024, 4:32pm UTC](https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989/6 "2024-11-24T16:32:31Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<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: [November 29, 2024, 4:32pm UTC](https://forum.codecrafters.io/t/stuck-at-read-multiple-keys/2989/7 "2024-11-29T16:32:40Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
