A Redis-like in-memory data store implementation in Rust, built from scratch.
- RESP Protocol: Full implementation of Redis Serialization Protocol (RESP)
- TCP Server: Async TCP server using Tokio
- In-Memory Store: Thread-safe key-value storage with RwLock
- TTL Support: Keys can expire after a specified time (seconds/milliseconds)
- Concurrency: Handles 20+ simultaneous connections
- Error Handling: Redis-compatible error messages
PING [message]- Ping the serverECHO message- Echo the given string
GET key- Get the value of a keySET key value [EX seconds] [PX milliseconds]- Set the string value of a key with optional expiryDEL key [key ...]- Delete one or more keysEXISTS key [key ...]- Check if keys existEXPIRE key seconds- Set a key's time to live in seconds
INCR key- Increment the integer value of a key by oneDECR key- Decrement the integer value of a key by one
LPUSH key value [value ...]- Insert values at the head of the listRPUSH key value [value ...]- Insert values at the tail of the listLPOP key- Remove and return the first element of the listRPOP key- Remove and return the last element of the listLRANGE key start stop- Get a range of elements from the listLLEN key- Get the length of the listLINDEX key index- Get an element by index
KEYS pattern- Find all keys matching the given patternDBSIZE- Return the number of keys in the databaseFLUSHDB- Remove all keys from the current database
# Development mode
cargo run
# Production mode
cargo build --release
./target/release/rudis
# Custom address
RUDIS_ADDR=0.0.0.0:6379 cargo run./scripts/tests.shConnect using standard Redis CLI:
redis-cli -p 6379
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> GET mykey
"Hello"
127.0.0.1:6379> INCR counter
(integer) 1
127.0.0.1:6379> KEYS *
1) "mykey"
2) "counter"See EXAMPLES for more usage examples.
-
RESP Parser (
resp.rs)- Parses Redis Serialization Protocol
- Supports all RESP data types: Simple Strings, Errors, Integers, Bulk Strings, Arrays
- Serializes responses back to RESP format
-
Store (
store.rs)- Thread-safe in-memory HashMap with RwLock
- Supports key expiration with TTL
- Automatic cleanup of expired keys on access
-
Command Handler (
command.rs)- Parses commands from RESP arrays
- Executes commands against the store
- Returns properly formatted RESP responses
-
TCP Server (
server.rs)- Async TCP server using Tokio
- Handles multiple concurrent connections
- Spawns a new task for each client connection
- Concurrency: Uses
Arc<RwLock<HashMap>>for thread-safe shared state - Async I/O: Built on Tokio for efficient async operations
- Memory Safety: Leverages Rust's ownership system for safety guarantees
- Zero-Copy: Uses
Vec<u8>for binary data to avoid unnecessary allocations
- Lists (LPUSH, RPUSH, LPOP, RPOP, LRANGE, LLEN, LINDEX)
- Sets (SADD, SREM, SMEMBERS, SISMEMBER)
- Sorted Sets (ZADD, ZRANGE, ZREM)
- Hashes (HSET, HGET, HDEL, HGETALL)
- Persistence (RDB snapshots, AOF)
- Pub/Sub messaging
- Transactions (MULTI/EXEC)
- Replication (master-slave)
- Configuration file support
- Logging
- Metrics and monitoring
- Improved error handling
- Performance optimizations
- Add support commands
INFO,CONFIG
MIT
- Sambo Chea cs@cubetiqs.com