GoRedis is a lightweight, in-memory key-value store inspired by Redis, implemented in Go. It supports a subset of Redis commands and the Redis Serialization Protocol (RESP).
- In-Memory Storage: Fast key-value storage with support for strings.
- RESP Protocol: Fully compatible with Redis Serialization Protocol (RESP).
- Command Support:
PING
PING string
SET key value
GET key
HSET hash key value
HGET hash key
HGETALL hash
DEL key
- Concurrency: Handles multiple clients concurrently using goroutines.
- Graceful Shutdown: Properly closes connections and cleans up resources.
-
Clone the repository:
git clone https://github.com/yourusername/goredis.git cd goredis
-
Build and run the server:
go run main.go
-
Connect using
redis-cli
ornetcat
:redis-cli -p 5001
make
redis-cli -p 6379
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> SET foo bar
OK
127.0.0.1:6379> GET foo
"bar"
127.0.0.1:6379> DEL foo
(integer) 1
echo -ne "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n" | nc localhost 5001
- Server: Handles client connections and command processing.
- Peer: Manages individual client connections.
- RESP Parser: Parses Redis Serialization Protocol (RESP) commands.
- Each client connection is handled in a separate goroutine.
- Commands are processed sequentially in a single-threaded event loop.
GoRedis implements the following RESP types:
- Simple Strings:
+OK\r\n
- Errors:
-ERR message\r\n
- Integers:
:1000\r\n
- Bulk Strings:
$5\r\nhello\r\n
- Arrays:
*2\r\n$3\r\nGET\r\n$3\r\nkey\r\n
(Non-homogeneous and Nested arrays also supported)
cd resp
go test -v
- Add support for more Redis commands (
EXISTS
,INCR
, etc.). - Implement TTL (Time-to-Live) for keys.
- Add persistence (AOF/RDB).
- Support Redis replication.
Contributions are welcome! Please open an issue or submit a pull request.
- Inspired by Redis.
- Built using Go.