Skip to main content

Config

Struct Config 

Source
pub struct Config {
    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,
}
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. Default "dump-0.rdb".

§aof_filename: String

AOF file name inside data_dir. Default "aof-0.aof".

§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.

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.

Examples found in repository?
examples/replay_real_aof.rs (line 35)
14fn main() {
15    let path = std::env::args()
16        .nth(1)
17        .expect("usage: replay_real_aof <aof-path>");
18    let src = PathBuf::from(&path);
19    let bytes = std::fs::metadata(&src)
20        .map(|m| m.len())
21        .unwrap_or(0);
22    println!("reproducer: staging {} bytes from {}", bytes, src.display());
23
24    let dir = std::env::temp_dir().join(format!(
25        "kevy-aof-reproducer-{}",
26        std::process::id()
27    ));
28    std::fs::create_dir_all(&dir).expect("create temp dir");
29    let staged = dir.join("aof-0.aof");
30    std::fs::copy(&src, &staged).expect("copy AOF into staging dir");
31
32    println!("reproducer: opening Store from {}", dir.display());
33    let store = Store::open(
34        Config::default()
35            .with_persist(&dir)
36            .with_aof_filename("aof-0.aof"),
37    )
38    .expect("Store::open");
39
40    println!("reproducer: opened OK; dbsize = {}", store.dbsize());
41}
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).

Examples found in repository?
examples/embedded-cache.rs (line 12)
9fn main() -> std::io::Result<()> {
10    let s = Store::open(
11        Config::default()
12            .with_max_memory(200 * 1024)
13            .with_eviction(EvictionPolicy::AllKeysLru),
14    )?;
15
16    for i in 0..10_000 {
17        let key = format!("user:{i:05}");
18        let val = format!("user-payload-{i}");
19        s.set(key.as_bytes(), val.as_bytes())?;
20    }
21
22    println!("dbsize after insert flood: {}", s.dbsize());
23    println!("used_memory: {} bytes (limit 200 KiB)", s.used_memory());
24    println!("evictions_total: {}", s.evictions_total());
25
26    // Touch a recent key — it should still be live.
27    let recent = format!("user:0{}", 9999);
28    println!(
29        "user:09999 → {:?}",
30        s.get(recent.as_bytes())?.as_deref().map(String::from_utf8_lossy)
31    );
32
33    Ok(())
34}
Source

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

Eviction policy when over Self::with_max_memory.

Examples found in repository?
examples/embedded-cache.rs (line 13)
9fn main() -> std::io::Result<()> {
10    let s = Store::open(
11        Config::default()
12            .with_max_memory(200 * 1024)
13            .with_eviction(EvictionPolicy::AllKeysLru),
14    )?;
15
16    for i in 0..10_000 {
17        let key = format!("user:{i:05}");
18        let val = format!("user-payload-{i}");
19        s.set(key.as_bytes(), val.as_bytes())?;
20    }
21
22    println!("dbsize after insert flood: {}", s.dbsize());
23    println!("used_memory: {} bytes (limit 200 KiB)", s.used_memory());
24    println!("evictions_total: {}", s.evictions_total());
25
26    // Touch a recent key — it should still be live.
27    let recent = format!("user:0{}", 9999);
28    println!(
29        "user:09999 → {:?}",
30        s.get(recent.as_bytes())?.as_deref().map(String::from_utf8_lossy)
31    );
32
33    Ok(())
34}
Source

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

AOF fsync policy. Default AppendFsync::EverySec.

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_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.

Examples found in repository?
examples/replay_real_aof.rs (line 36)
14fn main() {
15    let path = std::env::args()
16        .nth(1)
17        .expect("usage: replay_real_aof <aof-path>");
18    let src = PathBuf::from(&path);
19    let bytes = std::fs::metadata(&src)
20        .map(|m| m.len())
21        .unwrap_or(0);
22    println!("reproducer: staging {} bytes from {}", bytes, src.display());
23
24    let dir = std::env::temp_dir().join(format!(
25        "kevy-aof-reproducer-{}",
26        std::process::id()
27    ));
28    std::fs::create_dir_all(&dir).expect("create temp dir");
29    let staged = dir.join("aof-0.aof");
30    std::fs::copy(&src, &staged).expect("copy AOF into staging dir");
31
32    println!("reproducer: opening Store from {}", dir.display());
33    let store = Store::open(
34        Config::default()
35            .with_persist(&dir)
36            .with_aof_filename("aof-0.aof"),
37    )
38    .expect("Store::open");
39
40    println!("reproducer: opened OK; dbsize = {}", store.dbsize());
41}

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.