barddoo /zedis

Opinionated Redis in Zig

★ 298⑂ 14👁 3⑃ 28● 24▤ 13◈ 1
ZigMITCreated 2025-08-21
298
stars
14
forks
3
watchers
28
prs
24
issues
13
releases
1
discussions

README

Zedis




A Redis-compatible in-memory data store written in Zig, designed for learning and experimentation. Zedis implements the core Redis protocol and data structures with a focus on simplicity, performance, and thread safety.

 Features

- Redis Protocol Compatibility: Supports the Redis Serialization Protocol (RESP),
  including pipelined commands.
- Multiple Data Types: Strings and integers, lists, time series, and Bloom filters.
- Core Commands: Key management (DEL, EXISTS, TYPE, TTL, EXPIRE, KEYS),
  strings, lists (LPUSH/RPUSH/LRANGE, ...), and RANDOMKEY.
- High Performance: Written in Zig, with a single-executor command path and no
  global store lock.
- Key Expiration: Lazy TTL expiry on access, plus expiry checks during eviction.
- Disk persistence (RDB): Point-in-time snapshots of your dataset.
- Append-only file (AOF): Durable write-ahead logging with group commit.
- Memory Budgeting: Redis-compatible maxmemory with eviction, -OOM rejection
  for allocating commands, and cgroup-aware auto-sizing inside containers.
- Pub/Sub: Decoupled communication between services, with push delivery to idle
  subscribers.
- TLS: Optional TLS 1.2/1.3 listener (OpenSSL) with certificate/key/CA
  configuration and optional mutual TLS via tls-auth-clients.
- Observability: Real INFO counters (connections, ops/sec, hit rate,
  memory, AOF state), SLOWLOG, LATENCY, and a METRICS command exposing
  Prometheus text exposition.
- Graceful shutdown: SIGINT/SIGTERM and SHUTDOWN [NOSAVE|SAVE] stop
  accepting, drain clients, flush the AOF, and close the listeners. CONFIG
  REWRITE persists runtime changes.
- Time Series: Time series data structure. Now with Gorilla compression!
- Opinionated Design: No multiple logical databases, expiry is lazy only.

 Caveats

- Zedis is intentionally single-store. It does not support multiple logical databases and does not expose Redis SELECT. It adds complexity and segment memory. This follows the reasoning Salvatore Sanfilippo gave when he called Redis multiple databases one of his worst design decisions.


 Quick Start

Download the binary from the releases page or build from source to get started with Zedis.

 Prerequisites

- Zig 0.17.1 (pinned in build.zig.zon)

 Building and Running

bash
 Clone the repository
git clone https://github.com/barddoo/zedis.git
cd zedis

 Build the project (optimized, ReleaseFast)
zig build --release=fast

 Run the server
zig build run --release=fast


The server will start on 127.0.0.1:6379 by default.

 Testing with Redis CLI

You can test Zedis using the standard redis-cli or any Redis client:

bash
 Connect to Zedis
redis-cli -h 127.0.0.1 -p 6379

 Try some commands
127.0.0.1:6379 SET mykey "Hello, Zedis!"
OK
127.0.0.1:6379 GET mykey
"Hello, Zedis!"
127.0.0.1:6379 INCR counter
(integer) 1
127.0.0.1:6379 TYPE mykey
string


 TLS

Enable the TLS listener in the config file (see zedis.conf for all options):

conf
port 0                  optional: serve TLS only
tls-port 6380
tls-cert-fil

Top issues

Discussions

Latest release

v0.2.2 v0.2.2 2026-11-10
Added

- AOF rewrite on a background thread: BGREWRITEAOF and automatic rewrites (auto-aof-rewrite-percentage, auto-aof-rewrite-min-size) replace the AOF with a snapshot of the live dataset, so it no longer grows without bound, and the server keeps serving while it runs. The store has no locks, so the rewrite thread never touches it: it replays the existing AOF into a private store (what a restart would load), writes strings (with TTLs), lists and time series as commands to a temp file, copies the log written meanwhile, and the writer thread splices on the last bytes, fsyncs, and atomically re

Snapshot: 2026-11-11T15:31:17Z · Data license Apache-2.0 · JSON