Project 4: Build a redis-cli Clone

An asynchronous command-line client for a Redis server. Your tool will connect to Redis, send commands like PING, SET, and GET, and parse the RESP (REdis Serialization Protocol) responses.

Quick Reference

Attribute Value
Primary Language Rust
Alternative Languages Go, Python
Difficulty Level 2: Intermediate
Time Estimate 1-2 weeks
Knowledge Area Async I/O / Network Protocols
Tooling tokio crate, Redis
Prerequisites Project 1, basic understanding of what async is for.

What You Will Build

An asynchronous command-line client for a Redis server. Your tool will connect to Redis, send commands like PING, SET, and GET, and parse the RESP (REdis Serialization Protocol) responses.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Setting up an async runtime → maps to understanding tokio and the #[tokio::main] macro
  • Making an async TCP connection → maps to using tokio::net::TcpStream
  • Sending and receiving data asynchronously → maps to using .await on I/O operations
  • Parsing a streaming protocol (RESP) → maps to managing a read buffer and parsing framed messages safely

Key Concepts

  • Async/Await in Rust: “The Rust Programming Language” Ch. 16 (briefly), but the Tokio tutorial is better.
  • Futures: The core concept behind async. A Future is a value that will be computed later.
  • Tokio Runtime: The engine that polls your Futures and drives them to completion.
  • Protocol Parsing: Writing a state machine to parse incoming byte streams.

Real-World Outcome

$ cargo run -- PING
"PONG"

$ cargo run -- SET foo "hello world"
"OK"

$ cargo run -- GET foo
"hello world"

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_RUST_FROM_FIRST_PRINCIPLES.md
  • “Rust in Action” by Tim McNamara