> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codecrafters.io/llms.txt
> Use this file to discover all available pages before exploring further.

# How do I debug test failures in the Redis Challenge?

<Note>
  This is specifically for the Redis Challenge. For debugging test failures for common challenges, refer to our [guide](/challenges/debug-test-failures).
</Note>

## Required Tools

The easiest way to debug problems with your redis implementation is to compare it to the official implementation. To do this, we'll need a few tools handy.

### redis-cli, redis-server

Make sure you have [redis-cli](https://redis.io/topics/rediscli) and [redis-server](https://redis.io/topics/quickstart#starting-redis) installed. We'll use redis-cli to test commands against your redis implementation, and redis-server as a reference to compare with.

### Wireshark

Since redis-cli & redis-server communicate with each over using TCP, we'll need a tool to inspect TCP messages. Install [Wireshark](https://www.wireshark.org/#download). If you prefer CLI tools you can also use **tcpdump**.

## Methodology

### 1. Setup Wireshark to capture and display TCP traffic

Run Wireshark and use `tcp.port == 6379` or `tcp.port == 6380` as a display filter. We'll use this in step 4 to view captured packets.

<Frame>
  <img className="w-full" src="https://mintcdn.com/codecrafters/rBHxsHriiZT92xcM/img/wireshark.png?fit=max&auto=format&n=rBHxsHriiZT92xcM&q=85&s=1ebfceccc0f484e215f327d57d1ac64f" width="1610" height="1176" data-path="img/wireshark.png" />
</Frame>

Make sure that the bottom toolbar says `Loopback: lo0`, and not something like `Wi-Fi: en0`.

#### Using tcpdump to capture and display TCP traffic

```bash terminal theme={null}
sudo tcpdump -i lo0 -X port 6379 or port 6380
```

Only root or user with sudo privileges can run tcpdump. See `man tcpdump` for more information.

### 2. Start your redis server implementation (on port 6379)

You'll find instructions for this in your repository's README (like [here](https://github.com/codecrafters-io/redis-starter-go#usage)). Your server will run on `port 6379`, which is the port we've configured Wireshark to capture data on.

### 3. Start the official redis server implementation (on port 6380)

Run `redis-server --port 6380` to do this.

<Frame>
  <img className="w-full" src="https://mintcdn.com/codecrafters/rBHxsHriiZT92xcM/img/redis.png?fit=max&auto=format&n=rBHxsHriiZT92xcM&q=85&s=8a48b81c7f13e2fbb135fda9eede528e" width="2244" height="1510" data-path="img/redis.png" />
</Frame>

**Send a few commands to your server using redis-cli.**

Use redis-cli to send commands to your server.

```bash Terminal theme={null}
redis-cli -p 6379 ping
```

```bash Terminal theme={null}
redis-cli -p 6379 echo key
```

<Note>
  **Note**: You can also use the redis-cli [interactive mode / REPL](https://redis.io/topics/rediscli#interactive-mode), but keep in mind that it sends a [COMMAND](https://redis.io/commands/command) command when it boots, which we don't implement in the Redis challenge.
</Note>

If your redis implementation doesn't send a valid response, you might see an error like this:

<Frame>
  <img className="w-full" src="https://mintcdn.com/codecrafters/qGKwe-_AIUAS3RUS/img/redis-error.png?fit=max&auto=format&n=qGKwe-_AIUAS3RUS&q=85&s=4439aebe587fc7f59188c42742263e59" width="1364" height="774" data-path="img/redis-error.png" />
</Frame>

These error messages can be cryptic, and in some cases the Redis client might just hang waiting for bytes that never arrive.

### 4. View capture data in Wireshark

Once you've sent a few commands, head back to Wireshark and you'll now see some captured packets. You can inspect these to see exactly what data your implementation responded with.

<Frame>
  <img className="w-full" src="https://mintcdn.com/codecrafters/qGKwe-_AIUAS3RUS/img/capture-data-wireshark.png?fit=max&auto=format&n=qGKwe-_AIUAS3RUS&q=85&s=984d66ea89c4c770855865692fbe6201" width="1928" height="1406" data-path="img/capture-data-wireshark.png" />
</Frame>

Notice the "\*1 \$4 ping" at the bottom? That's the PING command, encoded using the [Redis protocol](https://redis.io/topics/protocol).

#### View capture data from tcpdump

tcpdump can output all the same information as Wireshark. For example, when sending the PING command, look for `$4..PING..` and `+PONG..` in the captured data.

### 5. Compare with official redis implementation

Now that you know exactly what data your Redis server is sending, you can compare it with the official redis implementation to verify that it is working properly.

Send commands using `redis-cli -p 6380 <command>`.

<Frame>
  <img className="w-full" src="https://mintcdn.com/codecrafters/qGKwe-_AIUAS3RUS/img/redis-command.png?fit=max&auto=format&n=qGKwe-_AIUAS3RUS&q=85&s=598ac94452a2f0f5a06369799aeb8875" width="1364" height="774" data-path="img/redis-command.png" />
</Frame>

Inspect the output in Wireshark (as mentioned in step 4) to see how the official Redis implementation differs from yours.

***

If everything seems correct and you're still seeing test failures, it's possible that the Codecrafters tester program is at fault. Please let us know at [hello@codecrafters.io](mailto:hello@codecrafters.io) if that's the case!
