18 stable releases

1.11.0 Aug 19, 2024
1.10.1 Jun 11, 2024
1.9.5 Mar 30, 2024
1.8.1 Jan 28, 2024
1.6.1 Aug 28, 2023

#557 in Database interfaces

Download history 50/week @ 2024-05-13 65/week @ 2024-05-20 133/week @ 2024-05-27 67/week @ 2024-06-03 300/week @ 2024-06-10 31/week @ 2024-06-17 23/week @ 2024-06-24 31/week @ 2024-07-01 14/week @ 2024-07-08 47/week @ 2024-07-15 23/week @ 2024-07-22 46/week @ 2024-07-29 85/week @ 2024-08-05 36/week @ 2024-08-12 232/week @ 2024-08-19 22/week @ 2024-08-26

377 downloads per month
Used in reduct-cli

MPL-2.0 license

96KB
2K 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 bytes::Bytes;
use futures_util::stream::StreamExt;
use reduct_rs::{QuotaType, ReductClient, ReductError};
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 in the 'sensor-1' entry
    let start = SystemTime::now();
    bucket
        .write_record("sensor-1")
        .data(b"Record #1")
        .timestamp(start)
        .send()
        .await?;

    bucket
        .write_record("sensor-1")
        .data(b"Record #2")
        .timestamp(start + Duration::from_secs(1))
        .send()
        .await?;

    // 4. Query the data by time range
    let query = bucket
        .query("sensor-1")
        .start(start)
        .stop(start + Duration::from_secs(2))
        .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

~16–29MB
~536K SLoC