Fast, Safe, and Intelligent. The next-generation in-memory data store.
SpinelDB is a high-performance, in-memory database server built from the ground up in Rust. It offers a Redis-compatible API while introducing powerful, modern features designed to solve common, real-world application challenges right out of the box.
Designed for today's architectures, SpinelDB is more than just a key-value store. It's a robust platform featuring an Intelligent Caching Engine with advanced strategies like SWR, grace periods, on-disk streaming, and cluster-aware tag-based invalidation; a Security-First design for authenticated cluster communications; and Native JSON Support, all while leveraging Rust's guarantees of memory safety and fearless concurrency.
SpinelDB combines the beloved simplicity and speed of Redis with the next-generation features and reliability that modern systems demand.
π§ Intelligent Caching Engine
A built-in, HTTP-aware caching engine. It natively supports Stale-While-Revalidate (SWR), grace periods, Vary header content negotiation, efficient tag-based invalidation (CACHE.PURGETAG) across a cluster, conditional revalidation (IF-NONE-MATCH, IF-MODIFIED-SINCE), forced revalidation (FORCE-REVALIDATE), negative caching, and explicit on-disk storage (FORCE-DISK). It also allows storing and retrieving HTTP headers (HEADERS option) with cached content. Offload complex caching logic from your application directly to the database.
π‘οΈ Security-First by Design Cluster communications are authenticated with HMAC-SHA256 to prevent spoofing. User authentication is powered by a modern, rule-based Access Control List (ACL) system with strong Argon2 password hashing.
π Native JSON Support
A first-class JSON data type. Atomically manipulate deeply nested JSON documents on the server with a rich command set (JSON.GET, JSON.SET, JSON.NUMINCRBY, JSON.ARRAPPEND, etc.) without needing external modules.
βοΈ Powerful Lua Scripting
Embed complex business logic directly into the database with a sandboxed, high-performance Lua scripting engine (EVAL, EVALSHA). Reduce network round-trips by moving logic to the data.
π True Multithreading Internally sharded from the core, SpinelDB leverages modern multi-core CPUs for true parallel command execution. This drastically reduces lock contention and boosts throughput for multi-key operations.
π Unparalleled Reliability Built in Rust, eliminating entire classes of memory safety bugs, null pointer dereferences, and data races. It features robust fail-safes, like automatically entering read-only mode on critical persistence errors to protect your data.
π Seamless Compatibility Drop-in ready. Use your existing Redis clients and libraries in any language without modification. SpinelDB speaks RESP2/RESP3.
ποΈ Advanced Optimistic Locking
WATCH/EXEC and complex commands like SORT use an advanced optimistic versioning system. This maximizes concurrency by avoiding long-held locks, even during complex, multi-key operations.
"Stop building boilerplate caching and data consistency logic in your application. SpinelDB provides intelligent primitives that let you focus on features, not plumbing. It's the performance of Redis with the safety of Rust and the features you wish you always had."
-
Intelligent Caching Engine:
CACHE.PROXY: The ultimate get-or-fetch command with declarative policy support.CACHE.SET/GET: Fine-grained control with TTL, Stale-While-Revalidate (SWR), Grace Periods, conditional revalidation (IF-NONE-MATCH,IF-MODIFIED-SINCE), negative caching, explicit on-disk storage (FORCE-DISK), and the ability to store and retrieve HTTP headers (HEADERSoption).CACHE.PURGETAG: Blazingly fast, tag-based invalidation of multiple keys in a single atomic operation.VaryHeader Support: Serve different versions of the same resource based on request headers (e.g.,Accept-Language).- On-Disk Streaming: Automatically streams large cache objects to disk to protect memory, with zero performance impact for the client.
-
Rich Data Structures: Strings, Lists, Hashes, Sets, Sorted Sets, Native JSON, Streams, Bloom Filters, and HyperLogLogs.
-
Server-Side Lua Scripting:
EVAL&EVALSHA: Full compatibility with Redis scripting commands.- Rich API: Execute SpinelDB commands from within scripts using
spineldb.call(...)andspineldb.pcall(...). - Safe Execution: Scripts run in a sandboxed environment with a configurable timeout to prevent long-running scripts from blocking the server.
- Persistence: Scripts executed via
EVALSHAare automatically persisted to the AOF with their full body, ensuring correct replay during recovery or replication.
Note on Atomicity: Unlike Redis, where scripts are fully atomic, SpinelDB's
spineldb.callexecutes each command with its own set of locks. This design allows for more flexible, long-running logic without holding a global lock. For atomic multi-key operations across multiple commands, useWATCH/MULTI/EXECfrom your client. -
Robust Persistence:
- AOF (Append-Only File):
fsyncpolicies (always,everysec,no), and a non-blocking, background rewrite process to keep the file compact (buffering writes during rewrite). - SPLDB (Snapshotting): Point-in-time snapshots with configurable save policies (
save <seconds> <changes>), including checksums and atomic writes. - Atomic & Safe: All file writes use a temporary file and atomic rename to prevent data corruption on crash.
- AOF (Append-Only File):
-
High Availability:
- Replication: Classic Primary-Replica model with full (SPLDB) and partial (backlog) resynchronization.
- Clustering: Horizontally scale your data with a Redis Cluster compatible protocol, including gossip-based discovery and self-fencing masters to prevent split-brain.
- Warden: A dedicated, Sentinel-compatible monitoring and automatic failover system (
--wardenmode) for maximum reliability.
-
Advanced Security:
- A modern, rule-based Access Control List (ACL) system with strong Argon2 password hashing.
- Secure, HMAC-SHA256 authenticated cluster bus to protect against unauthorized nodes.
-
Deep Introspection:
INFO,SLOWLOG, andLATENCYcommands for powerful monitoring and performance diagnostics. -
Production Safety: Built-in circuit breakers to prevent dangerous commands (like
KEYS *orSMEMBERSon huge sets) from impacting performance.
- Rust toolchain (latest stable version recommended)
- A C compiler toolchain (
build-essentialon Debian/Ubuntu,Xcode Command Line Toolson macOS) pkg-configand OpenSSL development libraries (libssl-devon Debian/Ubuntu,opensslvia Homebrew on macOS)
git clone https://github.com/spineldb/spineldb.git
cd spineldb
cargo build --releaseThe compiled binary will be at target/release/spineldb.
For a quick setup, you can use our installation script:
# Using curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/spineldb/spineldb/main/install.sh)"
# Using wget
sh -c "$(wget -qO- https://raw.githubusercontent.com/spineldb/spineldb/main/install.sh)"You can run SpinelDB using our official Docker image or by building it from source.
# Pull the latest image from Docker Hub
docker pull spineldb/spineldb:latest
# Run the container
docker run -d -p 7878:7878 --name spineldb_instance spineldb/spineldb:latestIf you prefer to build the image yourself, you can use the provided Dockerfile.
# Build the Docker image from the repository root
docker build -t spineldb/spineldb:latest .
# Run the container using the locally built image
docker run -d -p 7878:7878 --name spineldb_instance spineldb/spineldb:latestNote on Docker Networking: For the server to be accessible from outside the container, the
hostin yourconfig.tomlmust be set to0.0.0.0. The providedDockerfilehandles this automatically. If you are using a custom configuration, ensure this setting is correct.
For a more declarative approach, you can use the provided docker-compose.yml file.
# Start the service in the background
docker-compose up -d
# Stop and remove the container
docker-compose down- Configuration: A default
config.tomlis provided. Customize it to fit your needs, especiallyhostandport. - Start the Server:
./target/release/spineldb [--port <port>]
- Connect with any Redis Client:
redis-cli -p 7878 127.0.0.1:7878> PING PONG 127.0.0.1:7878> JSON.SET user:1 . '{"name": "Alice", "age": 30, "projects": ["SpinelDB"]}' OK 127.0.0.1:7878> JSON.ARRAPPEND user:1 .projects '"Rust"' (integer) 2 127.0.0.1:7878> JSON.GET user:1 "{\"age\":30,\"name\":\"Alice\",\"projects\":[\"SpinelDB\",\"Rust\"]}" 127.0.0.1:7878> CACHE.SET mypage:home "<html>Home Page</html>" TTL 60 SWR 300 REVALIDATE-URL "https://example.com/home" OK 127.0.0.1:7878> CACHE.GET mypage:home "<html>Home Page</html>"
- Configuration: Create a
warden.tomlfile to define the masters to monitor (seewarden.example.toml). - Start the Warden:
./target/release/spineldb --warden /path/to/warden.toml
SpinelDB is engineered from the ground up for modern hardware and robust, concurrent operation.
- Async Core: Built entirely on the Tokio async runtime for massively concurrent, non-blocking I/O.
- Internally Sharded & Lock-Efficient: Each database is internally sharded into concurrent segments. Commands acquire locks only on the necessary shards, drastically reducing contention and enabling true parallelism for multi-key operations on multi-core systems.
- Decoupled Event Bus: A central, non-blocking event bus propagates write commands to persistence (AOF) and replication subsystems. This decouples core command processing from disk I/O, ensuring high throughput even when persistence is slow.
- Memory-Safe by Design: Leverages Rust's ownership model and type system to prevent entire classes of bugs like buffer overflows, use-after-frees, and data races that plague systems written in C/C++.
SpinelDB is actively developed. Our current focus is on hardening the core and expanding our unique features.
- Rigorous Testing: Expand performance and chaos testing suites to validate clustering and failover under adverse conditions.
- Comprehensive Benchmarking: Publish detailed benchmarks against Redis and other alternatives, highlighting caching and multi-core performance.
We are thrilled you're interested in contributing to SpinelDB! Whether it's reporting a bug, proposing a new feature, or writing code, your help is welcome.
Please read our CONTRIBUTING.md (coming soon!) to learn how you can get started.
SpinelDB is distributed under the terms of the MIT License.
See LICENSE for details.
