This guide covers how to use celerix-store as a Rust library and how to deploy it as a service using Docker or Podman.
The celerix-store SDK provides a unified interface for both embedded (local) and remote (TCP) storage.
Add celerix-store to your Cargo.toml. You can use the official crate (recommended) or a Git URL for specific versions:
Crates.io (Recommended):
[dependencies]
celerix-store = "0.1.0"Git Dependency:
[dependencies]
celerix-store = { git = "https://github.com/celerix-dev/celerix-store-rust.git", tag = "v0.1.0" }Local Path (For local development):
[dependencies]
celerix-store = { path = "../celerix-store-rust" }Use sdk::new(data_dir) to initialize the store. It automatically detects the CELERIX_STORE_ADDR environment variable to decide between Embedded and Remote modes.
use celerix_store::sdk;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Automatically switches to Remote mode if CELERIX_STORE_ADDR is set
let store = sdk::new("./data").await?;
// Standard CRUD
store.set("persona1", "app1", "key1", serde_json::json!("value1")).await?;
let val = store.get("persona1", "app1", "key1").await?;
println!("Value: {}", val);
Ok(())
}Scopes allow you to "pin" a persona and application ID for cleaner code.
let app = store.app("my-persona", "my-app");
app.set("settings", serde_json::json!({"theme": "dark"})).await?;
let settings = app.get("settings").await?;The VaultScope provides transparent client-side encryption using AES-256-GCM. Data is encrypted before being sent to the store or written to disk.
let master_key = b"thisis32byteslongsecretkey123456"; // Must be 32 bytes
let vault = app.vault(master_key);
// Encrypts and saves
vault.set("password", "top-secret-password").await?;
// Retrieves and decrypts
let pass = vault.get("password").await?;
println!("Decrypted: {}", pass);The Client implementation provides generic helpers for type-safe operations.
use celerix_store::sdk::Client;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct User { name: String }
let client = Client::connect("127.0.0.1:7001").await?;
client.set_generic("p1", "a1", "u1", User { name: "Alice".into() }).await?;
let user: User = client.get_generic("p1", "a1", "u1").await?;The celerix-stored daemon can be containerized for easy deployment.
| Variable | Description | Default |
|---|---|---|
CELERIX_PORT |
Port for the TCP server | 7001 |
CELERIX_DATA_DIR |
Directory for JSON persistence | ./data |
CELERIX_DISABLE_TLS |
Must be set to true (TLS not yet supported in Rust version) |
true |
# Use the official Rust image to build the binary
FROM rust:1.75-slim as builder
WORKDIR /usr/src/celerix-store
COPY . .
RUN cargo build --release --bin celerix-stored
# Final stage
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y libssl-dev ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /usr/src/celerix-store/target/release/celerix-stored /usr/local/bin/celerix-stored
# Create data directory
RUN mkdir -p /app/data
EXPOSE 7001
ENV CELERIX_DATA_DIR=/app/data
ENV CELERIX_PORT=7001
ENV CELERIX_DISABLE_TLS=true
CMD ["celerix-stored"]version: '3.8'
services:
celerix-store:
build: .
ports:
- "7001:7001"
volumes:
- ./store-data:/app/data
environment:
- CELERIX_PORT=7001
- CELERIX_DATA_DIR=/app/data
- CELERIX_DISABLE_TLS=true
restart: alwaysPodman usage is identical to Docker. You can build and run using the same files:
podman build -t celerix-store .
podman run -d --name celerix-store -p 7001:7001 -v ./data:/app/data:Z celerix-storeIf you decide to publish celerix-store to the official Rust package registry, follow these steps:
Ensure Cargo.toml contains the following fields (already added in the latest version):
description: A short summary of the crate.license: An SPDX identifier (e.g.,MIT OR Apache-2.0).repository: URL to your source code.readme: Path to your README file.
Rust uses triple-slash /// comments for documentation. You can preview how your documentation will look on docs.rs by running:
cargo doc --open- Create an account on crates.io.
- Generate an API token in your account settings.
- Login locally via your terminal:
cargo login <your-token>
Verify that the package is ready for upload without actually publishing it:
cargo publish --dry-runWhen everything is ready and tests pass, you can publish manually:
cargo publishThis repository is configured with a GitHub Action that automatically publishes to crates.io when a new version tag (e.g., v0.1.1) is pushed.
Setup Requirements:
- Go to your GitHub repository settings.
- Navigate to Secrets and variables > Actions.
- Add a New repository secret named
CRATES_IO_TOKEN. - Paste your
crates.ioAPI token as the value.
Once the secret is added, simply tagging your commit will trigger the release:
git tag v0.1.1
git push origin v0.1.1Once published, users can simply add celerix-store = "0.1.0" to their dependencies instead of using the Git URL.