boost_redis 1.4.2
A redis client library
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 net = boost::asio;
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 net::io_context ioc;
33 connection conn{ioc};
34
35 conn.async_run(cfg, {}, net::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
A basic_connection that type erases the executor.
Definition: connection.hpp:308
auto async_run(config const &cfg, logger l, CompletionToken token)
Calls boost::redis::basic_connection::async_run.
Definition: connection.hpp:333
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:141
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:23
Configure parameters used by the connection classes.
Definition: config.hpp:30