-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c4fef8
commit 9818f68
Showing
15 changed files
with
577 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use core::str; | ||
use std::{sync::Arc, time::Duration}; | ||
|
||
use vicky_store::{Config, Result, VickyStore}; | ||
|
||
fn main() -> Result<()> { | ||
let db = Arc::new(VickyStore::open("/tmp/vicky-dir-mt", Config::default())?); | ||
|
||
// clear the DB just in case we has something there before. in real-life scenarios you would probably | ||
// not clear the DB every time | ||
db.clear()?; | ||
|
||
// clone db and spawn thread 1 | ||
let db1 = db.clone(); | ||
let h1 = std::thread::spawn(move || -> Result<()> { | ||
for i in 0..100 { | ||
db1.insert(&format!("key{i}"), "thread 1")?; | ||
std::thread::sleep(Duration::from_millis(1)); | ||
} | ||
Ok(()) | ||
}); | ||
|
||
// clone db and spawn thread 2 | ||
let db2 = db.clone(); | ||
let h2 = std::thread::spawn(move || -> Result<()> { | ||
for i in 0..100 { | ||
db2.insert(&format!("key{i}"), "thread 2")?; | ||
std::thread::sleep(Duration::from_millis(1)); | ||
} | ||
Ok(()) | ||
}); | ||
|
||
h1.join().unwrap()?; | ||
h2.join().unwrap()?; | ||
|
||
for res in db.iter() { | ||
let (k, v) = res?; | ||
println!( | ||
"{} = {}", | ||
str::from_utf8(&k).unwrap(), | ||
str::from_utf8(&v).unwrap() | ||
); | ||
} | ||
|
||
// key35 = thread 1 | ||
// key41 = thread 1 | ||
// key52 = thread 2 | ||
// key59 = thread 2 | ||
// key48 = thread 2 | ||
// key85 = thread 2 | ||
// key91 = thread 2 | ||
// key26 = thread 1 | ||
// key31 = thread 1 | ||
// ... | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use core::str; | ||
|
||
use vicky_store::{Config, Result, VickyStore}; | ||
|
||
fn main() -> Result<()> { | ||
let db = VickyStore::open("/tmp/vicky-dir", Config::default())?; | ||
|
||
// clear the DB just in case we has something there before. in real-life scenarios you would probably | ||
// not clear the DB every time | ||
db.clear()?; | ||
|
||
println!("{:?}", db.get("mykey")?); // None | ||
|
||
db.insert("mykey", "myval")?; | ||
println!("{:?}", db.get("mykey")?); // Some([109, 121, 118, 97, 108]) | ||
|
||
println!("{:?}", db.remove("mykey")?); // Some([109, 121, 118, 97, 108]) | ||
println!("{:?}", db.remove("mykey")?); // None | ||
|
||
println!("{:?}", db.get("mykey")?); // None | ||
|
||
for i in 0..10 { | ||
db.insert(&format!("mykey{i}"), &format!("myval{i}"))?; | ||
} | ||
for res in db.iter() { | ||
let (k, v) = res?; | ||
println!( | ||
"{} = {}", | ||
str::from_utf8(&k).unwrap(), | ||
str::from_utf8(&v).unwrap() | ||
); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.