Skip to content

Commit

Permalink
apply readme
Browse files Browse the repository at this point in the history
  • Loading branch information
atimin committed Jun 9, 2024
1 parent afdd1a8 commit 6bfd398
Showing 1 changed file with 46 additions and 24 deletions.
70 changes: 46 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,75 @@ database for unstructured data.

## Features

* Supports the [ReductStore HTTP API v1.10](https://reduct.store/docs/http-api)
* Supports the [ReductStore HTTP API v1.10](https://www.reduct.store/docs/http-api)
* Built on top of [reqwest](https://github.com/seanmonstar/reqwest)
* Asynchronous API

## Example

```rust

use bytes::Bytes;
use reduct_rs::{ReductClient, ReductError};
use std::str::from_utf8;
use std::time::SystemTime;

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> {
let client = ReductClient::builder().url("http://127.0.0.1:8383").build();
// 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?;

let timestamp = SystemTime::now();
// 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?;

let bucket = client.create_bucket("test").exist_ok(true).send().await?;
bucket
.write_record("entry-1")
.timestamp(timestamp)
.data("Hello, World!")
.write_record("sensor-1")
.data(b"Record #2")
.timestamp(start + Duration::from_secs(1))
.send()
.await?;

let record = bucket
.read_record("entry-1")
.timestamp(timestamp)
// 4. Query the data by time range
let query = bucket
.query("sensor-1")
.start(start)
.stop(start + Duration::from_secs(2))
.send()
.await?;

println!("Record: {:?}", record);
println!(
"Data: {}",
from_utf8(&record.bytes().await?.to_vec()).unwrap()
);
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(())
}

```
}

## References
```

* [Documentation](https://docs.rs/reduct-rs/latest/reduct_rs/)
* [ReductStore HTTP API](https://reduct.store/docs/http-api)
For more examples, see the [Guides](https://reduct.store/docs/guides) section in the ReductStore documentation.

0 comments on commit 6bfd398

Please sign in to comment.