Skip to content

aneeshpatne/goredis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoRedis

License: MIT

A lightweight Redis-compatible server implementation in Go, built from scratch using raw TCP sockets and the Redis Serialization Protocol (RESP).

Overview

GoRedis is an educational implementation of a Redis-like in-memory data store. It demonstrates low-level network programming in Go, including TCP socket handling, the RESP protocol parsing, and concurrent client management.

Features

Supported Commands

Command Description
PING Test server connectivity, returns PONG

Planned Commands

  • GET - Retrieve the value of a key
  • SET - Set a key to hold a string value
  • LPUSH - Prepend elements to a list
  • LRANGE - Get a range of elements from a list

Getting Started

Prerequisites

  • Go 1.22 or later

Installation

git clone https://github.com/aneeshpatne/goredis.git
cd goredis

Running the Server

go run server.go

The server listens on port 6380 by default.

Usage

Connect to the server using redis-cli or any Redis-compatible client.

Using redis-cli

redis-cli -p 6380
127.0.0.1:6380> PING
PONG

Using netcat

echo -e '*1\r\n$4\r\nPING\r\n' | nc localhost 6380

Architecture

goredis/
├── server.go       # Main server, TCP listener and client handler
└── resp/
    └── resp.go     # RESP protocol encoder and parser

Components

  • Server: Manages TCP connections and routes commands to handlers
  • RESP Package: Implements the Redis Serialization Protocol for encoding responses and parsing incoming commands

Protocol

GoRedis implements the RESP (Redis Serialization Protocol) specification:

  • Simple Strings: Prefixed with +
  • Errors: Prefixed with -
  • Bulk Strings: Prefixed with $ followed by the byte length
  • Arrays: Prefixed with * followed by the element count

License

This project is open source and available under the MIT License.

About

Redis Server written in Go

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages