Redix is a distributed, in-memory key-value data store written from scratch in Go. It replicates the core functionality of Redis, including command parsing, RDB persistence, TCP networking, and master-slave replication — designed for high performance, concurrency, and a deeper understanding of distributed systems.
- ⚡ In-memory key-value store with TTL support
- 💬 RESP (REdis Serialization Protocol) parser and encoder
- 💾 RDB persistence with
SAVEandBGSAVE - 🔄 Master-slave replication using
REPLICAOF,PSYNC,REPLCONF, andWAIT - 🧠 Core Redis commands:
PING,ECHO,SET,GET,DEL,KEYS,INFO, etc. - 🔌 Custom TCP server using Go's
netpackage - 🔒 Role-based connection handling (client/master/slave)
- 🧪 Clean modular codebase with extensibility in mind
Redix/
├── main.go # Entry point of the Redis server
├── resp/ # RESP protocol parser and encoder
├── rdb/ # RDB file handling (load/save/stream)
├── store/ # In-memory key-value store with TTL
├── testdata/ # Sample data directory (RDB files)
- Go 1.20+
- (Optional)
redis-clifor interaction
git clone https://github.com/varunarora1606/Redix.git
cd Redix
go build -o redix./redix --dir=./testdata --filename=dump.rdb --port=8000You can use redis-cli or telnet to interact with the server:
redis-cli -p 8000SET name varun
GET name
DEL name
KEYS *
SAVE
BGSAVE
INFO replicationREPLICAOF 127.0.0.1 8000REPLICAOF NO ONEEnsure WAIT <replicas> <timeout-ms> is used to wait for ACKs from slaves:
WAIT 1 1000SAVE: Synchronously saves the in-memory store to an RDB fileBGSAVE: Asynchronously saves in the background- Data is auto-loaded from the RDB file on server start
| Command | Description |
|---|---|
PING |
Health check |
ECHO msg |
Echo the message |
SET key val [PX ms] |
Set key with optional expiry |
GET key |
Get value by key |
DEL key |
Delete a key |
KEYS * |
Get all keys |
SAVE |
Save to RDB synchronously |
BGSAVE |
Save to RDB asynchronously |
INFO replication |
Get replication details |
REPLICAOF host port |
Become replica of a master |
WAIT n t |
Wait for n replicas or t ms |
PSYNC |
Used during replication handshake |
REPLCONF |
Used during replication handshake |
- Custom TCP connection handling
- RESP parsing with proper protocol handling
- Replication handshake protocol (
PING,REPLCONF,PSYNC) - RDB file streaming during full sync
- Offsets and replication IDs for syncing state
- Periodic ACKs to maintain replication health
Run master on port 8000:
./redix --port=8000Run slave on port 8001:
./redix --port=8001Connect to the slave:
redis-cli -p 8001
REPLICAOF 127.0.0.1 8000Set key from master:
redis-cli -p 8000
SET hello worldGet key from slave:
redis-cli -p 8001
GET hello
# Output: "world"Varun Arora
🔗 @VarunArora80243
MIT License. See LICENSE for details.
- Inspired by Redis
- RESP protocol: https://redis.io/docs/reference/protocol-spec/
- Built as part of a Redis deep dive learning project