
A fast, lightweight in-memory key-value store written in Go with persistence, TTL support, and AI-powered analytics.
- High Performance: Sub-microsecond GET operations, ~45M ops/sec
- Persistence: Write-Ahead Log (WAL) with crash recovery
- TTL Support: Per-key expiration with lazy and background cleanup
- Snapshots: Point-in-time snapshots for efficient compaction
- Analytics: Track access patterns, detect hot keys, suggest TTLs
- Redis-like Protocol: Familiar command syntax over TCP
- Zero Dependencies: Pure Go standard library
# Build
make build
# Run server
./bin/kvlite
# Connect with netcat or telnet
nc localhost 6380
+OK kvlite ready
SET greeting "Hello, World!"
+OK
GET greeting
Hello, World!
git clone https://github.com/lofoneh/kvlite.git
cd kvlite
make build
docker build -t kvlite .
docker run -p 6380:6380 kvlite
| Command |
Description |
Example |
SET key value |
Store a value |
SET name Alice |
GET key |
Retrieve a value |
GET name |
DELETE key |
Remove a key |
DELETE name |
EXISTS key |
Check if key exists |
EXISTS name |
KEYS pattern |
List keys matching pattern |
KEYS user:* |
| Command |
Description |
Example |
SETEX key seconds value |
Set with expiration |
SETEX session 3600 data |
EXPIRE key seconds |
Set TTL on existing key |
EXPIRE name 60 |
TTL key |
Get remaining TTL |
TTL session |
PERSIST key |
Remove TTL |
PERSIST session |
| Command |
Description |
Example |
MSET k1 v1 k2 v2 |
Set multiple keys |
MSET a 1 b 2 c 3 |
MGET k1 k2 k3 |
Get multiple keys |
MGET a b c |
MDEL k1 k2 k3 |
Delete multiple keys |
MDEL a b c |
| Command |
Description |
Example |
INCR key |
Increment by 1 |
INCR counter |
DECR key |
Decrement by 1 |
DECR counter |
| Command |
Description |
Example |
APPEND key value |
Append to string |
APPEND msg " world" |
STRLEN key |
Get string length |
STRLEN msg |
| Command |
Description |
PING |
Health check (returns PONG) |
INFO |
Server information |
STATS |
Detailed statistics |
HEALTH |
Health check (JSON) |
SYNC |
Force WAL flush |
COMPACT |
Force compaction |
CLEAR |
Delete all keys |
QUIT |
Close connection |
| Command |
Description |
Example |
ANALYZE key |
Get key statistics |
ANALYZE popular_key |
HOTKEYS n |
Get top N hot keys |
HOTKEYS 10 |
SUGGEST-TTL key |
Get TTL suggestion |
SUGGEST-TTL cache_key |
ANOMALIES |
Detect unusual patterns |
ANOMALIES |
./bin/kvlite \
--host 0.0.0.0 \
--port 6380 \
--max-connections 1000 \
--wal-path ./data \
--sync-mode \
--enable-analytics
| Variable |
Description |
Default |
KVLITE_HOST |
Bind address |
localhost |
KVLITE_PORT |
Listen port |
6380 |
KVLITE_MAX_CONNECTIONS |
Connection limit (0=unlimited) |
0 |
┌─────────────────────────────────────────────────────┐
│ TCP Server │
│ (pkg/api/) │
└─────────────────────┬───────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────┐
│ Engine │
│ (internal/engine/) │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌──────── ┐ │
│ │ Store │ │ WAL │ │Snapshot │ │Analytics│ │
│ └─────────┘ └─────────┘ └─────────┘ └──────── ┘ │
└─────────────────────────────────────────────────────┘
- Writes: Client → API → Engine → WAL → Store
- Reads: Client → API → Engine → Store (with lazy expiration)
- Recovery: Snapshot → WAL Replay → Store
See the examples/ directory for usage patterns:
# Run tests
make test
# Run tests with race detector
make test-race
# Run benchmarks
make bench
# Format code
make fmt
# Run linter
make lint
# Full check (fmt + vet + test)
make check
BenchmarkStore_Set-8 50000000 25.3 ns/op 0 B/op 0 allocs/op
BenchmarkStore_Get-8 100000000 10.2 ns/op 0 B/op 0 allocs/op
BenchmarkEngine_Set-8 500000 2145 ns/op 48 B/op 1 allocs/op
BenchmarkEngine_Get-8 50000000 28.4 ns/op 0 B/op 0 allocs/op
MIT License - see LICENSE for details.
Contributions welcome! Please read our:
Whether it's bug reports, feature requests, documentation improvements, or code contributions - we appreciate your help!