Skip to content

Commit

Permalink
Merge pull request #54 from extrawurst/sled-flushing
Browse files Browse the repository at this point in the history
sled: match redb behaviour and flush after any write
  • Loading branch information
johanhelsing authored Jul 8, 2024
2 parents 91e2b36 + 649bbf0 commit 260f3d3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sled_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ impl StoreImpl for SledStore {
let mut serializer = rmp_serde::Serializer::new(Vec::new()).with_struct_map();
value.serialize(&mut serializer)?;
self.db.insert(key, serializer.into_inner())?;
self.db.flush()?;
Ok(())
}

/// More or less the same as set::<String>, but can take a &str
fn set_string(&mut self, key: &str, value: &str) -> Result<(), Self::SetError> {
let bytes = rmp_serde::to_vec(value)?;
self.db.insert(key, bytes)?;
self.db.flush()?;
Ok(())
}

Expand All @@ -72,6 +74,7 @@ impl StoreImpl for SledStore {
/// clear is also a kind of store so it will return SetError on failure
fn clear(&mut self) -> Result<(), Self::SetError> {
self.db.clear()?;
self.db.flush()?;
Ok(())
}
}

0 comments on commit 260f3d3

Please sign in to comment.