A minimalist Redis clone written in Go, implementing the RESP2 protocol from scratch.
This project serves as a deep dive into building low-level systems and understanding the inner workings of Redis.
- Custom RESP2 (Redis Serialization Protocol) parser.
- Support for core Redis data types:
- Simple Strings (
+OK
) - Errors (
-ERROR
) - Integers (
:100
) - Bulk Strings (
$6\r\nfoobar\r\n
) - Arrays (
*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n
)
- Simple Strings (
- Basic command parsing and response handling.
- Modular codebase with clear separation of concerns.
my-redis/
├── command/ # Command parsing and execution
├── resp/ # RESP2 protocol implementation
├── server/ # TCP server setup and client handling
├── store/ # In-memory data storage
├── utils/ # Utility functions
├── main.go # Entry point of the application
├── go.mod # Go module file
└── README.md # Project documentation
- Go 1.20 or higher installed on your machine.
# Clone the repository
git clone https://github.com/DNahar74/my-redis.git
# Navigate to the project directory
cd my-redis
# Build the application
go build -o my-redis.exe
# Run the application
./my-redis
Once the server is running, you can interact with it using telnet
or any Redis client:
telnet localhost 6379
Example commands:
SET key value
GET key
DEL key
Note: Command support is currently limited as this is a work in progress.
- Description: Tests the connection with the server.
- Usage:
PING
- Response:
+PONG
- Description: Returns the input string.
- Usage:
ECHO "hello world"
- Response:
"hello world"
- Description: Stores a key with a string value. Optional expiry flag in seconds.
- Usage:
SET hello world SET hello world EX 100 # Key expires in 100 seconds
- Response:
+OK
- Description: Retrieves the value of the given key.
- Usage:
GET hello
- Response (if found):
"world"
- Description: Deletes the specified key.
- Usage:
DEL hello
- Response:
+OK
The Redis Serialization Protocol (RESP) is a simple protocol used by Redis for client-server communication.
This project implements RESP version 2.
- Format:
+<string>\r\n
- Format:
-<error message>\r\n
- Format:
:<number>\r\n
- Format:
$<length>\r\n<string>\r\n
- Format:
*<number of elements>\r\n<element1>\r\n<element2>\r\n...
For a more detailed explanation, refer to the Redis Protocol specification.
Contributions are welcome!
If you'd like to add features, fix bugs, or improve documentation, please fork the repository and submit a pull request.
- Redis for the inspiration and protocol specification.
- Go Programming Language for its simplicity and performance.