Skip to content

πŸš€ GoDis - A lightweight, Redis-inspired in-memory database πŸ—„οΈ built in Go. Supports basic commands βš™οΈ, AOF persistence πŸ“‚, and a custom CLI πŸ’».

License

Notifications You must be signed in to change notification settings

manimovassagh/Godis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Godis

A simple, lightweight Redis clone written in Go, featuring an in-memory data store with append-only file (AOF) persistence and a custom command-line interface (CLI).

Table of Contents

Introduction

Godis is a Redis-inspired in-memory data store built from scratch in Go. It supports basic Redis commands and features an append-only file (AOF) persistence mechanism to ensure data durability across restarts. Additionally, Godis includes a custom CLI for interacting with the server without relying on external tools.

Features

  • In-memory key-value data store
  • Append-only file (AOF) persistence
  • RESP (REdis Serialization Protocol) implementation
  • Custom Godis CLI for server interaction
  • Supports basic Redis commands: SET, GET, PING, ECHO
  • Thread-safe operations using Goroutines and Mutexes
  • Modular codebase with clear package separation

Architecture

Godis is structured into several packages to promote modularity and maintainability:

  • cmd: Contains the entry points for the server and CLI.
  • internal/aof: Manages the append-only file persistence.
  • internal/commands: Handles client connections and command execution.
  • internal/datastore: Implements the in-memory data store.
  • internal/protocol: Parses and constructs RESP messages.
  • internal/server: Contains the TCP server logic.

Getting Started

Prerequisites

  • Go 1.23 or higher installed on your machine
  • Git for cloning the repository (optional)

Installation

  1. Clone the repository

    git clone https://github.com/manimovassagh/Godis.git
  2. Navigate to the project directory

    cd Godis
  3. Build the server

    go build -o godis-server ./cmd/server
  4. Build the CLI

    go build -o godis-cli ./cmd/client

Usage

Starting the Server

Run the Godis server by executing:

./godis-server

The server will start listening on port 6379.

Using the CLI

In a new terminal window, start the Godis CLI:

./godis-cli

You should see:

Godis CLI connected to localhost:6379
Type 'exit' or 'quit' to close the CLI.
godis>

You can now enter commands to interact with the server.

Supported Commands

  • PING

    godis> PING
    PONG
  • ECHO

    godis> ECHO "Hello, Godis!"
    Hello, Godis!
  • SET

    godis> SET mykey "Some value"
    OK
  • GET

    godis> GET mykey
    Some value
  • EXIT / QUIT

    godis> EXIT
    Bye!

Project Structure

Godis/
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ server/
β”‚   β”‚   └── main.go          // Server entry point
β”‚   └── client/
β”‚       └── main.go          // CLI entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ aof/
β”‚   β”‚   └── aof.go           // AOF persistence
β”‚   β”œβ”€β”€ commands/
β”‚   β”‚   └── commands.go      // Command handling
β”‚   β”œβ”€β”€ datastore/
β”‚   β”‚   └── datastore.go     // In-memory data store
β”‚   β”œβ”€β”€ protocol/
β”‚   β”‚   └── protocol.go      // RESP implementation
β”‚   └── server/
β”‚       └── server.go        // TCP server logic
β”œβ”€β”€ go.mod                   // Go module file
└── README.md                // Project documentation

Roadmap

  • Additional Commands: Implement more Redis commands such as DEL, INCR, EXISTS.
  • Data Structures: Add support for lists, sets, hashes, and sorted sets.
  • Expiration: Implement key expiration and TTL functionality.
  • Persistence Enhancements: Introduce snapshotting (RDB files) and AOF rewriting.
  • Configuration: Allow server settings via configuration files or command-line flags.
  • Improved CLI: Enhance the CLI with command history, auto-completion, and syntax highlighting.
  • Testing: Develop comprehensive unit and integration tests for all components.
  • Logging: Implement structured logging for better observability.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository

  2. Create a new feature branch

    git checkout -b feature/my-feature
  3. Commit your changes

    git commit -am 'Add new feature'
  4. Push to the branch

    git push origin feature/my-feature
  5. Open a pull request

Please ensure your code adheres to the project's coding standards and includes appropriate tests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Redis for the inspiration behind this project.
  • The Go community for providing excellent tools and documentation.
  • Everyone who contributes to open-source projects and promotes knowledge sharing.

Note: This project is for educational purposes to understand how key-value stores and network servers work. It is not intended for production use.

About

πŸš€ GoDis - A lightweight, Redis-inspired in-memory database πŸ—„οΈ built in Go. Supports basic commands βš™οΈ, AOF persistence πŸ“‚, and a custom CLI πŸ’».

Resources

License

Stars

Watchers

Forks

Packages

No packages published