Skip to content

helloru20563/getsetgo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GetSetGo

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).

Table of Contents

Key Features

  • Key-Value Store: Supports basic SET and GET operations for string data.

  • Hash Store: Implements HSET, HGET, and HGETALL operations 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.

Architecture Overview

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.

Getting Started

Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Installation

  1. Clone the repository:
git clone https://github.com/sakshamg567/getsetgo.git

cd getsetgo
  1. Build the project:
make build

This command compiles the Go application and creates an executable in the ./bin directory.

Running the Server

To start the GetSetGo server:

make

The server will listen on port 8080 by default.

Development

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.

Usage

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.

Example Commands

PING

* 1\r\n$4\r\nPING\r\n

  • Response:*
+ PONG\r\n

SET

* 3\r\n$3\r\nSET\r\n$5\r\nmykey\r\n$7\r\nmyvalue\r\n

  • Response:*
+ OK\r\n

GET

* 2\r\n$3\r\nGET\r\n$5\r\nmykey\r\n

  • Response:*
$7\r\nmyvalue\r\n

HSET

* 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

HGETALL

* 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

Project Structure

├── aof.go

├── cmdHandler.go
├── db.aof

├── db.go
├── go.mod

├── main.go
├── Makefile

├── peer.go
├── README.md

├── serializer
│   └── respSerializer.go

Roadmap

  • 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.

About

A redis clone written in go, compatible with redis-client libraries.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 99.2%
  • Makefile 0.8%