10 releases
0.1.9 | Aug 25, 2024 |
---|---|
0.1.8 | Aug 25, 2024 |
0.1.6 | Jul 13, 2024 |
#1853 in Network programming
479 downloads per month
34KB
561 lines
rt-pods-client
Rust Client for RT(Radix Tree)-Pods. RT-Pods is a persisted, and distributed network of instances holding RadixTrees.
Description
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.
Installation
cargo add rt-pods-client
Example Usage
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()),
BatchOperation::Insert("/root/images".to_string()),
BatchOperation::Insert("/root/images/owls".to_string()),
BatchOperation::Insert("/root/images/owls/snow.jpg".to_string()),
BatchOperation::Insert("/root/images/owls/grey.jpg".to_string()),
],
)
.await?;
let search_result = rt_pods
.search(
"1337",
"/root/",
SearchOptionsBuilder::new()
.sort(vec![SearchSort::Length(SearchSortOrder::Ascending)])
.standard(12, Some(24))
.predictive(12, Some(24))
.build(),
)
.await?;
if let SearchResult::Ok(results) = search_result {
println!("{:?}", results);
// Logs
// [
// "images",
// "images/owls",
// "images/owls/snow.jpg",
// "images/owls/grey.jpg",
// ]
}
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;
}
});
Contributing
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.
License
MIT License
Copyright (c) 2024 Robert Lopez
See LICENSE.md
Project status
I plan to continue maintaining this project as long as I maintain rt-pods
.
Dependencies
~6–17MB
~236K SLoC