A lightweight, in-memory Redis clone built in GoπΉ over raw TCP, implementing core Redis functionality including transactions, pub/sub, expiration, and LRU eviction.

GET keySET key valueDEL keyINCR key/DECR keyFLUSHALLPINGQUIT
EXPIRE key secondsβ Set a timeout on a keyTTL keyβ Get remaining time to live- Automatic expiry with background eviction.
MULTIβ Start transactionEXECβ Execute queued commandsDISCARDβ Cancel transaction- Queues and executes atomic command blocks per connection
SUBSCRIBE channelPUBLISH channel message- Real-time pub/sub system with multiple channels
- Auto-evicts least recently used keys when size threshold is exceeded
- Built with
container/listfor efficient O(1) updates - Integrated into
GET,SET, andDELoperations
- Fully RESP-compliant parser (supports
*,$,+,-,:) - Allows communication with Redis CLI or custom tools
- Listens on
tcp://0.0.0.0:6380 - Handles concurrent clients
- Graceful error handling for malformed inputs
redis-clone/
βββ cmd/ # Entrypoints for different binaries
β βββ bench/ # Benchmark client
β β βββ bench.go # Runs benchmark tests on Redis clone
β βββ server/ # Main server entrypoint
β βββ main.go # Starts the Redis server
β
βββ internal/ # Core application logic, organized by domain
β βββ cache/ # In-memory storage layer
β β βββ lru.go # LRU eviction policy implementation
β β βββ lru_test.go
β β βββ store.go # Key-value store with expiration
β β βββ store_test.go
β
β βββ command/ # RESP command parsing and execution
β β βββ handler.go # Handles Redis commands: GET, SET, DEL, etc.
β β βββ handler_test.go
β
β βββ persistence/ # RDB/AOF Persistence mechanism
β β βββ rdb.go # Dump/load logic for persistence
β β βββ rdb_test.go
β
β βββ protocol/ # RESP protocol handling
β β βββ buffer_writer.go # Efficient buffered output
β β βββ parser.go # RESP3-compatible parser
β β βββ parser_test.go
β
β βββ pubsub/ # Publish/Subscribe message broker
β β βββ pubsub.go
β β βββ pubsub_test.go
β
β βββ session/ # Connection/session management
β β βββ session.go
β β βββ session_test.go
β
β βββ transaction/ # MULTI/EXEC transactions
β βββ transaction.go
β
βββ img/ # Architecture or design diagrams
β βββ sys.png
β βββ sys2.png
β
βββ dump.rdb # Sample RDB file for persistence testing
βββ redis-clone # Built binary (created by Makefile)
βββ go.mod # Go module definition
βββ LICENSE
βββ Makefile # Automates build, test, benchmark, etc.
βββ README.md # Project documentation
go run cmd/server/main.goConnect using Redis CLI:
redis-cli -p 6380Go CLI layout for benchnark:
go run cmd/benchmark/main.go -clients=50 -requests=100Warning
Tests are currently under construction
Some parts of the system aren't fully covered yet, and there are a few known issues we're ironing out.
- Running test for Cache package
go test ./internal/cache -v- Test file for the command package to test the Handle function,including GET, SET, SET EX, and DEL
go test ./internal/command -v- Running test for protocol package
go test ./internal/protocol -v- Running test for session package
go test ./internal/session -v- Running test for persistance package
go test ./internal/persistence -v- Running test for pubsub package
go test ./internal/pubsub -vThis project was inspired by a few projects, books and blog posts, it's based on them with things changed to the way I like
- redis-internals
- Writing a Redis clone in Go from scratch
- Go, for Distributed Systems by Russ Cox
- Designing Data-Intensive Applications by Martin Kleppmann
- and Obviously LLM like (GPT-4o, Claude, Gemini, etc)
Contribution Guidelines
- Fork the repository
- Create a new branch
# create a new branch
git checkout -b feature/my-update
# make your changes and push
git add .
git commit -m "Added my update"
git push origin feature/my-update
- Write tests for new functionality (if possible)
- Run tests locally
- Submit a pull request with a clear description
π Todo
- Fix unit tests
- Add proper LRU caching support
- Add persistence (RDB/AOF)
- Build a simple CLI client
- Benchmarking tool