my_redis_server is a lightweight, Redis-compatible, in-memory data store written in C++.
It supports strings, lists, and hashes, full RESP protocol parsing, multi-client concurrency, and periodic disk persistence.
- Common Commands:
PING,ECHO,FLUSHALL - Key/Value:
SET,GET,KEYS,TYPE,DEL,EXPIRE,RENAME - Lists:
LGET,LLEN,LPUSH,RPUSH,LPOP,RPOP,LREM,LINDEX,LSET - Hashes:
HSET,HGET,HEXISTS,HDEL,HKEYS,HVALS,HLEN,HGETALL,HMSET - Persistence: Data is dumped to
dump.my_rdbevery 5 minutes and on shutdown; loaded at startup if present. - Concurrency: Handles multiple clients using threads.
- RESP Protocol: Fully parses both inline and array formats.
├── include/ # Header files
│ ├── RedisCommandHandler.h
│ ├── RedisDatabase.h
│ └── RedisServer.h
├── src/ # Source files
│ ├── RedisCommandHandler.cpp
│ ├── RedisDatabase.cpp
│ ├── RedisServer.cpp
│ └── main.cpp
├── Concepts,UseCases&Tests.md # Design and test documentation
├── Makefile # Build script
├── README.md # This file
└── test_all.sh # Automated test script
You need a C++17 (or later) compiler.
Build with Make:
makeClean build artifacts:
make cleanManual compilation:
g++ -std=c++17 -pthread -Iinclude src/*.cpp -o my_redis_server./my_redis_server # Default port 6379
./my_redis_server 6380 # Custom portOn startup, you’ll see:
Database Loaded From dump.my_rdb
# or
No dump found or load failed; starting with an empty database.
The server saves the database every 5 minutes and on shutdown (Ctrl+C).
You can use the standard redis-cli or your own RESP client.
redis-cli -p 6379Example session:
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> SET bob "pawan kalyan"
OK
127.0.0.1:6379> GET bob
"pawan kalyan"
PING→PONGECHO <msg>→<msg>FLUSHALL→ clear all data
SET <key> <value>GET <key>KEYS *TYPE <key>DEL <key>EXPIRE <key> <seconds>RENAME <old> <new>
LGET <key>— get all elementsLLEN <key>LPUSH <key> <v1> [v2 ...]RPUSH <key> <v1> [v2 ...]LPOP <key>RPOP <key>LREM <key> <count> <value>LINDEX <key> <index>LSET <key> <index> <value>
HSET <key> <field> <value>HGET <key> <field>HEXISTS <key> <field>HDEL <key> <field>HLEN <key>HKEYS <key>HVALS <key>HGETALL <key>HMSET <key> <f1> <v1> [f2 v2 ...]
- Concurrency: Each client handled in a separate thread.
- Synchronization: Single mutex guards all data structures.
- Data Stores:
kv_storefor stringslist_storefor listshash_storefor hashes
- Expiration: Lazy eviction on access, with TTL map.
- Persistence: Simple text-based RDB dump/load (
dump.my_rdb). - Singleton Pattern: One shared database instance.
- RESP Parsing: Custom parser for both inline and array formats.
- Use
test_all.shto run a suite of commands for validation:./test_all.sh
- See
Concepts,UseCases&Tests.mdfor more examples and test cases.