Skip to content

A simple Redis server implementation in Go. Supports most Redis commands and replication . Built as part of a learning exercise.

Notifications You must be signed in to change notification settings

Gregjarvez/redis-go

Repository files navigation

Redis Go

A simple Redis server implementation in Go, built as part of a learning exercise or for lightweight, custom Redis-like use cases. This project leverages Go'store networking and concurrency features to support basic Redis commands, aiming to provide a functional yet minimal Redis-like server.

Features

  • Basic Commands
    • PING - Test connectivity with the server. Responds with PONG.
    • ECHO - Responds with the argument passed.
    • SET - Stores a key-value pair in memory with optional expiration.
    • GET - Retrieves the value for a given key. Returns nil if the key does not exist.
    • CONFIG - Retrieve or set server and environment configuration.
    • KEYS - Fetches keys matching a pattern (currently supports * wildcard).
    • INFO - Provides server information.
    • REPLCONF - Acknowledge and synchronize replica configuration.
      • GETACK - Replica synchronisation
      • ACK - Replica synchronisation
    • PSYNC - Implements full resynchronization for replica servers.
    • COMMAND for documentation purposes.
      • DOCS- Server documentation. Currently just returns Welcome
    • WAIT - Replica consistency - This command blocks the current client until all the previous write commands are successfully transferred and acknowledged by at least the number of replicas you specify in the numreplicas argument.

Prerequisites

  • Go v1.23 or higher.
  • Redis CLI or any Redis client for testing.

Installation

  1. Clone the repository::
   git clone <repository-url>
  1. Navigate to the project directory:
   cd redis-gp
  1. Build the project:
   go build -o redis-go .

Usage

  1. Start the server:
   ./redis-go
  1. Connect to the server using the Redis CLI:
   redis-cli

Testing Commands

  • PING:
  > PING
  +PONG
  • SET:
  > SET key value
  +OK
  • GET:
  > GET key
  "value"

CONFIG:

Retrieve configurations:

> CONFIG GET dir
1) "dir"
2) "/path/to/directory"

KEYS:

> KEYS *
1) "key1"
2) "key2"

INFO:

> INFO replication
"Master replication information"

REPLCONF:

> REPLCONF ACK 0
+OK

PSYNC:

> PSYNC
1) "FULLRESYNC <master-replid> <master-offset>"
2) "<data-dump>"

COMMAND:

> COMMAND docs
"Welcome"

Replication

This server supports a basic implementation of redis' master server replication, allowing replicas to synchronize with the master for data consistency. The server supports replica synchronization and replica command acknowledgment to ensure consistency and coordination between the master server and its replicas. Replication is implemented to allow replicas to stay synchronized with the master server, especially for critical commands and state updates. The commands related to replica synchronization include:

Project Goals

This project is designed to:

  1. Explore Go'store capabilities in building a custom server.
  2. Understand concurrency patterns and networking in Go.
  3. Serve as a practical example for custom lightweight Redis-like use cases.

About

A simple Redis server implementation in Go. Supports most Redis commands and replication . Built as part of a learning exercise.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published