Skip to content

cmunoz-g/mini-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mini-redis

Redis‑style data store focused on network programming, data structures, and low‑level systems code. It implements a TCP server and client and an in‑memory key/value engine (strings and sorted sets). It also includes a binary protocol, timers for key expiration, and a thread pool for background deletes.

Build and run

# Clone
git clone https://github.com/cmunoz-g/mini-redis.git
cd mini-redis

# Build
make

# Run server
./mini-redis <port>

# Run client
./mini-redis-client <port>

Usage

Supported commands:

  • set <key> <value>
  • get <key>
  • del <key>
  • keys
  • zadd <key> <score> <member>
  • zrem <key> <member>
  • zscore <key> <member>
  • zquery <key> <score> <name> <offset> <limit>
  • expire <key> <ttl_ms>
  • quit / exit

Implementation details

  • Server loop: builds pollfd set, computes timer deadline, accepts new connections, processes readable/writable sockets, applies expirations.
  • Connections: each Conn tracks readiness flags, in/out buffers, and idle/read/write timestamps. Buffers support append/consume.
  • Request path: handle_read assembles frames; handle_request parses length‑prefixed payloads, validates command/arity, dispatches do_request. Replies are serialized (response_begin/end).
  • Protocol: outer frame: 32‑bit big‑endian length. Payload: tag + type‑specific body (nil/str/int/dbl/arr/err/close).
  • Database: intrusive key storage via Entry nodes; strings stored inline, ZSET backed by an AVL tree.
  • TTL: Expirations are processed in the event loop.
  • Thread pool: workers block on a condition variable, pop tasks and execute. Used to background delete entries to speed up performance.

Notes

  • Protocol format is custom and not Redis RESP.
  • Command interface is intentionally minimal, building a full Redis command set is not the scope of this project.

About

Redis-style database coded in C+. Implements network programming to set up a TCP server, core data structures for storage and low-level systems code

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors