A lightweight Redis-compatible server implementation in Go, built from scratch using raw TCP sockets and the Redis Serialization Protocol (RESP).
GoRedis is an educational implementation of a Redis-like in-memory data store. It demonstrates low-level network programming in Go, including TCP socket handling, the RESP protocol parsing, and concurrent client management.
| Command | Description |
|---|---|
PING |
Test server connectivity, returns PONG |
GET- Retrieve the value of a keySET- Set a key to hold a string valueLPUSH- Prepend elements to a listLRANGE- Get a range of elements from a list
- Go 1.22 or later
git clone https://github.com/aneeshpatne/goredis.git
cd goredisgo run server.goThe server listens on port 6380 by default.
Connect to the server using redis-cli or any Redis-compatible client.
redis-cli -p 6380
127.0.0.1:6380> PING
PONGecho -e '*1\r\n$4\r\nPING\r\n' | nc localhost 6380goredis/
├── server.go # Main server, TCP listener and client handler
└── resp/
└── resp.go # RESP protocol encoder and parser
- Server: Manages TCP connections and routes commands to handlers
- RESP Package: Implements the Redis Serialization Protocol for encoding responses and parsing incoming commands
GoRedis implements the RESP (Redis Serialization Protocol) specification:
- Simple Strings: Prefixed with
+ - Errors: Prefixed with
- - Bulk Strings: Prefixed with
$followed by the byte length - Arrays: Prefixed with
*followed by the element count
This project is open source and available under the MIT License.