#[non_exhaustive]pub enum AppendFsync {
Always,
EverySec,
No,
}Expand description
When to fsync the AOF to disk. The three values of Redis’s
appendfsync.
use kevy_persist::Fsync;
assert_eq!(Fsync::parse("EverySec"), Some(Fsync::EverySec));
assert_eq!(Fsync::Always.as_str(), "always");
assert_eq!(Fsync::default(), Fsync::EverySec);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.
Always
fsync after every write — safest, slowest.
use kevy_persist::{Aof, Argv, Fsync};
let path = std::env::temp_dir().join(format!("fsync-always-doc-{}.aof", std::process::id()));
let mut aof = Aof::open(&path, Fsync::Always)?;
aof.append(&Argv::from(vec![b"SET".to_vec(), b"k".to_vec(), b"v".to_vec()]))?;
// on disk before append returned: no tick, no drop needed
assert_eq!(std::fs::metadata(&path)?.len(), aof.size_bytes());EverySec
fsync about once per second; each crate::Aof::tick (or
crate::Aof::maybe_sync) writes the buffer into the kernel. A
power loss loses about one second plus the time one fsync takes.
The default.
use kevy_persist::{Aof, Fsync};
let path = std::env::temp_dir().join(format!("fsync-everysec-doc-{}.aof", std::process::id()));
let aof = Aof::open(&path, Fsync::default())?;
assert_eq!(aof.fsync_policy(), Fsync::EverySec);
assert_eq!(Fsync::EverySec.as_str(), "everysec");No
Never fsync explicitly: each crate::Aof::tick writes the buffer
into the kernel, and the OS decides when it reaches the disk.
use kevy_persist::{Aof, Fsync};
let path = std::env::temp_dir().join(format!("fsync-no-doc-{}.aof", std::process::id()));
let mut aof = Aof::open(&path, Fsync::Always)?;
aof.set_fsync(Fsync::parse("no").unwrap_or_default())?; // CONFIG SET appendfsync no
assert_eq!(aof.fsync_policy(), Fsync::No);Implementations§
Trait Implementations§
impl Copy for Fsync
impl Eq for Fsync
impl StructuralPartialEq for Fsync
Auto Trait Implementations§
impl Freeze for Fsync
impl RefUnwindSafe for Fsync
impl Send for Fsync
impl Sync for Fsync
impl Unpin for Fsync
impl UnsafeUnpin for Fsync
impl UnwindSafe for Fsync
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