hero_redis/lib.rs
1//! # Hero Redis
2//!
3//! High-performance Redis-compatible server on redb with vector database support.
4//!
5//! ## Highlights
6//!
7//! - **Redis Protocol Compatible** - Works with any Redis client
8//! - **Dual Authentication** - Ed25519 signatures or simple secrets
9//! - **Vector Search** - HNSW-based similarity search for AI embeddings
10//! - **Encrypted Storage** - ChaCha20-Poly1305 encryption at rest
11//! - **Multi-Database** - Up to 1000 databases with per-database ACL
12//! - **Rhai Scripting** - Embedded scripting for complex operations
13//!
14//! ## Features
15//!
16//! This crate supports feature flags to control which components are compiled:
17//!
18//! | Feature | Description | Default |
19//! |----------|-------------|---------|
20//! | `client` | Redis client with Ed25519 authentication | Yes |
21//! | `server` | Redis-compatible server with redb backend | No |
22//! | `rhai` | Rhai scripting support for the client | No |
23//! | `vector` | Vector database with HNSW similarity search | No |
24//! | `full` | All features enabled | No |
25//!
26//! ## Quick Start - Client Only (Default)
27//!
28//! ```toml
29//! [dependencies]
30//! hero_redis = "0.3"
31//! ```
32//!
33//! ```rust,ignore
34//! use hero_redis::hero_redis_client::{HeroRedisClient, Permission};
35//!
36//! // Connect with private key (Ed25519)
37//! let mut client = HeroRedisClient::new("127.0.0.1", 6666, "your_private_key_hex")?;
38//!
39//! // Select database
40//! client.select(1)?;
41//!
42//! // Simple key-value operations
43//! client.set("name", "Alice")?;
44//! let name = client.get("name")?.unwrap();
45//!
46//! // Hashes
47//! client.hset("user:1", "name", "Bob")?;
48//! let user = client.hgetall("user:1")?;
49//!
50//! // Lists
51//! client.rpush("queue", "job1")?;
52//! let job = client.lpop("queue")?;
53//!
54//! // Admin operations (requires admin privileges)
55//! let db = client.admin().create_database("encryption_key")?;
56//! client.admin().grant_permission(db, &pubkey, Permission::Write)?;
57//! ```
58//!
59//! ## Vector Search
60//!
61//! ```rust,ignore
62//! // Create a vector index
63//! client.vector_create("embeddings", 1536, "cosine", None)?;
64//!
65//! // Add vectors (supports bulk insert for performance)
66//! client.vector_add("embeddings", 1, &embedding_vec)?;
67//! client.vector_add_batch("embeddings", 1536, &batch_items)?;
68//!
69//! // Build index and search
70//! client.vector_build("embeddings")?;
71//! let results = client.vector_search("embeddings", &query_vec, 10)?;
72//! ```
73//!
74//! ## Client with Rhai Scripting
75//!
76//! ```toml
77//! [dependencies]
78//! hero_redis = { version = "0.3", features = ["rhai"] }
79//! ```
80//!
81//! ```rust,ignore
82//! use hero_redis::hero_redis_rhai::RhaiScriptRunner;
83//!
84//! let runner = RhaiScriptRunner::builder()
85//! .host("127.0.0.1")
86//! .port(6666)
87//! .private_key("your_private_key_hex")
88//! .build()?;
89//!
90//! runner.run_script("scripts/my_script.rhai")?;
91//! ```
92//!
93//! ## Server Only
94//!
95//! ```toml
96//! [dependencies]
97//! hero_redis = { version = "0.3", default-features = false, features = ["server"] }
98//! ```
99//!
100//! ## Full Build (Everything)
101//!
102//! ```toml
103//! [dependencies]
104//! hero_redis = { version = "0.3", features = ["full"] }
105//! ```
106//!
107//! ## Repository
108//!
109//! Source code and issues: <https://forge.ourworld.tf/geomind_code/hero_redis>
110
111// =============================================================================
112// Server Module (requires "server" feature)
113// =============================================================================
114#[cfg(feature = "server")]
115pub mod hero_redis_server;
116
117#[cfg(feature = "server")]
118pub use hero_redis_server::auth::{
119 Permission as ServerPermission, SessionContext, validate_pubkey, verify_signature,
120};
121
122#[cfg(feature = "server")]
123pub use hero_redis_server::protocol::{RespParser, RespValue};
124
125// =============================================================================
126// Login Module (requires "client" feature)
127// =============================================================================
128/// Hero Redis Login client module for obtaining auth tokens
129#[cfg(feature = "client")]
130pub mod hero_redis_login;
131
132// =============================================================================
133// Client Module (requires "client" feature)
134// =============================================================================
135/// Hero Redis Client - full-featured client with authentication
136#[cfg(feature = "client")]
137pub mod hero_redis_client;
138
139// =============================================================================
140// Rhai Module (requires "rhai" feature)
141// =============================================================================
142/// Hero Redis Rhai - Rhai scripting support for the client
143#[cfg(feature = "rhai")]
144pub mod hero_redis_rhai;
145
146// =============================================================================
147// Vector Module (requires "vector" feature)
148// =============================================================================
149/// Vector database module - HNSW-based vector similarity search
150#[cfg(feature = "vector")]
151pub mod vector;