rt-pods-client 0.1.2

Official Client for RtPods
Documentation

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, PredictiveSearchOptions, RtPods, SearchOptions,
    SearchSort, SearchSortOrder, StandardSearchOptions,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let rt_pods = RtPods::new(vec!["127.0.0.1:1337"])?;

    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/",
            SearchOptions {
                sort: Some(vec![SearchSort::Length(SearchSortOrder::Ascending)]),
                standard: Some(StandardSearchOptions {
                    depth: 12,
                    limit: Some(24),
                }),
                predictive: Some(PredictiveSearchOptions {
                    depth: 12,
                    limit: Some(24),
                }),
                prepend_prefix: Some(false),
            },
        )
        .await?;

    if let SearchResult::Ok(results) = search_result {
        println!("{:?}", results);

        // Logs
        // [
        //     "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",
])?;

// 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.