A Redis clone built from scratch in Rust. This project implements core Redis functionality including data structures, persistence, replication, pub/sub messaging, and more.
SET key value [PX milliseconds]- Set a key with optional expirationGET key- Get the value of a keyINCR key- Increment the integer value of a key
LPUSH key value [value ...]- Prepend values to a listRPUSH key value [value ...]- Append values to a listLPOP key [count]- Remove and return elements from the headLRANGE key start stop- Get a range of elementsLLEN key- Get the length of a list
ZADD key score member- Add a member with score to a sorted setZRANGE key start stop- Get members by index rangeZRANK key member- Get the rank of a memberZSCORE key member- Get the score of a memberZCARD key- Get the number of membersZREM key member- Remove a member
XADD key id field value [field value ...]- Append an entry to a streamXRANGE key start end- Get a range of entriesXREAD STREAMS key id- Read entries from streams
SUBSCRIBE channel [channel ...]- Subscribe to channelsUNSUBSCRIBE channel [channel ...]- Unsubscribe from channelsPUBLISH channel message- Publish a message to a channel
GEOADD key longitude latitude member- Add geospatial itemsGEOPOS key member [member ...]- Get positions of membersGEODIST key member1 member2 [unit]- Get distance between membersGEOSEARCH key FROMMEMBER member BYRADIUS radius unit- Search for members within radius
MULTI- Start a transactionEXEC- Execute queued commandsDISCARD- Discard queued commands
- RDB Loading - Automatically loads data from RDB files on startup
CONFIG GET dir- Get the database directoryCONFIG GET dbfilename- Get the RDB filenameKEYS *- Get all keys in the database
- Master/Slave replication support
INFO replication- Get replication informationREPLCONF- Replication configurationPSYNC- Partial synchronization
AUTH password- Authenticate to the serverACL- Access control list management
PING- Test connectionECHO message- Echo a messageTYPE key- Get the type of a key
- Rust (latest stable version)
- Cargo
cargo build --releaseBasic server:
cargo runWith custom port:
cargo run -- --port 6380With RDB persistence:
cargo run -- --dir /path/to/data --dbfilename dump.rdbAs a replica:
cargo run -- --port 6380 --replicaof "127.0.0.1 6379"Use redis-cli or any Redis client:
redis-cli -p 6379src/
├── main.rs # Server entry point and connection handling
├── resp/ # RESP protocol implementation
│ ├── parser.rs # RESP message parser
│ ├── serializer.rs # RESP message serializer
│ └── types.rs # RESP data types
├── db/ # Database core
│ └── core.rs # In-memory data store with expiration
├── commands/ # Command implementations
│ ├── dispatcher.rs # Command routing
│ ├── string_cmds.rs # String commands
│ ├── list_cmds.rs # List commands
│ ├── sets_cmd.rs # Sorted set commands
│ ├── streams_cmds.rs # Stream commands
│ ├── pubsub_cmds.rs # Pub/Sub commands
│ ├── geospatial_cmds.rs # Geospatial commands
│ ├── persistence_cmds.rs # Persistence commands
│ ├── repl_cmds.rs # Replication commands
│ └── auth_cmds.rs # Authentication commands
├── rdb/ # RDB persistence
│ └── parser.rs # RDB file parser
├── replication/ # Replication support
│ └── handshake.rs # Master-slave handshake
└── client.rs # Client state management
- Async I/O - Built with Tokio for high-performance async networking
- RESP Protocol - Full implementation of Redis Serialization Protocol
- Memory Efficient - Uses
bytes::Bytesfor zero-copy operations - Concurrent Access - Thread-safe data structures with
Arc<Mutex<>> - Background Tasks - Automatic key expiration via background task
- RDB Compatibility - Reads standard Redis RDB files (version 11)
| Option | Description | Default |
|---|---|---|
--port <port> |
Server port | 6379 |
--dir <path> |
Directory for RDB files | None |
--dbfilename <name> |
RDB filename | None |
--replicaof "<host> <port>" |
Run as replica of master | None |
- Inspired by Redis