Skip to content

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redisetgo

A minimal Redis-compatible server written in Go, supporting multiple concurrent clients, basic Redis commands, and append-only file (AOF) persistence. You can connect to it using the official redis-cli or any RESP-compatible client.

Features

  • RESP Protocol Support: Parses and responds using the Redis Serialization Protocol (RESP).
  • Multiple Client Support: Handles many clients concurrently using goroutines.
  • In-Memory Data Store: Supports string and hash data types.
  • Persistence: Uses an append-only file (AOF) to persist write operations and restore state on startup.
  • Thread-Safe: Uses mutexes to ensure safe concurrent access to data.
  • Basic Redis Commands: Implements a subset of Redis commands (see below).

Getting Started

git clone https://github.com/pratham-exe/redisetgo.git
cd redisetgo
go run main.go

The server listens on port 6379 by default.

You can connect using:

redis-cli -p 6379

Supported Commands

Command Description Example Usage
PING Health check, returns PONG or echo PING, PING hello
SET Set a string key SET mykey myvalue
GET Get a string key GET mykey
DEL Delete a string key DEL mykey
EXISTS Check if a key exists EXISTS mykey
INCR Increment integer value at key INCR counter
HSET Set a field in a hash HSET myhash field value
HGET Get a field from a hash HGET myhash field
HGETALL Get all fields and values in a hash HGETALL myhash
REDISHELP List all supported commands and usage REDISHELP

How It Works

Server Loop

  • Listens for TCP connections on port 6379.
  • For each client, spawns a goroutine to handle requests independently.

Command Processing

  • Parses incoming RESP messages.
  • Looks up the command in a map and executes the corresponding function.
  • For write commands (SET, HSET, DEL, INCR), appends the command to the AOF for persistence.

Persistence

  • On startup, replays the AOF file (redis.aof) to restore the in-memory state.
  • A background goroutine periodically syncs the AOF file to disk.

Thread Safety

  • Uses sync.RWMutex to protect shared maps for string and hash data.

About

Redis Server

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages