Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-redis-with-rust

A lightweight Redis-compatible implementation powered by Tokio. It supports PING, GET, and SET (with EX/PX expiration) and ships with async, blocking, and buffered clients as well as CLI and server binaries. The project is intended for learning how to build RESP-based systems in async Rust; do not use it in production.

Features

  • RESP encoding/decoding via the frame and parse modules plus a Connection abstraction that keeps network IO pipeline-friendly.
  • In-memory database Db with optional TTL, a background cleanup task, and graceful shutdown hooks.
  • Command layer covering PING, GET, SET, with an Unknown fallback for unsupported commands.
  • Server binary simple-redis-server that enforces a connection cap, handles concurrent clients, and supports graceful shutdown.
  • Client options:
    • clients::Client: async API offering get / set / set_expires / ping.
    • clients::BlockingClient: synchronous wrapper around the async client.
    • clients::BufferedClient: request serialization via an internal channel for multi-task scenarios.
    • simple-redis-cli: Clap-powered CLI for issuing commands easily.

Prerequisites

  • Rust 1.72+ (Tokio 1.x line)
  • cargo build tool

Usage

Start the server

cargo run --bin simple-redis-server -- --host 127.0.0.1 --port 6379

Send commands from the CLI

# Ping
cargo run --bin simple-redis-cli -- ping

# Set + Get
cargo run --bin simple-redis-cli -- set my-key my-value --expires 5000
cargo run --bin simple-redis-cli -- get my-key

Use the client library

use bytes::Bytes;
use simple_redis_with_rust::connect;

#[tokio::main]
async fn main() -> simple_redis_with_rust::Result<()> {
    let mut client = connect("127.0.0.1:6379").await?;
    client.set("hello", Bytes::from("world")).await?;
    println!("{:?}", client.get("hello").await?);
    Ok(())
}

Testing

Run cargo test (unit + integration) to validate the core modules. When adding features or commands, extend the suites for frame, parse, db, and cmd to cover new behavior.

About

a simple redis implemented with rust language.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages