Skip to content

Yash-sudo-web/redis-implementation-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis Implementation in Go

A lightweight Redis server and a Redis Client implementation written in Go featuring support for various Redis commands, RESP protocol handling, loading RDB files and basic master-slave replication.

Untitled-2025-02-05-2055


Table of Contents


Features

  • Basic Redis commands (GET, SET, DEL, PING, ECHO)
  • Key expiration support
  • Master-slave replication
  • RDB file persistence
  • RESP (Redis Serialization Protocol) implementation
  • Docker support with master-slave configuration
  • Compatibility with Redis: The custom server and client are fully compatible with Redis's official server and client. This means the custom server can interact with the Redis client, and the custom client can work with the Redis server.

Demo

2025-02-06.20-55-30.mp4

Getting Started

Prerequisites

  • Go version 1.21 or higher.
  • Basic understanding of Redis and its protocol.
  • Docker (optional)
  • Docker Compose (optional)

Installation

Local Installation

  1. Clone this repository:

    git clone https://github.com/Yash-sudo-web/redis-implementation-golang.git
    cd redis-implementation-golang
    cd redis-server
  2. Build the Server:

    go build ./cmd/main.go
  3. Run the Server

    # Standalone mode
     ./main --port 6379 --dir ./test-rdb --dbfilename dump.rdb
     
     # Slave mode
     ./main --port 6380 --dir ./test-rdb --dbfilename dump.rdb --replicaof "localhost 6379"
    
      #RDB files can be loaded into the server, with a sample file provided in the test-rdb directory for reference.
  4. Bulid the Client

    cd .. && cd redis-client
    go build .
    
  5. Run the Client

    ./redis-client
    

Docker Deployment

  1. Run with Docker Compose (master-slave setup): This will deploy and expose 1 master and 2 slave instances of the server and 1 Client on port 6379, 6380, 6381 and 8080 respectively.

    # Build docker images
    docker-compose build
    # Start all services
    docker-compose up

Usage

Connection Details

When using the custom client, specify the hostnames and ports as redis-master:6379 for the master, redis-slave-1:6379 for slave 1, and redis-slave-2:6379 for slave 2. These settings can be adjusted in the docker-compose file if needed. However, when using Redis's official CLI, specifying these hostnames is not required and only ports would be required to establish the connection.

Command Line Arguments

  • --port: Server port (default: 6379)
  • --dir: Directory for RDB file storage
  • --dbfilename: Name of the RDB file
  • --replicaof: Master node configuration for slave mode (format: "host port")

Supported Commands

Command Description Usage
PING Test connection PING
ECHO Echo input ECHO message
SET Set key-value SET key value [PX milliseconds]
GET Get value GET key
DEL Delete key DEL key
KEYS List all keys KEYS *
CONFIG GET Get configuration CONFIG GET parameter
INFO REPLICATION Get replication info INFO REPLICATION

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published