Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ridgeDB

ridgeDB is a key-value database written in Go.

It provides a TCP command server, RESP-style protocol handling, TTL-based in-memory storage, append-only persistence, startup recovery, log compaction, and controlled shutdown behavior.

Features

  • TCP server
  • RESP-style protocol
  • CLI client through ridgectl
  • In-memory key-value store
  • TTL-based expiry
  • AOF persistence
  • AOF replay on startup
  • AOF compaction
  • Context-based shutdown flow

Commands

SET <key> <value> <ttl_seconds>
GET <key>
DEL <key>
PING
COMPACT

TTL is provided in seconds. A TTL of 0 means no expiry.

Running

Start the server:

go run ./cmd/ridgedb

Run a command:

go run ./cmd/ridgectl PING

Custom server port:

go run ./cmd/ridgedb -port :9000

Project layout

cmd/ridgedb              server entrypoint
cmd/ridgectl             CLI client
internal/server          TCP handling and command execution
internal/storage         in-memory store, expiry, snapshots
internal/persistence     AOF append, replay, compaction
internal/protocol        RESP-style decoder and encoder

Storage model

Data is kept in memory behind a mutex-protected map. Expiry is handled lazily during reads and actively through a cleanup loop.

The store can produce a snapshot of live keys. This is used by AOF compaction so persistence code does not access the internal map directly.

Persistence model

Write commands are appended to ridgedb.aof.

On startup, ridgeDB replays the AOF to rebuild in-memory state.

Compaction rewrites the AOF from the current live store snapshot, removing overwritten values and deleted keys from the log.

Protocol model

ridgeDB uses a RESP-style protocol over TCP.

Requests are decoded from RESP arrays of bulk strings. Responses are encoded as RESP simple strings, bulk strings, null bulk strings, integers, or errors.

The protocol layer only handles bytes and framing. Command validation and execution live in the server layer.

About

KV store in Go with a custom TCP protocol and append-only persistence

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages