#持久化 #存储 #内存中 #tokio #高并发

rstorage

快速、持久、高并发 HashMap

3 个稳定版本

1.0.2 2022年4月22日

#1194 in 文件系统

Apache-2.0

24KB
403

durableMap

durableMap 是内存中、持久化存储,针对(写密集型,读密集型)进行了优化

为什么需要 DurableMap ??

它是一个使用非阻塞 WAL 引擎进行持久化的并发 HashMap,避免任何数据丢失

示例


#[tokio::main]
async fn main() {

    
   // Optimized for write concurrent (API is same) 
   let dlw = WConcurrentStorage::<Document>::open("tester".to_owned(), 1000).await;
   
   // Optimized for read concurrent
   let dlr = RConcurrentStorage::<Document>::open("tester".to_owned(), 1000).await;

   
   // Insert / Update
   let _ = dlr.insert_entry(format!("102xa"), Document::new()).await;

   let _ = dlw.insert_entry(format!("102xa"), Document::new()).await;

   
   // Remove
   dlr.remove_entry(&format("102xa")).await;

   dlw.remove_entry(&format("102xa")).await;

   // Read
   dlr.table.read().await
           .iter()
           .for_each(|(key, doc)| {
               println!("==> {} -> {}", key, &doc.funame)
           });


   // Just Difference (RConcurrentStorage) and (WConcurrentStorage) is
   //  WConcurrentStorage for iter  table dont need lock
   //      because internally used sharded lock

   dlw.table
           .iter()
           .for_each(|(key, doc)| {
               println!("==> {} -> {}", key, &doc.funame)
           });
}  


#[derive(Serialize, Deserialize, Clone)]
struct Document {
    funame: String,
    age: i32,
}
impl Document {
    pub fn new() -> Self {
        Document { 
            funame: String::from("DanyalMh"), 
            age: 24, 
        }
    }
}



安装

[dependencies]

rstorage = "1.0.2"

依赖项

~4–12MB
~109K SLoC