rt-pods-client

Crates.iort-pods-client
lib.rsrt-pods-client
version0.1.11
sourcesrc
created_at2024-07-11 18:30:13.892445
updated_at2024-09-23 18:11:42.143989
descriptionOfficial Client for RtPods
homepage
repositoryhttps://gitlab.com/robertlopezdev/rt-pods-client
max_upload_size
id1299871
size33,176
(robertlopezdev)

documentation

README

rt-pods-client

Rust Client for RT(Radix Tree)-Pods. RT-Pods RadixTree DBMS written in Rust.

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(12)
                .sort(vec![SearchSort::Length(SearchSortOrder::Ascending)])
                .limit(12)
                .predictive(true)
                .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.

Commit count: 52

cargo fmt