Skip to main content

Crate kevy

Crate kevy 

Source
Expand description

kevy — a single-machine, Redis-compatible key–value server.

This crate is the server: it supplies the command semantics — routing (KevyCommands) and execution ([dispatch]) — and wires them to the kevy-rt shared-nothing thread-per-core runtime via serve. The command logic is also reachable directly (one keyspace, no I/O) through [dispatch], which is handy for embedding or testing. Built from a small stack of zero-dependency crates: kevy-sys, kevy-resp, kevy-store, kevy-net, kevy-rt, kevy-persist.

§Example

Run commands against an in-process keyspace (no sockets):

use kevy::{Argv, KevyCommands, KeyspaceStore};

let kevy = KevyCommands::new();
let mut store = KeyspaceStore::new();
let cmd = |parts: &[&[u8]]| Argv::from(parts.iter().map(|p| p.to_vec()).collect::<Vec<_>>());
assert_eq!(kevy.dispatch(&mut store, &cmd(&[b"SET", b"k", b"v"])), b"+OK\r\n");
assert_eq!(kevy.dispatch(&mut store, &cmd(&[b"GET", b"k"])), b"$1\r\nv\r\n");
assert_eq!(kevy.dispatch(&mut store, &cmd(&[b"INCR", b"n"])), b":1\r\n");

To run the full server: serve(config).

Modules§

verb_meta
Verb documentation metadata — the single source of truth for COMMAND DOCS, llms.txt, and the MCP schema. Parity tests in tests_verb_meta.rs hold this table and the dispatch surface bidirectionally equal.

Structs§

Argv
A parsed command’s argument vector.
KevyCommands
kevy’s command set, plugged into the kevy-rt runtime: the shared RuntimeState plus this shard’s private [ShardCtx]. The runtime clones one KevyCommands per shard; the manual Clone shares the state Arc and rebuilds the shard zone empty.
KeyspaceStore
A single-database keyspace.
RuntimeState
Everything the server knows that is not per-shard keyspace data. Built once (by crate::serve or an embedder) and shared across shards behind an Arc.

Enums§

AfterDrain
What to do with a connection after draining its buffered commands.

Functions§

drain_commands
Parse and dispatch every complete command in input, appending replies to output. Consumes parsed bytes; leaves a trailing partial frame. Returns Close after a QUIT or a protocol error (whose reply is already appended).
handle_conn
Blocking single-connection handler. Shares command logic with the reactor; retained for tests and simple uses.
serve
Run the thread-per-core server forever, entirely shaped by cfg: cfg.server.threads shards on cfg.server.bind:cfg.server.port, snapshotting to / restoring from cfg.server.data_dir, AOF per cfg.persistence.aof. threads = 0 (the auto sentinel) runs one shard; the CLI resolves auto to available_parallelism() before calling in.