projects > from_scratch > redis.go
1
A Redis-compatible server, from scratch, in Go[github]
1
2
A Redis-compatible server built from scratch in Go, speaking the
3
real RESP wire protocol over TCP — you can talk to it with
4
redis-cli. Concurrent clients are handled with a
5
goroutine-per-connection model over a thread-safe keyspace.
6
7
Implements strings with expiry, streams (XADD/XRANGE/XREAD),
8
transactions (MULTI/EXEC/DISCARD), optimistic locking (WATCH),
9
and full leader-follower replication with command propagation and
10
WAIT. Built through the CodeCrafters challenge — base stages plus
11
the Streams, Transactions, Optimistic Locking, and Replication
12
extensions.
13
14
[Go][RESP][TCP][Streams][Transactions][Replication][CodeCrafters]
15
17
18
func Parse(r Reader) (RESPValue, error) {
19
b, err := r.ReadByte()
20
if err != nil {
21
return nil, err
22
}
23
switch b {
24
case '*':
25
return ParseArray(r)
26
case '$':
27
return ParseBulkString(r)
28
case ':':
29
return ParseInteger(r)
30
case '+':
31
return ParseSimpleString(r)
32
33
default:
34
return nil, fmt.Errorf("unexpected input %q", b)
35
}
36
}
37
38
39
40
41
42
43
NORMAL~/oleksandr/projects/from_scratch/redis.go.../from_scratch/redis.gomainutf-8
Enter to open · :q to quit
keys
j / kmove the cursor line, or the tree cursor
hfocus the tree; in the tree, fold or go to the parent
l / Enterin the tree, unfold or open the file
gg / Gfirst / last line
clickput the cursor on a line; on README.sh, run the session again
:qquit to the shell
:help ?this table
q / Escclose this