Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Subscribing new record with Reduct C++ SDK

This article provides an introduction to ReductStore and explains how to use the Reduct C++ SDK to subscribe to data from the database. PrerequisitesTo subscribe to new records, we should use a continuous query, which has been supported by ReductStore since version v1.4. We can use the following Docker command to run it:docker pull reduct/store:latestdocker run -p 8383:8383 reduct/store:latest Now, we need to install the Reduct Client SDK for C++. Please refer to these instructions. Full ExampleNow, take a look at the code of the example.#include #include #include using reduct::IBucket;using reduct::IClient;int main() { auto writer = std::thread([]() { auto client = IClient::Build("http://127.0.0.1:8383"); auto [bucket, err] = client->GetOrCreateBucket("bucket"); if (err) { std::cerr Write("entry-1", opts, [msg](auto rec) { rec->WriteAll(msg); }); std::cout GetOrCreateBucket("bucket"); if (err) { std::cerr Query("entry-1", IBucket::Time::clock::now(), std::nullopt, opts, [&good_count](auto &&record) { auto [msg, read_err] = record.ReadAll(); if (read_err) { std::cerr GetOrCreateBucket("bucket"); if (err) { std::cerr Write("entry-1", opts, [msg](auto rec) { rec->WriteAll(msg); });ReductStore is a time-series database that stores data as a blob. Each blob is a record that must have a timestamp. However, you can attach additional information to the record, such as labels, and use them for annotation or data filtering. In this case, we assign the label goog with the values true or false.In this example, we send short text messages for demonstration purposes only. ReductStore is better suited for handling larger data blobs, such as images, sound, or binary data like Protobuf messages. Continuous QueryAfter we ran writing labels in a separated thread we can query only good data and wait for first 3:const auto opts = IBucket::QueryOptions{ .include = {{"good", "true"}}, .continuous = true, .poll_interval = std::chrono::milliseconds{100},};auto query_err = bucket->Query("entry-1", IBucket::Time::clock::now(), std::nullopt, opts, [&good_count](auto &&record) { auto [msg, read_err] = record.ReadAll(); if (read_err) { std::cerr



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Subscribing new record with Reduct C++ SDK

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×