A lightweight, production-ready Redis-compatible key-value store implementation in Go. This server implements a subset of the RESP (REdis Serialization Protocol) and can be used with standard Redis clients.
- RESP Protocol Support: Implements Redis Serialization Protocol for compatibility with Redis clients
- Concurrent Connections: Thread-safe handling of multiple client connections
- Core Commands: Supports essential Redis commands:
SET- Store key-value pairsGET- Retrieve values by keyHELLO- Server handshake commandCLIENT- Client management command
- Graceful Shutdown: Proper cleanup of connections and resources
- Context Support: Full context-based cancellation for request handling
- Production Ready: Clean architecture, proper error handling, and structured logging
/
├── cmd/
│ └── server/
│ └── main.go # Application entry point
├── internal/
│ ├── server/
│ │ └── server.go # Server lifecycle and connection management
│ ├── peer/
│ │ └── peer.go # Client connection handling
│ ├── protocol/
│ │ ├── commands.go # Command definitions
│ │ └── parser.go # RESP protocol parsing
│ └── storage/
│ ├── kv.go # Key-value store implementation
│ └── errors.go # Storage error types
├── tests/
│ └── integration_test.go # Integration tests
├── Makefile
├── go.mod
└── README.md
- Server: Manages the TCP listener, peer connections, and command routing
- Peer: Handles individual client connections and message reading
- Protocol: Implements RESP protocol parsing and command definitions
- Storage: Thread-safe in-memory key-value store
- Go 1.22 or later
- Make (optional, for using Makefile commands)
# Clone the repository
git clone < https://github.com/ProgrammedByHussain/GoRedis >
cd goredisclone-master
# Build the server
make build
# or
go build -o bin/goredis ./cmd/serverStart the server with default settings (listens on port 5001):
make run
# or
./bin/goredisStart the server on a custom port:
./bin/goredis --listenAddr :6379You can connect to the server using the official Redis CLI:
redis-cli -p 5001Once connected, you can use supported commands:
> SET foo bar
OK
> GET foo
"bar"
> HELLO 3
%1
server:redis
> CLIENT SETNAME myclient
OK
The server is compatible with standard Redis client libraries. Example using go-redis:
import (
"context"
"github.com/redis/go-redis/v9"
)
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:5001",
})
err := rdb.Set(context.Background(), "key", "value", 0).Err()
val, err := rdb.Get(context.Background(), "key").Result()--listenAddr: TCP address to listen on (default::5001)- Example:
--listenAddr :6379or--listenAddr 0.0.0.0:5001
- Example:
Currently, configuration is done via command-line flags. Future versions may support environment variables.
make test
# or
go test -v ./tests/...This implementation supports a subset of the RESP protocol:
- Simple Strings:
+OK\r\n - Bulk Strings:
$5\r\nhello\r\n - Arrays:
*2\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n - Maps:
%2\r\n$6\r\nserver\r\n$5\r\nredis\r\n
| Command | Description | Example |
|---|---|---|
SET key value |
Store a key-value pair | SET foo bar |
GET key |
Retrieve a value by key | GET foo |
HELLO version |
Server handshake | HELLO 3 |
CLIENT SETNAME name |
Set client name | CLIENT SETNAME myclient |
- Built with tidwall/resp for RESP protocol support
- Tested with redis/go-redis client library