Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hedis

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.

Read the literate guide →


How it works

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.

Supported commands

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

Run it

go run .

Listens on :6379. Connect with any Redis client:

redis-cli ping
redis-cli set foo bar
redis-cli get foo

Test it

# 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

Files

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

Platform

macOS only — uses kqueue, which is a BSD/macOS kernel API. Linux equivalent is epoll.

About

redis clone in golang using event loop

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages