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, 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.
KevyCommands
kevy’s command set, plugged into the kevy-rt runtime. Stateless — the keyspace lives in each shard’s Store, so this is a zero-sized clone target.
KeyspaceStore
A single-database keyspace.

Enums§

AfterDrain
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). serve is the canonical caller; use replace from the CONFIG SET path to overwrite.
config_replace
Atomically swap in a new live config. Returns Err if init has 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 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: nshards shards on ip:port, snapshotting to / restoring from data_dir, with the AOF on/off.