How sleeprite/rudis works
Project type and purpose
• Rudis is an open-source, Redis-compatible, high-performance in-memory key-value database written in Rust.
• It implements the Redis wire protocol, provides common data structures (strings, lists, hashes, sets, sorted sets), supports RDB/AOF persistence, and can be deployed as a standalone binary or in Docker.
File structure
• Top-level: Cargo manifest, Docker assets, release binaries, docs/ (VitePress-powered static site), examples/, tests/.
• src/ contains the main crate with these sub-modules:
• server.rs / server_handler.rs – network listener, TCP framing, request/response loop
• frame.rs – Redis protocol parser/generator
• session.rs – per-connection state (selected DB index, authentication)
• cmd/ – one file per command or per command group, implements the “Command” trait
• db.rs – in-memory storage engine and data-structure implementations
• persistence/ – RDB snapshotter and AOF appender modules
• args.rs, command.rs – command-line flags, dispatch registry
• tests/ exercise commands and performance.
README for additional insights
• Describes core components: command parsing, database operations, persistence, session management.
• Mentions configuration options (port, bind, AOF/RDB settings).
1. Clients (any Redis client library or CLI)
2. Rudis Server
– Config Loader (args.rs + properties file)
– TCP Listener & Reactor (server.rs)
– Protocol Layer (frame.rs)
– Session Manager (session.rs)
– Command Dispatcher (command.rs)
– Command Modules (src/cmd/*.rs)
– Storage Engine (db.rs)
– Persistence Manager (persistence/rdb & persistence/aof)
– Logging & Metrics
3. File System (RDB/AOF files on disk)
4. Optional: Docker / Release Packaging (docker/Dockerfile, release/)
5. Documentation Site (docs/ – outside runtime, but part of the project)
b. Relationships and data flow
• TCP Listener → Protocol Layer (parse incoming byte frames)
• Protocol Layer → Session Manager (attaches DB index & auth state)
• Session Manager → Command Dispatcher (routes command name to handler)
• Dispatcher → Command Module (e.g., cmd/get.rs, cmd/set.rs)
• Command Module ↔ Storage Engine (query/update in-memory data)
• Write commands → Persistence Manager → File System (append AOF / trigger RDB)
• Command Module → Protocol Layer (serialize response)
• Protocol Layer → TCP Listener → Clients
c. Architectural patterns & design principles
– Modular “command” plugin pattern: each Redis command is its own Rust module, registered in a dispatch table.
– Single-responsibility: separate protocol framing, session tracking, storage, persistence.
– Layered design: network → protocol → logic → storage → disk.
– Extensibility point: add new cmd/*.rs modules and register in command.rs.
d. Key technologies & frameworks
– Rust & Cargo (crate management)
– Tokio or std::net (async or blocking TCP I/O in server.rs)
– Custom Redis protocol implementation (frame.rs)
– Static site generator (VitePress in docs/) for documentation
Detail is critical but avoid over-complicating
• How a new command would flow through the same pipeline.