mini_redis is a Redis-inspired in-memory data store implemented in C++17 with a focus on clean modular design, thread safety, and operational tooling.
- TCP server with blocking socket I/O and a worker thread pool
- RESP parser and serializer for Redis-compatible command framing
- Command dispatcher with
PING,ECHO,SET,GET,DEL,EXISTS,EXPIRE,TTL,DBSIZE,INFO, andCONFIG GET - Thread-safe in-memory key-value store
- TTL support with lazy reads plus active expiration sweeps
- LRU eviction when
max_keysis reached - Config file support for runtime tuning
- Structured logging with severity filtering and optional file sink
- Unit tests and a benchmark executable similar to
redis-benchmark
flowchart LR
A["TCP Listener"] --> B["Thread Pool"]
B --> C["Client Session"]
C --> D["RESP Parser"]
D --> E["Command Dispatcher"]
E --> F["KeyValueStore"]
F --> G["LRU List"]
F --> H["TTL Metadata"]
E --> I["RESP Writer"]
I --> C
J["Config Loader"] --> A
J --> B
K["Logger"] --> A
K --> C
L["Expiration Thread"] --> F
M["Benchmark Tool"] --> A
include/mini_redis/: public interfaces for each modulesrc/: implementation of server, storage, protocol, logging, client, and config modulesbenchmark/: load generator similar toredis-benchmarktests/: unit test executable and lightweight test frameworkconfig/mini_redis.conf: sample production-style configuration
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure./build/mini_redis_server config/mini_redis.confThe server listens on 127.0.0.1:6379 by default.
./build/mini_redis_benchmark --host 127.0.0.1 --port 6379 --requests 100000 --clients 50 --pipeline 16 --command SET --data-size 64Supported benchmark commands are SET, GET, and PING.
Example knobs from config/mini_redis.conf:
bind_addressportworker_threadsmax_keyslisten_backlogsocket_read_bufferexpiration_check_interval_mslog_levellog_file
- The store is protected by a mutex because reads also update LRU state.
- Expiration is both lazy on key access and active via a periodic maintenance thread.
- Connection handling uses a bounded worker pool instead of per-request thread creation.
- The benchmark tool uses persistent connections and optional pipelining to measure throughput and latency.