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, KeyspaceStore, dispatch};
let mut store = KeyspaceStore::new();
let cmd = |parts: &[&[u8]]| Argv::from(parts.iter().map(|p| p.to_vec()).collect::<Vec<_>>());
assert_eq!(dispatch(&mut store, &cmd(&[b"SET", b"k", b"v"])), b"+OK\r\n");
assert_eq!(dispatch(&mut store, &cmd(&[b"GET", b"k"])), b"$1\r\nv\r\n");
assert_eq!(dispatch(&mut store, &cmd(&[b"INCR", b"n"])), b":1\r\n");To run the full server: serve(ip, port, nshards, dir, aof).
Structs§
- Argv
- A parsed command’s argument vector.
- Kevy
Commands - kevy’s command set, plugged into the
kevy-rtruntime. Stateless — the keyspace lives in each shard’sStore, so this is a zero-sized clone target. - Keyspace
Store - A single-database keyspace.
Enums§
- After
Drain - What to do with a connection after draining its buffered commands.
Functions§
- config_
init - Install the process-wide config. Idempotent — subsequent calls are
silently ignored (first one wins).
serveis the canonical caller; usereplacefrom the CONFIG SET path to overwrite. - config_
replace - Atomically swap in a new live config. Returns
Errifinithas never run — refusing to silently fabricate an initial state from a CONFIG SET call. The caller (CONFIG SET) maps the Err to the matching RESP error. - dispatch
- Map one command to its RESP reply bytes.
- drain_
commands - Parse and dispatch every complete command in
input, appending replies tooutput. Consumes parsed bytes; leaves a trailing partial frame. ReturnsCloseafter aQUITor 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