Skip to content

yuann3/rego

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rego

A lightweight Redis-compatible server written in Go. Rego speaks the RESP protocol so it can be driven by standard Redis clients while providing core Redis data structures, replication, and persistence features.

Features

  • RESP protocol compatibility for use with existing Redis tooling
  • String storage with NX/XX and PX/EX options plus atomic INCR
  • Durable state via RDB parsing on startup with optional replica mode
  • Transaction support (MULTI/EXEC/DISCARD) and synchronous replication via WAIT
  • Stream primitives (XADD, XRANGE, XREAD) for append-only data
  • List data type with blocking pops (BLPOP) for queue-style workloads
  • Pub/Sub channels with SUBSCRIBE, UNSUBSCRIBE, and PUBLISH
  • Sorted sets backing both ZSET commands and geospatial queries (GEO*)

Getting Started

Prerequisites

  • Go 1.21 or higher

Running the Server

# Run the server with default settings
./run.sh

# Run the server with custom settings
./run.sh --port 6380 --dir /path/to/data --dbfilename custom.rdb

Setting up Replication

To create a replica instance:

# Start the master on the default port (6379)
./run.sh

# Start a replica on port 6380
./run.sh --port 6380 --replicaof "localhost 6379"

Project Structure

  • app/ – Server source code
    • main.go – Process entrypoint, connection handling, CLI flags
    • handler.go – RESP command registry and command implementations
    • resp.go – RESP encoder/decoder
    • key-value-store.go – In-memory store with TTL management
    • config.go – Runtime configuration and replication offsets
    • replica.go – Master/replica synchronization logic
    • rdb_parser.go – RDB file parser and loader
    • stream.go, stream_manager.go – Stream data structure and range/read helpers
    • list.go, list_manager.go – List operations plus blocking pop coordination
    • pubsub_manager.go – Channel subscription tracking and message fan-out
    • sorted_set.go – Sorted set storage used by ZSET and GEO commands
  • run.sh – Convenience script to build and run the server
  • create_rdb.sh, dump.rdb, empty.rdb – Test fixtures for RDB parsing

Supported Commands

  • Basic: PING, ECHO
  • Strings: SET, GET, INCR, TYPE
  • Keys: KEYS
  • Configuration & replication: CONFIG GET, INFO REPLICATION, REPLCONF, PSYNC, WAIT
  • Transactions: MULTI, EXEC, DISCARD
  • Streams: XADD, XRANGE, XREAD
  • Lists: LPUSH, RPUSH, LRANGE, LLEN, LPOP, BLPOP
  • Pub/Sub: SUBSCRIBE, UNSUBSCRIBE, PUBLISH
  • Sorted sets: ZADD, ZRANGE, ZRANK, ZCARD, ZSCORE, ZREM
  • Geospatial: GEOADD, GEOPOS, GEODIST, GEOSEARCH

The server is intentionally focused on the subset of Redis features above, making it a practical playground for understanding how Redis works under the hood.

About

a redis server, but in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published