Skip to main content

Config

Struct Config 

Source
pub struct Config {
Show 20 fields pub maxmemory: u64, pub eviction_policy: EvictionPolicy, pub data_dir: Option<PathBuf>, pub aof: bool, pub appendfsync: AppendFsync, pub snapshot_filename: String, pub aof_filename: String, pub ttl_reaper: TtlReaperMode, pub reaper_interval: Duration, pub reaper_samples: usize, pub reaper_max_rounds: u32, pub auto_aof_rewrite_pct: u32, pub auto_aof_rewrite_min_size: u64, pub shards: usize, pub replica_upstream: Option<String>, pub replica_id: String, pub replica_reconnect_min: Duration, pub replica_reconnect_max: Duration, pub embed_writer_listen_addr: Option<String>, pub embed_writer_backlog_bytes: usize, /* private fields */
}
Expand description

Embedded-store config. Build by chaining with_* methods on Config::default.

Fields§

§maxmemory: u64

Soft memory ceiling in bytes. 0 (default) = unlimited.

§eviction_policy: EvictionPolicy

Eviction policy when over maxmemory. Default NoEviction.

§data_dir: Option<PathBuf>

Persistence directory. None = pure in-memory (no AOF, no snapshot).

§aof: bool

AOF on/off when data_dir is set. Defaults to true (on) when with_persist was called; ignored if data_dir is None.

§appendfsync: AppendFsync

AOF fsync policy. Default EverySec (matches Redis: ≤ 1 s loss).

§snapshot_filename: String

Snapshot file name inside data_dir (single-shard only; n > 1 always uses dump-{i}.rdb). Default "dump-0.rdb". A custom name opts the dir out of server interop: no shards.meta is recorded, and a kevy server opening the same dir won’t find the files.

§aof_filename: String

AOF file name inside data_dir (single-shard only; n > 1 always uses aof-{i}.aof). Default "aof-0.aof". Same interop opt-out as Self::snapshot_filename.

§ttl_reaper: TtlReaperMode

TTL reaper mode. Default Background.

§reaper_interval: Duration

Reaper tick interval. Default 100 ms (10 Hz).

§reaper_samples: usize

tick_expire samples per round. Default 20 (matches Redis).

§reaper_max_rounds: u32

Max sample rounds per tick. Default 16.

§auto_aof_rewrite_pct: u32

Auto-BGREWRITEAOF trigger: rewrite when the live AOF has grown by at least this percent over its size at the previous rewrite. 0 disables (call crate::Store::rewrite_aof manually). Default 100 (Redis).

§auto_aof_rewrite_min_size: u64

Floor below which auto-rewrite is skipped. Default 64 MiB (Redis).

§shards: usize

Keyspace shard count (hash(key) % shards), each a fully independent lock + keyspace + AOF (shared-nothing) — concurrent access scales across cores. Default 1 (single shard = the original single-lock / single-aof-0.aof layout, zero migration). Set > 1 via Self::with_shards; the first open with > 1 re-shards an existing single AOF into per-shard files.

§replica_upstream: Option<String>

Replication upstream. Some("host:port") makes this store a read-replica that streams writes from the named primary; None (default) is a normal primary store. Configured via Self::with_replica_upstream or the convenience constructor crate::Store::open_replica. See Phase 2 of the v3-cluster RFC.

§replica_id: String

Replica identity string sent to the primary at handshake (REPLICATE FROM <offset> ID <replica_id>). Default "kevy-embedded-replica". Override per-process when multiple embed replicas connect to the same primary (they’d otherwise share the slot and clobber each other’s session state on the primary side).

§replica_reconnect_min: Duration

Replica reconnect backoff: lower bound. Default 100 ms. The runner sleeps this long after the first connection failure; each subsequent failure doubles the wait up to Self::replica_reconnect_max.

§replica_reconnect_max: Duration

Replica reconnect backoff: upper bound. Default 5 s — picked to match the v1.18 server’s reconnect_window_ms default so embed replicas and server replicas behave identically when the same primary disappears.

§embed_writer_listen_addr: Option<String>

Phase 3 / v1.21 embed-as-writer: bind address ("host:port" or "0.0.0.0:port") for the replication source listener. When Some, every commit on this store pushes its argv into a process-local ReplicationSource backlog, and replicas (other embeds, server-as-replicas) connect to this port to stream the writes. None (default) keeps the embed in pure-local mode. Mutually exclusive in spirit with replica_upstream (a single store should be either a writer source OR a reader sink, not both); the builder doesn’t reject the combo so tests can exercise the guard rails.

