C++ APISession methods
set_session_value
Stores a key-value pair in temporary session-scoped storage.
set_session_value(std::string key, std::string content, std::chrono::seconds ttl)
stores a value under key in the current session cache and returns
blaze::status.
Function variants
blaze::status set_session_value(std::string key, std::string content, std::chrono::seconds ttl);
blaze::status set_session_value(std::string key, std::string content, std::chrono::seconds ttl, std::error_code& ec) noexcept;
void async_set_session_value(
std::string key,
std::string content,
std::chrono::seconds ttl,
std::function<void(std::error_code, blaze::status)> callback
);
blaze::coro::awaitable_result<blaze::status> co_set_session_value(std::string key, std::string content, std::chrono::seconds ttl);Status vs error
The returned blaze::status is the API result. std::error_code and
std::system_error are used for transport/runtime failures only.
Parameters
Prop
Type
Result
blaze::statusUse direct comparison, for example:
if (status == blaze::status::ok) {
// success
}Behavior notes
- Call
set_session_valueonly after successfulconnectandinitialize. - This is session-scoped volatile storage attached to the current websocket session.
- Values are not shared across sessions.
- Writing an existing
keyoverwrites its content and refreshes its TTL. - Use
delete_session_valueif you need to remove an entry before its TTL expires. - This method does not provide a built-in default TTL. You pass
ttlexplicitly on every call. - If
ttl <= 0s, the request still sends that value and the server applies its own default TTL of72h. - Current server-side limits for this cache are
64entries and16384bytes of total stored values per session.
Example
Compilation note
Synchronous and Asynchronous examples compile in the same form from C++17
to C++26.
#include "blazeauth/api/api.hpp"
#include <chrono>
#include <iostream>
#include <string>
#include <system_error>
void print_error_code(const std::string& context, const std::error_code& ec) {
std::cout << context << ": " << ec.message() << " ("
<< ec.value() << " : " << ec.category().name() << ")\n";
}
std::string read_line(const std::string& label) {
std::string value;
std::cout << label << ": ";
std::getline(std::cin, value);
return value;
}
void print_status(const std::string& context, blaze::status status) {
std::cout << context << ": "
<< static_cast<unsigned int>(status)
<< " (" << blaze::to_string(status) << ")\n";
}
int main() {
const std::string websocket_api_key = read_line("Websocket API key");
const std::string client_id = read_line("Client ID");
const std::string key = read_line("Session key");
const std::string value_content = read_line("Session value");
blaze::session session;
try {
const blaze::api_server server = session.connect();
std::cout << "Connected to server location: " << server.location << '\n';
const blaze::application app = session.initialize(websocket_api_key, client_id);
if (!app.good()) {
print_status("Initialize returned status", app.status);
return 1;
}
const blaze::status set_status = session.set_session_value(key, value_content, std::chrono::hours(1));
if (set_status != blaze::status::ok) {
print_status("Set-session-value returned status", set_status);
return 1;
}
std::cout << "Session value stored successfully\n";
session.shutdown();
} catch (const std::system_error& e) {
print_error_code("Set-session-value failed", e.code());
return 1;
}
return 0;
}Set-session-value statuses
| Value | Status | Returned when |
|---|---|---|
1 | ok | Value was stored successfully. |
701 | store_out_of_memory | Session cache memory limit was exceeded for this write. |
702 | store_out_of_entries | Session cache entry limit was exceeded for this write. |
Connection-level shutdowns
Normal set-session-value results are returned as
blaze::status. The websocket may still be closed by session-level guards:
| Close code | Meaning | When it can happen |
|---|---|---|
4200 | not_initialized | set_session_value was called before a successful initialize. |
4201 | rate_limited | Session or IP rate limiting closed the websocket around this operation. |