Crates.io | rt-pods-client |
lib.rs | rt-pods-client |
version | 0.1.12 |
source | src |
created_at | 2024-07-11 18:30:13.892445 |
updated_at | 2024-11-16 22:33:39.88504 |
description | Official Client for RtPods |
homepage | |
repository | https://gitlab.com/robertlopezdev/rt-pods-client |
max_upload_size | |
id | 1299871 |
size | 34,605 |
Rust Client for RT(Radix Tree)-Pods. RT-Pods is a RadixTree DBMS written in Rust.
Rust client to interface with a running RT-Pods deployment.
For documentation beyond the doc comments on the methods and docs.rs; or how to get started with RT-Pods, see the rt-pods
repository.
cargo add rt-pods-client
use rt_pods_client::{
results::SearchResult, BatchOperation, RtPods, SearchOptionsBuilder, SearchSort,
SearchSortOrder,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let rt_pods = RtPods::new(vec!["127.0.0.1:1337"], None)?;
rt_pods.create_radix_tree("1337").await?;
rt_pods
.batch_operation(
"1337",
vec![
BatchOperation::Insert(("/root".to_string(), None)),
BatchOperation::Insert(("/root/images".to_string(), None)),
BatchOperation::Insert(("/root/images/owls".to_string(), None)),
BatchOperation::Insert(("/root/images/owls/snow.jpg".to_string(), Some("data".to_string()))),
BatchOperation::Insert(("/root/images/owls/grey.jpg".to_string(), None)),
],
)
.await?;
let search_result = rt_pods
.search(
"1337",
"/root/",
SearchOptionsBuilder::new(12)
.sort(vec![SearchSort::Length(SearchSortOrder::Ascending)])
.limit(12)
.predictive(true)
.build(),
)
.await?;
if let SearchResult::Ok(results) = search_result {
println!("{:?}", results);
// Logs
// [
// ("images", None),
// ("images/owls", None),
// ("images/owls/snow.jpg", Some("data")),
// ("images/owls/grey.jpg", None),
// ]
}
rt_pods.remove("1337", "/root/images/owls/grey.jpg").await?;
rt_pods.delete_radix_tree("1337").await?;
Ok(())
}
// Cluster
let rt_pods = RtPods::new(vec![
"127.0.0.1:1337",
"127.0.0.1:1338",
"127.0.0.1:1339",
], None)?;
// It is highly recommended to at-least sync on startup
rt_pods.sync().await;
// Syncing with the cluster can let the client know
// about newly registered radix trees since the initial
// sync on construction and improve routing performance.
let rt_pods_clone = rt_pods.clone();
tokio::spawn(async move {
loop {
rt_pods_clone.sync().await;
sleep(Duration::from_secs(60)).await;
}
});
Open to any contributions, but this repository must mirror the rt-pods-client-ts
Typescript client completely; meaning any proposed changes here will need to be carried over to the next release of rt-pods-client-ts
or any following clients for other languages.
MIT License
Copyright (c) 2024 Robert Lopez
See LICENSE.md
I plan to continue maintaining this project as long as I maintain rt-pods
.