- Notifications
You must be signed in to change notification settings - Fork1
Rugged embedded and client/server key-value database (Rust implementation)
License
alttch/yedb-rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Features:
- client-sync synchronous client
- client-async asynchronous client
- cli yedb-cli
- server yedb-server
Is it fast?
Rust version is pretty fast, except writes are still slow if auto-flush isenabled.
Is it smart?
No
So what is YEDB for?
YEDB is ultra-reliable, thread-safe and very easy to use.
I don't like Rust
There are otherimplementations.
https://www.youtube.com/watch?v=i3hSWjrNqLo
YEDB is absolutely reliable rugged key-value database, which can survive in anypower loss, unless the OS file system die. Keys data is saved in the veryreliable way and immediately flushed to disk (this can be disabled to speed upthe engine but is not recommended - why then YEDB is used for).
Rust version is built on top ofSerde framework.
All key values areserde_json::Value objects.
Storage serialization formats supported: JSON (default), YAML, MessagePackand CBOR.
As byte type is not supported byserde_json::Value at this moment, Rustversion can not handle byte key values.
Contains: embedded library, async server and command-line client (TCP/Unixsocket only).
The command-line client is very basic. If you need more features, useyedbPython CLI.
"delete" command does not delete keys, they are moved to .trash folderinstead
.trash folder is being cleaned when "purge" method is invoked.
"auto_bak" property tells server to automatically create backup key versionswhen key data is modified
"bak" keys are hidden
Binaries available at thereleasespage.
Run server:
./yedb-server /tmp/db1
Use client:
# get server info./yedb-cli info# set key value./yedb-cliset x 5 -p number# list all keys./yedb-cli ls /# edit key with $EDITOR./yedb-cli edit x# get key as JSON./yedb-cli get x# get help for all commands./yedb-cli -h
The database/client objects can be safely shared between threads using any kindof Lock/Mutex preferred.
use yedb::Database;use serde_json::Value;letmut db =Database::new();db.set_db_path("/tmp/db1").unwrap();db.open().unwrap();let key_name ="test/key1";db.key_set(&key_name,Value::from(123_u8)).unwrap();println!("{:?}", db.key_get(&key_name));db.key_delete(&key_name).unwrap();db.close().unwrap();
use yedb::YedbClient;use serde_json::Value;letmut client =YedbClient::new("tcp://127.0.0.1:8870");let key_name ="test/key1";client.key_set(&key_name,Value::from(123_u8)).unwrap();println!("{:?}", client.key_get(&key_name));client.key_delete(&key_name).unwrap();
use serde_json::Value;use yedb::{YedbClientAsync,YedbClientAsyncExt};asyncfntest(){letmut client =YedbClientAsync::new("tcp://127.0.0.1:8870");let key_name ="test/key1"; client.key_set(&key_name,Value::from(123_u8)).await.unwrap();println!("{:?}", client.key_get(&key_name).await); client.key_delete(&key_name).await.unwrap();}
use serde_json::Value;use std::sync::Arc;use std::time::Duration;use yedb::{YedbClientPoolAsync,YedbClientAsyncExt};asyncfntest(){let pool =Arc::new(YedbClientPoolAsync::create().size(10).path("tcp://127.0.0.1:8870").retries(3).timeout(Duration::from_secs(2)).build());letmut futs =Vec::new();for iin0..10{let task_pool = pool.clone();let fut = tokio::spawn(asyncmove{letmut client = task_pool.get().await;let key =format!("test/key{}", i); client.key_set(&key,Value::from(i)).await.unwrap();println!("{}", client.key_get(&key).await.unwrap()); client.key_delete(&key).await.unwrap();}); futs.push(fut);}for futin futs{ fut.await.unwrap();}}
- CPU: Intel Core i7-8550U (4 cores)
- Drive: Samsung MZVLB512HAJQ-000L7 (NVMe)
- auto_flush: false
- connection: Unix socket
- server workers: 2
- client threads: 4
set/number: 8164 ops/secset/string: 7313 ops/secset/array: 7152 ops/secset/object: 5272 ops/secget/number: 49709 ops/secget/string: 33338 ops/secget/array: 31426 ops/secget/object: 11654 ops/secget(cached)/number: 122697 ops/secget(cached)/string: 61206 ops/secget(cached)/array: 59309 ops/secget(cached)/object: 34583 ops/secincrement: 7079 ops/sec
About
Rugged embedded and client/server key-value database (Rust implementation)