RESP mini-server (Redis) — Go
Topics: wire-protocol parsing, RESP, in-memory store
Problem
Implement the core of a Redis-style server: parse one client command in the RESP wire format,
run it against an in-memory store, and return the RESP reply. (Connection handling and framing are
out of scope — see the line-protocol and message-framing challenges.)
func New() *Server
func (s *Server) Handle(request []byte) []byte
RESP shapes:
array *<count>\r\n <element>...
bulk string $<len>\r\n<bytes>\r\n (null bulk = $-1\r\n)
simple +OK\r\n integer :<n>\r\n error -ERR <msg>\r\n
Clients send a command as an array of bulk strings, e.g. *2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n.
Commands (case-insensitive):
PING → +PONG\r\n; PING <msg> → bulk reply of <msg>.
SET key val → +OK\r\n.
GET key → bulk reply, or null bulk $-1\r\n if missing.
INCR key → integer reply; error if the stored value isn't an integer.
DEL key... → integer count of keys removed.
- Unknown command or malformed input →
-ERR ...\r\n.
The store, New, and the bulk/errReply encoders are provided; you implement Handle — parse the
RESP array, then dispatch.
Run
go test -v ./challenges/resp-server/go/
Sign in to submit your solution.