Boost.Redis: example/cpp17_intro.cpp Source File

Boost.Redis 1.84.0 A redis client library

Loading...
Searching...
No Matches
cpp17_intro.cpp
1/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com)
2 *
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE.txt)
5 */
6
7#include <boost/redis/connection.hpp>
8#include <boost/asio/detached.hpp>
9#include <iostream>
10
11namespace asio = boost::asio;
12using boost::redis::connection;
13using boost::redis::request;
14using boost::redis::response;
15using boost::redis::config;
16
17auto main(int argc, char * argv[]) -> int
18{
19 try {
20 config cfg;
21
22 if (argc == 3) {
23 cfg.addr.host = argv[1];
24 cfg.addr.port = argv[2];
25 }
26
27 request req;
28 req.push("PING", "Hello world");
29
30 response<std::string> resp;
31
32 asio::io_context ioc;
33 connection conn{ioc};
34
35 conn.async_run(cfg, {}, asio::detached);
36
37 conn.async_exec(req, resp, [&](auto ec, auto) {
38 if (!ec)
39 std::cout << "PING: " << std::get<0>(resp).value() << std::endl;
40 conn.cancel();
41 });
42
43 ioc.run();
44
45 } catch (std::exception const& e) {
46 std::cerr << "Error: " << e.what() << std::endl;
47 return 1;
48 }
49}
50
boost::redis::connection
A basic_connection that type erases the executor.
Definition connection.hpp:1231
boost::redis::connection::async_run
auto async_run(config const &cfg, logger l, CompletionToken &&token={})
Calls boost::redis::basic_connection::async_run.
Definition connection.hpp:1256
boost::redis::request
Creates Redis requests.
Definition request.hpp:46
boost::redis::request::push
void push(std::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
Definition request.hpp:146
boost::redis::config::addr
address addr
Address of the Redis server.
Definition config.hpp:35
boost::redis::address::port
std::string port
Redis port.
Definition config.hpp:24
boost::redis::address::host
std::string host
Redis host.
Definition config.hpp:22
boost::redis::response
std::tuple< adapter::result< Ts >... > response
Response with compile-time size.
Definition response.hpp:25
boost::redis::config
Configure parameters used by the connection classes.
Definition config.hpp:30