A minimal Redis-compatible server written in Go.
Implements core Redis commands using the RESP (REdis Serialization Protocol).
You can use any standard Redis client (like redis-cli) to test and interact with it.
- ✅ RESP protocol (serializer/deserializer) implemented from scratch
- ✅ TCP-based byte stream handling
- ✅ Command support:
PINGSETGETHSETHGETHGETALL
- ✅ Works with real Redis clients
- 🚫 No persistence yet (AOF not implemented)
.
├── main.go # Entry point for server
├── server/ # TCP server setup and connection handling
├── resp/ # RESP protocol (serialization/deserialization)
├── commands/ # Implementation of supported commands
├── writer/ # Response writer abstraction using bufio
## 🔌 RESP Protocol Overview
RESP is a **binary-safe**, **length-prefixed** protocol (not delimiter-based).
### Key Concepts:
- `*` denotes an **array**
- `$` denotes a **bulk string**
- `+` denotes a **simple string**
For example, the command:
GET name hamza
Is translated into RESP as:
*3\r\n
$3\r\n
GET\r\n
$4\r\n
name\r\n
$5\r\n
hamza\r\n
This means:
- `*3` → 3 elements in the array
- `$3 GET` → the command
- `$4 name`, `$5 hamza` → the arguments
Note: While the protocol is CRLF-based (`\r\n`), clients like `redis-cli` abstract that away—you can write inline commands normally.
---
## 🧪 Testing the Server
### Prerequisite
Install a Redis client (`redis-cli`).
Any client should work, but this was tested with the Debian package version.
### Run Instructions
Open two terminals:
**Terminal 1 – Start the server**
```bash
go run main.go
Terminal 2 – Test commands with redis-cli
redis-cli ping
redis-cli set mykey myvalue
redis-cli get mykey
redis-cli hset myhash field1 value1
redis-cli hget myhash field1
redis-cli hgetall myhash
🧠 How It Works
resp/: Parses and constructs RESP messages (serializer and deserializer).
commands/: Implements supported commands and stores them in a command map.
writer/: Wraps bufio to abstract the TCP response sending mechanism.
server/: Bootstraps the TCP listener and routes requests to handlers.
🚧 Data Persistence
Persistence is not implemented yet (AOF is not used like in real Redis).
Looking for a lightweight alternative—open to ideas and contributions!