A Redis clone written in Go, compatible with Redis client libraries. GetSetGo provides a high-performance, in-memory key-value and hash store with data persistence through an Append-Only File (AOF).
-
Key-Value Store: Supports basic
SETandGEToperations for string data. -
Hash Store: Implements
HSET,HGET, andHGETALLoperations for storing hash data structures. -
Append-Only File (AOF): Persists data to disk to prevent data loss, ensuring durability.
-
AOF Rewriting: Periodically rewrites the AOF file to optimize its size and improve recovery performance.
-
TCP Server: Listens for client connections on a specified port, communicating via the RESP (REdis Serialization Protocol).
-
Redis Client Compatibility: Designed to be compatible with standard Redis client libraries.
GetSetGo operates as a single-threaded TCP server, handling client connections and processing commands. It utilizes a core in-memory database (CoreDataBase) to store key-value pairs and hash maps. All incoming commands are parsed using a custom RESP serializer (serializer/respSerializer.go) and then dispatched to appropriate handlers (cmdHandler.go). For data persistence, GetSetGo implements an Append-Only File (AOF) mechanism (aof.go). All write operations (SET, HSET) are appended to the AOF file. To prevent the AOF from growing indefinitely, a background routine periodically rewrites the AOF, creating a compact snapshot of the current database state. This design ensures both high performance for in-memory operations and data durability.
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
-
Go: Version 1.24.1 or later.
- Clone the repository:
git clone https://github.com/sakshamg567/getsetgo.git
cd getsetgo
- Build the project:
make build
This command compiles the Go application and creates an executable in the ./bin directory.
To start the GetSetGo server:
make
The server will listen on port 8080 by default.
For development with hot-reloading, you can use air:
make dev
This command runs air main.go, which automatically recompiles and restarts the server when code changes are detected, significantly speeding up the development cycle.
You can interact with the GetSetGo server using any Redis client library or by manually sending RESP (REdis Serialization Protocol) commands over a TCP connection.
* 1\r\n$4\r\nPING\r\n
- Response:*
+ PONG\r\n
* 3\r\n$3\r\nSET\r\n$5\r\nmykey\r\n$7\r\nmyvalue\r\n
- Response:*
+ OK\r\n
* 2\r\n$3\r\nGET\r\n$5\r\nmykey\r\n
- Response:*
$7\r\nmyvalue\r\n
* 5\r\n$4\r\nHSET\r\n$4\r\nmyhash\r\n$3\r\nkey1\r\n$5\r\nval1\r\n
- Response:*
:1\r\n
* 2\r\n$7\r\nHGETALL\r\n$4\r\nmyhash\r\n
- Response:*
* 2\r\n$4\r\nkey1\r\n$5\r\nval1\r\n
├── aof.go
├── cmdHandler.go
├── db.aof
├── db.go
├── go.mod
├── main.go
├── Makefile
├── peer.go
├── README.md
├── serializer
│ └── respSerializer.go
-
Implement more Redis commands (e.g.,
DEL,EXPIRE,LPUSH,RPUSH,SADD,SMEMBERS). -
Add support for different data types (e.g., Lists, Sets, Sorted Sets).
-
Introduce expiration for keys.