A Redis clone in Go built with raw kqueue syscalls — no net package, no goroutine per connection, no mutex.
Handles thousands of concurrent clients on a single goroutine by letting the kernel do the waiting.
The event loop registers every client socket with kqueue, then blocks on Kevent(). The kernel wakes it up only when a socket has data ready. One goroutine reads, parses, executes, and replies — then goes back to sleep.
Kevent() sleeps...
→ kernel: fd 7 has data
→ parse RESP command
→ execute against store
→ write response
→ back to Kevent()
No locks needed because nothing runs concurrently.
| Command | Example |
|---|---|
PING |
PING → +PONG |
SET |
SET key value → +OK |
GET |
GET key → $3\r\nbar |
DEL |
DEL key → :1 |
EXISTS |
EXISTS key → :1 or :0 |
go run .Listens on :6379. Connect with any Redis client:
redis-cli ping
redis-cli set foo bar
redis-cli get foo# In one terminal
go run .
# In another
go test ./...Includes correctness tests, a 100-goroutine concurrent SET/GET test, and benchmarks.
go test -bench=. -benchtime=5s| File | What it does |
|---|---|
main.go |
Entry point — creates store, starts server |
server.go |
kqueue event loop — accept, read, close |
client.go |
Per-client buffer and RESP parse loop |
resp.go |
RESP protocol parser and marshaller |
store.go |
map[string]string — the entire database |
commands.go |
Command dispatch table |
handler.go |
One handler per command |
macOS only — uses kqueue, which is a BSD/macOS kernel API. Linux equivalent is epoll.