A fast, embedded key-value store in Rust
TurboKV is an async embedded key-value database with atomic batches, ordered range scans, configurable durability, compression, and background compaction.
Installation
cargo add turbokv cargo add tokio --features full
Or add the dependencies directly:
[ dependencies ] turbokv = " 0.6 " tokio = { version = " 1 " , features = [ " full " ] }
TurboKV's persisted Bloom-filter format uses hardware AES. Build x86/x86_64 targets with RUSTFLAGS="-C target-feature=+aes,+sse2" , and ARM/AArch64 targets with RUSTFLAGS="-C target-feature=+aes,+neon" . You may instead use -C target-cpu=native when the binary will run only on the same CPU model or a feature superset.
Quick start
use turbokv :: { Db , DbOptions , WriteBatch } ; # [ tokio :: main ] async fn main ( ) -> Result < ( ) , Box < dyn std :: error :: Error > > { let db = Db :: open_with_options ( "./my-database" , DbOptions :: durable ( ) ) . await ? ; db . insert ( b"user:1" , b"Ada" ) . await ? ; assert_eq ! ( db . get ( b"user:1" ) . await ? , Some ( b"Ada" . to_vec ( ) ) ) ; let mut batch = WriteBatch :: new ( ) ; batch . put ( b"user:2" , b"Grace" ) ; batch . put ( b"user:3" , b"Linus" ) ; batch . delete ( b"user:1" ) ; db . write_batch ( & batch ) . await ? ; for ( key , value ) in db . scan_prefix ( b"user:" ) . await ? { println ! ( "{} = {}" , String :: from_utf8_lossy ( & key ) , String :: from_utf8_lossy ( & value ) ) ; } db . close ( ) . await ? ; Ok ( ( ) ) }
Runnable examples:
... continue reading