#[non_exhaustive]pub enum TtlReaperMode {
Background,
Manual,
}Expand description
How the active TTL reaper runs.
use kevy_embedded::{Config, TtlReaperMode};
assert_eq!(Config::default().ttl_reaper, TtlReaperMode::Background);
assert_eq!(Config::default().with_ttl_reaper_manual().ttl_reaper, TtlReaperMode::Manual);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Background
Spawn a background thread that ticks at the configured interval
(default 100 ms / 10 Hz, matching Redis’s hz=10). Default.
use std::time::Duration;
use kevy_embedded::{Config, Store};
let s = Store::open(Config::default())?;
s.set_with_ttl(b"k", b"v", Duration::from_millis(1))?;
// nobody calls tick(): the background thread reclaims the key
for _ in 0..500 {
if s.info().expired_keys == 1 {
break;
}
std::thread::sleep(Duration::from_millis(10));
}
assert_eq!(s.info().expired_keys, 1);Manual
Caller-driven via crate::Store::tick. Required for WASM
targets (no threads) and single-threaded apps that don’t want a
background worker.
use std::time::Duration;
use kevy_embedded::{Config, Store};
let s = Store::open(Config::default().with_ttl_reaper_manual())?;
s.set_with_ttl(b"k", b"v", Duration::from_millis(1))?;
std::thread::sleep(Duration::from_millis(250));
assert_eq!(s.info().expired_keys, 0, "nothing reaps until the caller ticks");
for _ in 0..50 { s.tick(); }
assert_eq!(s.info().expired_keys, 1);Trait Implementations§
Source§impl Clone for TtlReaperMode
impl Clone for TtlReaperMode
impl Copy for TtlReaperMode
Source§impl Debug for TtlReaperMode
impl Debug for TtlReaperMode
Source§impl Default for TtlReaperMode
impl Default for TtlReaperMode
impl Eq for TtlReaperMode
Source§impl Hash for TtlReaperMode
impl Hash for TtlReaperMode
Source§impl PartialEq for TtlReaperMode
impl PartialEq for TtlReaperMode
impl StructuralPartialEq for TtlReaperMode
Auto Trait Implementations§
impl Freeze for TtlReaperMode
impl RefUnwindSafe for TtlReaperMode
impl Send for TtlReaperMode
impl Sync for TtlReaperMode
impl Unpin for TtlReaperMode
impl UnsafeUnpin for TtlReaperMode
impl UnwindSafe for TtlReaperMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more