A minimal Redis clone built from scratch in Go — just enough to power basic SET and GET commands, using the same RESP protocol that real Redis speaks. It’s fast, lightweight, and works out of the box with the official Go Redis client. Perfect for learning how Redis works under the hood.
This project mimics a small part of Redis by:
- Accepting TCP connections on port
5001 - Parsing commands using the RESP (REdis Serialization Protocol)
- Handling the two most basic Redis operations:
SETandGET - Supporting concurrent connections
- Being fully compatible with Redis clients (tested with Go Redis)
- Running in Docker or natively with a Makefile
- ✅
SETandGETsupport with in-memory storage - RESP protocol parsing and encoding (bulk strings, arrays, simple strings, etc.)
- Works with official Redis clients
- Concurrent connections handling.
git clone https://github.com/ShivankSharma070/redis-clone-golang.git
cd redis-clone-golangmake build # builds the binary
make run # runs the server (defaults to localhost:5001)To specify the port for redis server set PORT while running your make command.
make run PORT=":3000" # ':' is required.If you prefer containers:
docker build . -t go-redis-clone
docker run -p 5001:5001 go-redis-clone To specify the port for redis server user --listenAddr flag :
docker run -p 3000:3000 go-redis-clone --listenAddr :3000Once the server is running, you can interact with it using the official Go Redis client:
import (
"fmt"
"github.com/redis/go-redis/v9"
)
func main() {
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:5001",
DisableIndentity: true,
})
err := rdb.Set(context.Background(), "foo", "bar", 0).Err()
if err != nil {
panic(err)
}
val, err := rdb.Get(context.TODO(), "foo").Result()
if err != nil {
panic(err)
}
fmt.Println("foo", val)
}RESP is the protocol that Redis uses to talk to clients. It's super simple and human-readable:
*means an array$means a bulk string+means a simple string-means an error:means an integer
Example raw SET command over TCP:
*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n
This server parses and handles this, just like Redis would.
| Command | Description |
|---|---|
make build |
Compile the server binary |
make run |
Run the server locally |
make test |
Test server with multiple Clients |
make test-client |
Test Golang's Official Redis client |
make clean |
Remove binaries and build artifacts |
This is a basic prototype meant for learning. Some things it does not do yet:
- No persistence (all data is in-memory)
- No support for other Redis commands
- No clustering, pub/sub, or authentication
- Limited error handling
Redis is a brilliant piece of software — simple in concept, blazing fast in practice. By building a tiny clone from scratch, I wanted to deeply understand:
- TCP servers in Go
- Protocol design and parsing
- Memory stores and command dispatching
- How real clients interact with Redis over the wire
This project helped me gain that insight, and I hope it helps you too.
This project was originally inspired by the following video tutorial:
All core logic and protocol implementation were based on that walkthrough. I've since modified, extended, and containerized the project to suit my own learning and understanding of how Redis works internally.
Big thanks to the original creator for making such a helpful resource!