AN EXPERIMENT IN RUST

Small by choice.
Built to learn.

An in-memory database inspired by Redis. Explore networking, concurrency and persistence in a codebase you can actually understand.

Rust + TokioOpen sourceMIT / Apache-2.0
memorust — redis-cli

# A conversation with Memorust

$ redis-cli -p 6379

127.0.0.1:6379 > SET name Roberto

OK

127.0.0.1:6379 > GET name

"Roberto"

127.0.0.1:6379 > PING

PONG

01 / SET. GET. Understand.
In-memory key-valueRESP protocolTTLAOF persistence

THE FUNDAMENTALS, HANDS ON

What it does

A focused subset of Redis, implemented from scratch with readability as the goal.

01

RESP protocol

Speaks the Redis Serialization Protocol, so redis-cli and existing Redis clients connect with no changes.

02

Async TCP server

Built on Tokio with concurrent client support and concurrent reads under a shared lock.

03

TTL & expiration

SETEX, EXPIRE and TTL with a background cleaner that reclaims expired keys.

04

AOF persistence

Append Only File with a buffered writer, periodic fsync (~1s) and replay on startup.

05

AOF rewrite

Compacts the log with AOFREWRITE so the on-disk history stays small.

06

Single binary, one dependency

Rust edition 2024 with Tokio as the only dependency. Easy to build, read and hack on.

QUICK START

Start at the terminal

Clone, build and connect with any Redis client.

Rust 1.85+ · redis-cli to connect

Read the docs
Terminal
git clone https://github.com/robertolima-dev/memorust.git
cd memorust
cargo run

# In another terminal

redis-cli -p 6379

MEASURING IS LEARNING

Fast where it counts

redis-benchmark on a release build, Apple M-series development machine.

GET · PIPELINE 16~1.27M

operations per second

OperationNo pipeline (-P 1)Pipelined (-P 16)
SET~142k ops/sec~264k ops/sec
GET~163k ops/sec~1.27M ops/sec

Reference results; performance varies by environment.

Without pipelining the benchmark is dominated by network round-trips. Under pipelining the server ceiling shows: reads scale far past writes because GET runs concurrently under a shared lock.

COMMAND REFERENCE

Supported commands

A growing subset of the Redis command set.

Connection

  • PING

Key / Value

  • SET
  • GET
  • DEL
  • EXISTS

Expiration

  • SETEX
  • EXPIRE
  • TTL

Administration

  • INFO
  • FLUSHALL
  • AOFREWRITE

WORK IN PROGRESS

Roadmap

Where Memorust is heading next.

Open an issue

Implemented

  • TCP server & RESP protocol
  • redis-cli compatibility
  • TTL & background cleaner
  • AOF, replay & rewrite
  • Buffered AOF writer (appendfsync everysec)

Up next

  • Async AOF writer
  • Value types (Integer, JSON, List)
  • Config.toml
  • Memory eviction policies
  • Binary snapshot (.db)
  • Replication
  • Cluster mode