A lightweight Redis server implementation in Go that supports basic Redis commands and persistence via RDB files.
- Implementation of core Redis commands (PING, ECHO, SET, GET, CONFIG GET, KEYS, INFO)
- Key-value storage with expiration support
- RDB file format persistence
- Command parsing based on the Redis protocol
- Support for master-slave replication configuration
-
Parser
- Algorithm: Redis Protocol (RESP) parser
- Converts client messages into executable commands
- Handles command arguments and parsing
- Supports different command formats and arguments
-
Command System
- Command interface for uniform execution
- Individual command implementations (PingCommand, EchoCommand, etc.)
- Error handling and response formatting according to RESP
-
Storage
- In-memory key-value database implementation
- Support for key expiration (both milliseconds and seconds)
- Concurrent access handling with timers for expiry
-
Persistence
- Algorithm: RDB file format parsing
- Reading and parsing RDB dump files
- Support for different value types and expiry formats
- Binary data handling for compact storage
- Go 1.16+
git clone https://github.com/sjwhole/redis-go.git
cd redis-go
./spawn_redis_server.sh
./spawn_redis_server.sh --dbfilename dump.rdb
redis-cli -p 6379
> PING
PONG
> SET mykey "Hello World"
OK
> GET mykey
"Hello World"
> SET key-with-expiry "I will expire" PX 5000
OK
> KEYS *
1) "mykey"
2) "key-with-expiry"