The ReductStore Client SDK for C++ is an open source client for ReductStore written in C++20. It allows developers to easily interact with the database from their C++ applications.
- Written in C++20
- Support ReductStore HTTP API v1.10
- Support HTTP and HTTPS protocols
- Support Linux AMD64
Here is a simple example of how to use the ReductStore Client SDK for C++ to create a bucket, write data to it, and read the data back:
#include <reduct/client.h>
#include <iostream>
using reduct::IBucket;
using reduct::IClient;
using sec = std::chrono::seconds;
int main() {
// 1. Create a ReductStore client
auto client = IClient::Build("http://127.0.0.1:8383",{
.api_token = "my-token"
});
// 2. Get or create a bucket with 1Gb quota
auto [bucket, create_err] = client->GetOrCreateBucket("my-bucket", {
.quota_type = IBucket::QuotaType::kFifo,
.quota_size = 1'000'000'000
});
if (create_err) {
std::cerr << "Error: " << create_err;
return -1;
}
// 3. Write some data with timestamps in the 'sensor-1' entry
IBucket::Time start = IBucket::Time::clock::now();
[[maybe_unused]] auto write_err =
bucket->Write("sensor-1", start, [](auto rec) { rec->WriteAll("Record #1"); });
write_err = bucket->Write("sensor-1", start + sec(1), [](auto rec) { rec->WriteAll("Record #2"); });
// 4. Query the data by time range
auto err = bucket->Query("sensor-1", start, start + sec(2), {}, [](auto&& record) {
std::cout << "Timestamp: " << record.timestamp.time_since_epoch().count() << std::endl;
std::cout << "Content Length: " << record.size << std::endl;
auto [blob, read_err] = record.ReadAll();
if (!read_err) {
std::cout << "Read blob: " << blob << std::endl;
}
return true;
});
if (err) {
std::cerr << "Error: " << err;
return -1;
}
return 0;
}
- GCC 11.2 or higher (support C++20)
- CMake 3.18 or higher
- ZLib
- OpenSSL 1.1 or 3.0
- Conan 1.58 (optionally)
To build the library, follow these steps:
git clone https://github.com/reductstore/reduct-cpp.git
cd reduct-cpp
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
sudo cmake --build . --target install
CMake tries to use the conan
package manager if it is installed. If it isn't, it downloads all the dependencies by using
FetchContent. To use ReductStore SDK you need only to use find_pacakge
in your cmake lists:
find_package(ReductCpp)
For more examples, see the Guides section in the ReductStore documentation.