| 6 | |
| 7 | #[tokio::main] |
| 8 | async fn main() { |
| 9 | // path can be '.' in storage::open |
| 10 | let path = "."; |
| 11 | |
| 12 | let storage_name = "blackbird"; |
| 13 | let total_page_size = 1000; |
| 14 | |
| 15 | // ** RamCopies ** |
| 16 | // Dont log to disk and after shutdown , loss data |
| 17 | |
| 18 | let stype = StorageType::RamCopies; |
| 19 | |
| 20 | // ** DiskCopies ** |
| 21 | // whole storage operation is in-memory but log to disk, |
| 22 | // automatic load whole data after restart, avoid any loss data |
| 23 | // |
| 24 | // let stype = StorageType::DiskCopies; |
| 25 | |
| 26 | let ops = Options::new(path, storage_name, total_page_size, StorageType::RamCopies, true); |
| 27 | |
| 28 | // Storage is built for high concurrency usage |
| 29 | // dont need to Mutex / Rwlock, it is safe for shared between thread |
| 30 | // |
| 31 | // create storage and initialize other service (reporter, disk_log) |
| 32 | // |
| 33 | // when calling storage::open, it load whole storage from disk |
| 34 | // |
| 35 | |
| 36 | let s1 = Storage::<Pid, User>::open(ops).await.unwrap(); |
| 37 | |
| 38 | // insert to memory and send to (disk_log) and (reporter) |
| 39 | s1.insert("+98 9370156893".to_owned(), User::new("DanyalMh")) |
| 40 | .await |
| 41 | .unwrap(); |
| 42 | |
| 43 | { |
| 44 | let opd = s1.lookup(&"+98 9370156893".to_string()).unwrap(); |
| 45 | println!("==> {:?}", opd.value()); |
| 46 | } |
| 47 | |
| 48 | // remove from memory and send to (disk_log) and (reporter) |
| 49 | s1.remove("+98 9370156893".to_owned()).await; |
| 50 | |
| 51 | |
| 52 | |
| 53 | // iter over storage |
| 54 | s1.iter().for_each(|r| { |
| 55 | println!("==> {}-{:?}", r.key(), r.value()); |
| 56 | }) |
| 57 | } |
| 58 | |
| 59 | type Pid = String; |
| 60 | |