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: u64Soft memory ceiling in bytes. 0 (default) = unlimited.
eviction_policy: EvictionPolicyEviction policy when over maxmemory. Default NoEviction.
data_dir: Option<PathBuf>Persistence directory. None = pure in-memory (no AOF, no snapshot).
aof: boolAOF on/off when data_dir is set. Defaults to true (on) when
with_persist was called; ignored if data_dir is None.
appendfsync: AppendFsyncAOF fsync policy. Default EverySec (matches Redis: ≤ 1 s loss).
snapshot_filename: StringSnapshot file name inside data_dir. Default "dump-0.rdb".
aof_filename: StringAOF file name inside data_dir. Default "aof-0.aof".
ttl_reaper: TtlReaperModeTTL reaper mode. Default Background.
reaper_interval: DurationReaper tick interval. Default 100 ms (10 Hz).
reaper_samples: usizetick_expire samples per round. Default 20 (matches Redis).
reaper_max_rounds: u32Max sample rounds per tick. Default 16.
Implementations§
Source§impl Config
impl Config
Sourcepub fn with_persist(self, dir: impl Into<PathBuf>) -> Self
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.
Sourcepub fn without_aof(self) -> Self
pub fn without_aof(self) -> Self
Disable the AOF (snapshot-only persistence — explicit save_snapshot
calls are the only way data survives restart).
Sourcepub fn with_max_memory(self, bytes: u64) -> Self
pub fn with_max_memory(self, bytes: u64) -> Self
Soft memory ceiling in bytes. 0 keeps the default (unlimited).
Examples found in repository?
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}Sourcepub fn with_eviction(self, policy: EvictionPolicy) -> Self
pub fn with_eviction(self, policy: EvictionPolicy) -> Self
Eviction policy when over Self::with_max_memory.
Examples found in repository?
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}Sourcepub fn with_appendfsync(self, fsync: AppendFsync) -> Self
pub fn with_appendfsync(self, fsync: AppendFsync) -> Self
AOF fsync policy. Default AppendFsync::EverySec.
Sourcepub fn with_ttl_reaper_manual(self) -> Self
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.
Sourcepub fn with_reaper_interval(self, iv: Duration) -> Self
pub fn with_reaper_interval(self, iv: Duration) -> Self
Override the background reaper interval. Default 100 ms.
Sourcepub fn with_snapshot_filename(self, name: impl Into<String>) -> Self
pub fn with_snapshot_filename(self, name: impl Into<String>) -> Self
Override the snapshot file name inside data_dir.
Sourcepub fn with_aof_filename(self, name: impl Into<String>) -> Self
pub fn with_aof_filename(self, name: impl Into<String>) -> Self
Override the AOF file name inside data_dir.