Skip to content

littleKitchen/MiniRedis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MiniRedis πŸ”΄

A lightweight Redis clone built in Rust. Supports basic Redis commands with TTL (time-to-live) functionality.

Features

  • ⚑ Async I/O with Tokio
  • πŸ”’ Thread-safe with DashMap
  • ⏰ TTL/Expiration support
  • πŸ“¦ Zero dependencies on actual Redis
  • πŸš€ Simple text protocol (works with netcat)

Installation

# Clone the repo
git clone https://github.com/littleKitchen/MiniRedis.git
cd MiniRedis

# Build
cargo build --release

# Run
./target/release/MiniRedis

Usage

Start the server:

./target/release/MiniRedis

Connect with netcat or telnet:

nc localhost 6380

Or use redis-cli:

redis-cli -p 6380

Supported Commands

Command Description Example
PING Test connection PING β†’ PONG
ECHO msg Echo message ECHO hello β†’ hello
SET key value Set a key SET name Yuxuan
SET key value EX secs Set with TTL SET token abc123 EX 60
GET key Get value GET name β†’ Yuxuan
DEL key [key ...] Delete key(s) DEL name
EXISTS key [key ...] Check if exists EXISTS name β†’ 1
INCR key Increment INCR counter β†’ 1
DECR key Decrement DECR counter β†’ 0
EXPIRE key secs Set TTL EXPIRE token 30
TTL key Get remaining TTL TTL token β†’ 25
KEYS pattern List keys KEYS *
DBSIZE Count keys DBSIZE β†’ 5
FLUSHDB Clear all keys FLUSHDB
INFO Server info INFO
QUIT Close connection QUIT

Example Session

$ nc localhost 6380
PING
+PONG
SET greeting Hello World
+OK
GET greeting
+Hello World
SET counter 0
+OK
INCR counter
:1
INCR counter
:2
GET counter
+2
SET temp data EX 10
+OK
TTL temp
:9
KEYS *
*3
+greeting
+counter
+temp
DBSIZE
:3
DEL temp
:1
QUIT
+OK

Architecture

  • Tokio - Async runtime for handling concurrent connections
  • DashMap - Lock-free concurrent HashMap for thread-safe storage
  • Bytes - Efficient byte buffer handling

Port

Default port: 6380 (to avoid conflict with real Redis on 6379)

License

MIT

Author

Yuxuan Che

About

πŸ”΄ A lightweight Redis clone built in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages