ToonStore - Blazingly fast embedded database with Redis-compatible protocol
939
β οΈ NOT PRODUCTION READY - v0.1 Alpha β οΈ
A blazingly fast embedded database with Redis-compatible protocol, built in Rust.
ToonStore is a high-performance key-value store that gives you the speed of embedded databases (5.28M ops/sec) with the convenience of Redis compatibility. Use it as an embedded library for maximum performance, or run it as a Redis-compatible server accessible from any language.
TOON (Token-Oriented Object Notation) is a compact, human-readable data format specifically designed for the age of AI and LLMs. In a world where every token countsβboth for cost and context window limitsβTOON provides 40-60% token savings compared to JSON while maintaining higher LLM comprehension accuracy.
[N] lengths and {fields} headers help LLMs parse data reliablyJSON (22,250 tokens):
{
"metrics": [
{"date": "2025-01-01", "views": 5715, "clicks": 211, "conversions": 28, "revenue": 7976.46},
{"date": "2025-01-02", "views": 7103, "clicks": 393, "conversions": 28, "revenue": 8360.53}
]
}
TOON (9,120 tokens - 59% reduction):
metrics[2]{date,views,clicks,conversions,revenue}:
2025-01-01,5715,211,28,7976.46
2025-01-02,7103,393,28,8360.53
ToonStore uses the TOON format for efficient data storage. To learn more about the format specification:
ToonStore is a persistent key-value database that combines the token-efficient TOON format with extreme performance:
ToonStore combines the best of all worlds with TOON format storage:
| Feature | ToonStore | Redis | PostgreSQL | RocksDB |
|---|---|---|---|---|
| Speed | 5.28M ops/sec (embedded) | ~80k ops/sec | ~65k ops/sec | ~100k ops/sec |
| Persistent | β Yes | β Optional | β Yes | β Yes |
| Token-Efficient Format | β TOON (~40% savings) | β Binary | β Binary | β Binary |
| Redis Protocol | β Yes | β Yes | β No | β No |
| Embedded Mode | β Yes | β No | β No | β Yes |
| Network Mode | β Yes | β Yes | β Yes | β No |
| Multi-language | β Yes | β Yes | β Yes | β οΈ Limited |
GET, SET, DEL, EXISTS, KEYSNetwork Mode:
// Connect from Node.js, Python, Go, etc.
const redis = require('redis');
const client = redis.createClient({ url: 'redis://localhost:6379' });
await client.set('key', 'value');
Embedded Mode:
// Direct Rust integration (66x faster!)
let cache = ToonCache::new("./data", 10000)?;
let id = cache.put(b"data")?;
let data = cache.get(id)?;
ToonStore saves all data persistently on disk using the efficient TOON format:
Data is stored in TOON (Token-Oriented Object Notation) format, which provides:
By default, ToonStore saves data to:
./data/ # Data directory
βββ toon.db # Main database file (TOON format)
βββ index.db # Index mappings
When you save this data:
{
"id": "user:1",
"name": "John Doe",
"email": "[email protected]",
"age": 30
}
ToonStore converts and stores it in TOON format:
user:1{id,name,email,age}:
user:1,John Doe,[email protected],30
This format is:
ToonStore provides:
Automatic Persistence
SET operation writes to diskMemory-Mapped I/O
Built-in LRU Cache
# Specify data directory
tstd --data /path/to/data
# Configure cache size
tstd --capacity 50000
# View stored data files
ls -lh ./data/
# Check database size
redis-cli DBSIZE
# Get server info
redis-cli INFO
In the age of AI and LLMs, the TOON format provides significant advantages:
Learn more about TOON: TOON Format Repositoryβ
ToonStore is designed for speed:
| Operation | ToonStore (Embedded) | ToonStore (Network) | Redis | PostgreSQL |
|---|---|---|---|---|
| GET (cached) | 5.28M ops/sec | ~80k ops/sec | ~80k ops/sec | ~65k ops/sec |
| GET (storage) | 215k ops/sec | ~70k ops/sec | ~65k ops/sec | ~65k ops/sec |
| SET | 82k ops/sec | ~60k ops/sec | ~60k ops/sec | ~55k ops/sec |
| DELETE | 32M ops/sec | ~100k ops/sec | ~100k ops/sec | ~70k ops/sec |
Key Insight: Embedded mode is 66x faster than network mode (no TCP overhead)
See BENCHMARKS.mdβ for detailed benchmarks and methodology.
# Pull from Docker Hub
docker pull samso9th/toonstore:latest
# Or pull from GitHub Container Registry
docker pull ghcr.io/kalama-tech/toonstoredb:latest
# Run ToonStore
docker run -d \
--name toonstore \
-p 6379:6379 \
-v toonstore_data:/data \
samso9th/toonstore:latest
# Test connection
redis-cli -h 127.0.0.1 -p 6379 PING
# Output: PONG
# Use it
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> SET mykey "Hello World"
OK
127.0.0.1:6379> GET mykey
"Hello World"
With Docker Compose:
# Download docker-compose.yml
curl -O https://raw.githubusercontent.com/Kalama-Tech/toonstoredb/main/docker-compose.yml
# Start
docker-compose up -d
# Stop
docker-compose down
# Linux/macOS
curl -L https://github.com/Kalama-Tech/toonstoredb/releases/latest/download/tstd -o tstd
chmod +x tstd
./tstd --bind 0.0.0.0:6379
# Windows
# Download from: https://github.com/Kalama-Tech/toonstoredb/releases
# Clone repository
git clone https://github.com/Kalama-Tech/toonstoredb.git
cd toonstoredb
# Build (requires Rust 1.70+)
cargo build --release
# Run
./target/release/tstd --bind 0.0.0.0:6379
# Cargo.toml
[dependencies]
tooncache = { git = "https://github.com/Kalama-Tech/toonstoredb" }
use tooncache::ToonCache;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open database
let cache = ToonCache::new("./data", 10000)?;
// Store data
let id = cache.put(b"Hello, World!")?;
// Retrieve data
let data = cache.get(id)?;
println!("Retrieved: {:?}", String::from_utf8(data)?);
Ok(())
}
ToonStore is Redis-compatible, so you can use any Redis client library:
const redis = require('redis');
const client = redis.createClient({ url: 'toonstore://localhost:6379' });
await client.connect();
await client.set('user:1', 'John Doe');
const user = await client.get('user:1');
console.log(user); // "John Doe"
Note: ToonStore uses
toonstore://as its connection string prefix for branding, but it's fully Redis-compatible soredis://also works with any Redis client library.
import redis
client = redis.from_url('toonstore://localhost:6379')
client.set('user:1', 'John Doe')
user = client.get('user:1')
print(user) # b'John Doe'
import "github.com/redis/go-redis/v9"
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
client.Set(ctx, "user:1", "John Doe", 0)
user, _ := client.Get(ctx, "user:1").Result()
fmt.Println(user) // "John Doe"
See docs/connecting-from-apps.mdβ for more examples.
PING, ECHO - Connection testing
GET, SET, DEL - Core operations
EXISTS, KEYS - Key inspection
DBSIZE, FLUSHDB - Database management
INFO - Server statistics
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Application β
βββββββββββββββββββ¬βββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β β
Network Mode (tstd) Embedded Mode (library)
redis://host:port ToonCache::new()
~70k ops/sec 5.28M ops/sec
β β
ββββββββββββ¬ββββββββββββ
β
ββββββββββββββββββββββββββββββββββββ
β tooncache (LRU Cache) β
β - 5.28M ops/sec (cached reads) β
β - Configurable capacity β
ββββββββββββββββ¬ββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββββββ
β toonstoredb (Storage Engine) β
β - 215k ops/sec (storage reads) β
β - TOON format parser β
β - Memory-mapped files β
ββββββββββββββββββββββββββββββββββββ
# Clone repository
git clone https://github.com/Kalama-Tech/toonstoredb
cd toonstoredb
# Build release
cargo build --release
# Run server
./target/release/tstd --bind 0.0.0.0:6379
# Install server binary
cargo install tstd
# Add to your Rust project
cargo add tooncache
# Pull image
docker pull ghcr.io/yourusername/toonstore:latest
# Run server
docker run -d \
-p 6379:6379 \
-v $(pwd)/data:/data \
ghcr.io/yourusername/toonstore:latest
See DOCKER_SETUP_GUIDE.mdβ for complete Docker setup.
Python
import redis
client = redis.from_url('toonstore://localhost:6379')
client.set('key', 'value')
Node.js
const Redis = require('ioredis');
const client = new Redis('toonstore://localhost:6379');
await client.set('key', 'value');
Go
import "github.com/redis/go-redis/v9"
client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
client.Set(ctx, "key", "value", 0)
Rust
use tooncache::ToonCache;
let cache = ToonCache::new("./data", 10000)?;
Python (Coming Week 4)
import toonstore
db = toonstore.ToonCache("./data", capacity=10000)
tstd \
--bind 0.0.0.0:6379 \ # Bind address
--data ./data \ # Data directory
--capacity 10000 # Cache capacity
RUST_LOG=info # Logging level (info, debug, trace)
let cache = ToonCache::new(
"./data", // Data directory
10000 // Cache capacity
)?;
# Connect with redis-cli
redis-cli -h 127.0.0.1 -p 6379
# Get statistics
127.0.0.1:6379> INFO
# Server
toonstore_version:0.1.0
# Stats
total_keys:1000
cache_size:850
cache_capacity:10000
cache_hits:95000
cache_misses:5000
cache_hit_ratio:0.95
# Check database size
127.0.0.1:6379> DBSIZE
(integer) 1000
# Docker health check
tstd --health
# Or via TCP
redis-cli PING
PONG
# Check if port is already in use
netstat -an | grep 6379
# Try different port
tstd --bind 127.0.0.1:6380
# Check server is running
ps aux | grep tstd
# Check firewall
sudo ufw allow 6379/tcp
# Increase cache capacity
tstd --capacity 50000
# Check cache hit ratio
redis-cli INFO | grep cache_hit_ratio
# Use embedded mode for maximum performance
See docs/troubleshooting.mdβ for more solutions.
ToonStore is in active development. We welcome contributions!
# Clone
git clone https://github.com/Kalama-Tech/toonstoredb
cd toonstoredb
# Build
cargo build
# Run tests
cargo test
# Run benchmarks
cargo bench
cargo fmt and cargo clippySee CONTRIBUTING.mdβ for details.
ToonStore is licensed under the MIT Licenseβ .
Built with β€οΈ in Rust | Performance: 5.28M ops/sec | License: MIT
Content type
Image
Digest
sha256:7b71699d7β¦
Size
31.6 MB
Last updated
10 months ago
docker pull samso9th/toonstore