8个版本

0.1.7 2024年8月6日
0.1.6 2024年7月13日

6#radix-tree

Download history 102/week @ 2024-07-05 348/week @ 2024-07-12 28/week @ 2024-07-19 51/week @ 2024-07-26 133/week @ 2024-08-02

662 每月下载量

MIT 许可证

31KB
465

rt-pods-client

Rust客户端,用于与RT(Radix Tree)-Pods交互。RT-Pods是一个持久化和分布式的实例网络,持有RadixTree。

描述

Rust客户端,用于与运行中的RT-Pods部署进行交互。

有关方法上的doc注释之外的文档或如何开始使用RT-Pods,请参阅rt-pods仓库。

安装

  • cargo添加 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"])?;

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

// 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;
    }
});

贡献

欢迎任何贡献,但此仓库必须完全镜像rt-pods-client-ts TypeScript客户端;这意味着在此处提出的任何更改都需要迁移到下一个版本的rt-pods-client-ts或任何其他语言的后续客户端。

许可证

MIT许可证

版权所有 (c) 2024 Robert Lopez

查看 LICENSE.md

项目状态

只要我维护rt-pods,我就计划继续维护此项目。

依赖项

~6–17MB
~237K SLoC