Go-Redis is a high-performance, single-threaded, Redis-compatible Key-Value store implemented in Go. It replicates the core architecture of Redis to achieve high throughput and low latency, handling ~49,000 GET/sec at 20 µs average latency on a single thread.
This project was built to explore operating system internals, specifically non-blocking I/O, event loops, and efficient data structures.
-
I/O Multiplexing: Implements a custom event loop using
syscall.EpollWait(Linux) andsyscall.Kqueue(macOS) to handle thousands of concurrent connections (C10k ready). - Redis Protocol (RESP): 100% compatible with existing Redis clients (redis-cli, Jedis, go-redis).
-
Data Structures:
- Strings: Binary-safe string storage.
-
Hash Maps: Incremental resizing for strict
$O(1)$ performance. -
Sorted Sets (ZSET): Implementation of SkipList for
$O(\log N)$ range queries and ranking.
- Persistence: AOF (Append Only File) persistence (optional configuration).
- TTL: Key expiration and eviction strategies (LRU approximation).
Benchmarks conducted on a local development environment (Intel Core i7-10750H) demonstrate performance comparable to standard Redis for supported commands.
Verified using redis-benchmark -t set,get -n 100000 -c 50 — 50 concurrent
connections, average latency per operation.
The 20 µs above is redis-benchmark average latency at 50 connections. Under a
sustained load test at 200+ virtual users the server stays up and P95 rises to
~129 ms: a saturation figure, not a per-operation one. The two numbers describe
different loads and are not comparable — quote whichever matches the question.
The architecture mimics the single-threaded event loop design of Redis:
graph TD
Client1[Client] -->|TCP IP| Epoll["Event Loop (Epoll/Kqueue)"]
Client2[Client] -->|TCP IP| Epoll
Epoll -->|File Event| FileHandler[Connection Handler]
Timer["Time Events"] -->|Tick| TimerHandler["Cron/Cleanup"]
FileHandler --> Parser["RESP Parser"]
Parser --> Dispatcher["Command Dispatcher"]
Dispatcher --> Dict["Global Dictionary (Hash Map)"]
Dispatcher --> SkipList["Sorted Set Engine"]
subgraph "Core Engine (Single Threaded)"
Epoll
FileHandler
Parser
Dispatcher
end
- Go 1.21+
- Docker (optional)
# Clone the repository
git clone https://github.com/Mazukiri/Go-Redis.git
cd Go-Redis
# Build the binary
make build
# Run the server
make runThe server listens on 0.0.0.0:8082 by default.
docker build -t redis-clone .
docker run -p 8082:8082 -p 9090:9090 redis-clone# Run unit tests
make test
# Run benchmarks
make benchYou can connect using the standard redis-cli:
redis-cli -p 8082
127.0.0.1:8082> SET mykey "Hello World"
OK
127.0.0.1:8082> GET mykey
"Hello World"MIT
