A lightweight, in-memory Redis-clone key-value storage written in Go. Supports atomic operations, TTLs, and concurrency-safe access.
Requirements:
- Go >= 1.25.1
Run:
go run ./cmd/server/-
Core Commands
SET– store a key/value with optional NX/XX and TTL (EX/PX)GET– retrieve a key, respecting TTLDEL– delete a keyEXPIRE– set TTL in seconds with optional NX/XXTTL– get remaining TTL in secondsPTTL– get remaining TTL in millisecondsPERSIST– remove TTL from a keyINCR– atomically increment an integer valueDECR– atomically decrement an integer valueINCRBY– atomically increment an integer value by a given amountDECRBY– atomically decrements an integer value by a given amountPING– server liveness check
-
TTL Handling
- Supports EX (seconds) and PX (milliseconds)
- Immediate deletion when TTL ≤ 0
- Background janitor cleans expired keys
- Lazy expiration ensures all commands see correct state
-
Concurrency Safe
- All operations protected by a mutex
- Atomic reads and writes
-
RESP Protocol Ready
- Designed to integrate with RESP handlers for network communication
[!NOTE] It does not use bufio.Reader for parsing. Custom parser has been implemented to prevent memory exhaustion attacks, and for better robustness.
-
TODOs:
-
Having a better logger
-
Seperate package for the Server
-
New Data Types: Sets, Hashes, and JŚON.
-
Sharding