§embed_writer_backlog_bytes: usize

Backlog byte budget for the embed-as-writer source. Default 1 MiB (matches the v1.18 server replication default). Set higher when consumers may disconnect for longer than the backlog can buffer (otherwise reconnects hit TooOld and v1.21 closes the link — snapshot-ship from embed is a follow-up).

Implementations§

Source§

impl Config

Source

pub fn with_persist(self, dir: impl Into<PathBuf>) -> Self

Enable persistence under dir — snapshot file + AOF land inside. AOF defaults on; turn it off with Self::without_aof for pure snapshot-only durability.

Source

pub fn without_aof(self) -> Self

Disable the AOF (snapshot-only persistence — explicit save_snapshot calls are the only way data survives restart).

Source

pub fn with_max_memory(self, bytes: u64) -> Self

Soft memory ceiling in bytes. 0 keeps the default (unlimited).

Source

pub fn with_eviction(self, policy: EvictionPolicy) -> Self

Eviction policy when over Self::with_max_memory.

Source

pub fn with_appendfsync(self, fsync: AppendFsync) -> Self

AOF fsync policy. Default AppendFsync::EverySec.

Source

pub fn with_auto_aof_rewrite(self, pct: u32, min_size: u64) -> Self

Auto-BGREWRITEAOF thresholds: rewrite once the AOF has grown pct percent past its size at the last rewrite AND is at least min_size bytes. In Background reaper mode the check runs on the reaper tick; in Manual mode it runs when you call crate::Store::tick. Pass pct = 0 to disable auto-rewrite (you can still call crate::Store::rewrite_aof yourself). Defaults: 100 % / 64 MiB.

Source

pub fn with_shards(self, n: usize) -> Self

Shard the keyspace into n shared-nothing partitions (hash(key) % n), each with its own lock + keyspace + AOF, so concurrent access scales across cores. n clamps to ≥ 1; 1 (default) is the original single-shard layout. Going from a single-AOF store to n > 1 re-shards the existing aof-0.aof into aof-0..aof-{n-1} on the next open (the old file is backed up to aof-0.aof.premigration.<ts> first). Pub/sub is process-wide (handled on shard 0), not sharded.

Source

pub fn with_metric_sink( self, sink: impl Fn(KevyMetric) + Send + Sync + 'static, ) -> Self

Register a push-style metric callback. It receives a crate::KevyMetric for each AOF replay (startup) and AOF rewrite (compaction) — wire it to Prometheus / a log line / a counter. The callback runs synchronously on the emitting thread (reaper thread for background rewrites), so keep it fast and non-blocking. Replaces any previously-set sink.

Source

pub fn with_ttl_reaper_manual(self) -> Self

Caller-driven TTL reaping — disables the background thread. Required for WASM (no threads available). Call crate::Store::tick yourself from your event loop.

Source

pub fn with_replica_upstream(self, upstream: impl Into<String>) -> Self

Configure this store as a replication replica of upstream ("host:port" of a kevy server’s replication listener). A background thread streams writes from the primary and applies them locally; this store rejects local writes with a READONLY error. See crate::Store::open_replica for the convenience constructor. Phase 2 of the v3-cluster RFC.

Source

pub fn with_replica_id(self, id: impl Into<String>) -> Self

Override the replica identity sent to the primary at handshake. Useful when multiple embed replicas share one primary — otherwise they’d share the slot and stomp each other’s session state.

Source

pub fn with_replica_reconnect(self, min: Duration, max: Duration) -> Self

Override the replica reconnect backoff bounds.

Source

pub fn with_embed_writer(self, bind_addr: impl Into<String>) -> Self

Run this store as a Phase 3 embed-as-writer: bind a replication source listener on bind_addr so replicas can subscribe to the writes applied here.

Source

pub fn with_embed_writer_backlog(self, bytes: usize) -> Self

Override the embed-as-writer backlog byte budget.

Source

pub fn with_reaper_interval(self, iv: Duration) -> Self

Override the background reaper interval. Default 100 ms.

Source

pub fn with_snapshot_filename(self, name: impl Into<String>) -> Self

Override the snapshot file name inside data_dir.

Source

pub fn with_aof_filename(self, name: impl Into<String>) -> Self

Override the AOF file name inside data_dir.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.