# minidis **Repository Path**: volving/minidis ## Basic Information - **Project Name**: minidis - **Description**: 这是一个简易版的单机Redis, 用于学习和测试 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-19 - **Last Updated**: 2025-06-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Minidis A single-node Redis server implementation in Rust. ## Features ### Data Types - [x] Strings - [x] Lists - [x] Sets - [x] Hashes - [ ] Sorted Sets (planned) ### Commands #### String Commands - `GET key` - `SET key value [EX seconds]` - `APPEND key value` - `INCR key` / `DECR key` #### List Commands - `LPUSH key element [element ...]` - `RPUSH key element [element ...]` - `LPOP key` / `RPOP key` - `LLEN key` - `LRANGE key start stop` #### Hash Commands - `HSET key field value` - `HGET key field` - `HDEL key field [field ...]` - `HGETALL key` - `HEXISTS key field` #### Set Commands - `SADD key member [member ...]` - `SREM key member [member ...]` - `SISMEMBER key member` - `SMEMBERS key` - `SCARD key` #### Generic Commands - `DEL key [key ...]` - `EXISTS key [key ...]` - `KEYS pattern` - `TYPE key` - `TTL key` - `EXPIRE key seconds` - `PERSIST key` - `FLUSHDB` #### Server Commands - `PING [message]` - `ECHO message` - `TIME` - `INFO [section]` ## Quick Start ### Prerequisites - Rust 1.70 or later - Docker (optional, for containerized deployment) ### Building #### Native Build ```bash cargo build --release ``` #### Docker Build ```bash # Build both Alpine and scratch versions ./build-docker.sh # Or build specific versions: docker build -t minidis:alpine -f Dockerfile.alpine . docker build -t minidis:scratch -f Dockerfile . ``` ### Running the Server #### Native ```bash cargo run ``` #### Docker ```bash # Using docker-compose (recommended) docker-compose up # Or run directly docker run -d -p 6379:6379 --name minidis minidis:latest ``` The server will start on `127.0.0.1:6379` by default. ### Command Line Options ```bash minidis [OPTIONS] OPTIONS: -h, --help Print help information -c, --config Server configuration file [default: minidis.conf] -p, --port Server port [default: 6379] -a, --addr Server address [default: 127.0.0.1] ``` ### Testing #### Using Redis CLI You can test the server using the standard Redis CLI: ```bash redis-cli -p 6379 ``` #### Using the Test Scripts Run the comprehensive test suite: ```bash # For Docker environment ./test_minidis.sh # For local environment (using nc) ./test_local.sh ``` #### Manual Testing with nc For quick testing without Redis CLI: ```bash # PING command echo -e '*1\r\n$4\r\nPING\r\n' | nc 127.0.0.1 6379 # SET/GET commands echo -e '*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n' | nc 127.0.0.1 6379 echo -e '*2\r\n$3\r\nGET\r\n$3\r\nkey\r\n' | nc 127.0.0.1 6379 ``` ## Architecture ### Project Structure ``` src/ ├── main.rs # Program entry point ├── server/ # Server implementation │ ├── mod.rs # Server struct and TCP handling │ ├── connection.rs # Client connection management │ └── handler.rs # Additional handlers ├── protocol/ # RESP protocol implementation │ ├── mod.rs # Protocol types and errors │ ├── resp.rs # RESP data types │ ├── parser.rs # RESP parser │ └── encoder.rs # RESP encoder ├── storage/ # Storage engine │ ├── mod.rs # Storage implementation │ ├── types.rs # Redis data types │ ├── engine.rs # Storage trait │ └── ttl.rs # TTL management ├── commands/ # Command handlers │ ├── mod.rs # Command executor │ ├── string.rs # String commands │ ├── list.rs # List commands │ ├── hash.rs # Hash commands │ ├── set.rs # Set commands │ └── generic.rs # Generic commands └── config/ # Configuration └── mod.rs # Config management ``` ### Key Components 1. **RESP Protocol**: Full implementation of Redis Serialization Protocol 2. **Storage Engine**: Thread-safe in-memory storage with TTL support 3. **Command System**: Modular command handlers for different data types 4. **Async Server**: Tokio-based async TCP server supporting concurrent connections ## Development Status This is a learning project implementing core Redis functionality. It's not production-ready and should not be used in production environments. ### Completed - ✅ Basic server architecture - ✅ RESP protocol parsing and encoding - ✅ Core data types (String, List, Hash, Set) - ✅ TTL support - ✅ Multi-client support ### Planned - [ ] Persistence (RDB snapshots) - [ ] AOF (Append Only File) - [ ] Sorted Sets - [ ] Pub/Sub - [ ] Lua scripting - [ ] Clustering ## Contributing This is primarily a learning project, but contributions are welcome! Please feel free to: - Report bugs - Suggest improvements - Submit pull requests ## License MIT License