7#include <boost/redis/connection.hpp>
8#include <boost/asio/deferred.hpp>
9#include <boost/asio/detached.hpp>
10#include <boost/asio/co_spawn.hpp>
15#if defined(BOOST_ASIO_HAS_CO_AWAIT)
17namespace net = boost::asio;
25void print(std::map<std::string, std::string>
const& cont)
27 for (
auto const& e: cont)
28 std::cout << e.first <<
": " << e.second <<
"\n";
31void print(std::vector<int>
const& cont)
33 for (
auto const& e: cont) std::cout << e <<
" ";
38auto store(std::shared_ptr<connection> conn) -> net::awaitable<void>
43 std::map<std::string, std::string>
map
44 {{
"key1",
"value1"}, {
"key2",
"value2"}, {
"key3",
"value3"}};
47 req.push_range(
"RPUSH",
"rpush-key", vec);
48 req.push_range(
"HSET",
"hset-key", map);
50 co_await conn->async_exec(req,
ignore, net::deferred);
53auto hgetall(std::shared_ptr<connection> conn) -> net::awaitable<void>
57 req.push(
"HGETALL",
"hset-key");
60 response<std::map<std::string, std::string>> resp;
63 co_await conn->async_exec(req, resp, net::deferred);
65 print(std::get<0>(resp).value());
69auto transaction(std::shared_ptr<connection> conn) -> net::awaitable<void>
73 req.push(
"LRANGE",
"rpush-key", 0, -1);
74 req.push(
"HGETALL",
"hset-key");
81 response<std::optional<std::vector<int>>, std::optional<std::map<std::string, std::string>>>
84 co_await conn->async_exec(req, resp, net::deferred);
86 print(std::get<0>(std::get<3>(resp).value()).value().value());
87 print(std::get<1>(std::get<3>(resp).value()).value().value());
91net::awaitable<void> co_main(config cfg)
93 auto conn = std::make_shared<connection>(
co_await net::this_coro::executor);
94 conn->async_run(cfg, {}, net::consign(net::detached, conn));
97 co_await transaction(conn);
98 co_await hgetall(conn);
A basic_connection that type erases the executor.
ignore_t ignore
Global ignore object.
std::decay_t< decltype(std::ignore)> ignore_t
Type used to ignore responses.
std::tuple< adapter::result< Ts >... > response
Response with compile-time size.
Configure parameters used by the connection classes.