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
9#include <boost/asio/detached.hpp>
10
11#include <iostream>
12
13namespace asio = boost::asio;
18
19auto main(int argc, char* argv[]) -> int
20{
21 try {
22 config cfg;
23
24 if (argc == 3) {
25 cfg.addr.host = argv[1];
26 cfg.addr.port = argv[2];
27 }
28
29 request req;
30 req.push("PING", "Hello world");
31
33
34 asio::io_context ioc;
35 connection conn{ioc};
36
37 conn.async_run(cfg, asio::detached);
38
39 conn.async_exec(req, resp, [&](auto ec, auto) {
40 if (!ec)
41 std::cout << "PING: " << std::get<0>(resp).value() << std::endl;
42 conn.cancel();
43 });
44
45 ioc.run();
46
47 } catch (std::exception const& e) {
48 std::cerr << "Error: " << e.what() << std::endl;
49 return 1;
50 }
51}
A basic_connection that type erases the executor.
Creates Redis requests.
Definition request.hpp:46
void push(std::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
Definition request.hpp:147
address addr
Address of the Redis server.
Definition config.hpp:35
std::string port
Redis port.
Definition config.hpp:24
std::string host
Redis host.
Definition config.hpp:22
std::tuple< adapter::result< Ts >... > response
Response with compile-time size.
Definition response.hpp:25
Configure parameters used by the connection classes.
Definition config.hpp:30