21 stable releases

new 1.13.0 Dec 4, 2024
1.12.1 Oct 21, 2024
1.11.0 Aug 19, 2024
1.10.1 Jun 11, 2024
1.7.3 Nov 8, 2023

#610 in Database interfaces

Download history 228/week @ 2024-08-18 25/week @ 2024-08-25 16/week @ 2024-09-01 30/week @ 2024-09-08 22/week @ 2024-09-15 97/week @ 2024-09-22 255/week @ 2024-09-29 194/week @ 2024-10-06 194/week @ 2024-10-13 368/week @ 2024-10-20 212/week @ 2024-10-27 279/week @ 2024-11-03 114/week @ 2024-11-10 203/week @ 2024-11-17 165/week @ 2024-11-24 249/week @ 2024-12-01

742 downloads per month
Used in reduct-cli

MPL-2.0 license

120KB
2.5K SLoC

ReductStore Client SDK for Rust

Crates.io Docs.rs GitHub Workflow Status

This package provides an HTTP client for interacting with the ReductStore, time-series database for unstructured data.

Features

Example

use futures_util::stream::StreamExt;
use reduct_rs::{QuotaType, ReductClient, ReductError};
use serde_json::json;
use std::pin::pin;
use std::time::{Duration, SystemTime};
use tokio;

#[tokio::main]
async fn main() -> Result<(), ReductError> {
    // 1. Create a ReductStore client
    let client = ReductClient::builder()
        .url("http://127.0.0.1:8383")
        .api_token("my-token")
        .build();

    // 2. Get or create a bucket with 1Gb quota
    let bucket = client
        .create_bucket("my-bucket")
        .quota_type(QuotaType::FIFO)
        .quota_size(1_000_000_000)
        .exist_ok(true)
        .send()
        .await?;

    // 3. Write some data with timestamps and labels to the 'entry-1' entry
    let start = SystemTime::now();
    bucket
        .write_record("sensor-1")
        .data("<Blob data>")
        .timestamp(start)
        .add_label("score", 10)
        .send()
        .await?;

    bucket
        .write_record("sensor-1")
        .data("<Blob data>")
        .timestamp(start + Duration::from_secs(1))
        .add_label("score", 20)
        .send()
        .await?;

    // 4. Query the data by time range and condition
    let query = bucket
        .query("sensor-1")
        .start(start)
        .stop(start + Duration::from_secs(2))
        .when(json!({"&score": {"$gt": 15}}))
        .send()
        .await?;

    let mut query = pin!(query);
    while let Some(record) = query.next().await {
        let record = record?;
        println!("Record timestamp: {:?}", record.timestamp());
        println!("Record size: {}", record.content_length());
        println!("{:?}", record.bytes().await?);
    }

    // 5. Exit
    Ok(())
}

For more examples, see the Guides section in the ReductStore documentation.

Dependencies

~11–22MB
~319K SLoC