boost_redis 1.4.2
A redis client library
cpp20_intro_tls.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/deferred.hpp>
9#include <boost/asio/use_awaitable.hpp>
10#include <boost/asio/detached.hpp>
11#include <boost/asio/consign.hpp>
12#include <iostream>
13
14#if defined(BOOST_ASIO_HAS_CO_AWAIT)
15
16namespace net = boost::asio;
22
23auto verify_certificate(bool, net::ssl::verify_context&) -> bool
24{
25 std::cout << "set_verify_callback" << std::endl;
26 return true;
27}
28
29auto co_main(config cfg) -> net::awaitable<void>
30{
31 cfg.use_ssl = true;
32 cfg.username = "aedis";
33 cfg.password = "aedis";
34 cfg.addr.host = "db.occase.de";
35 cfg.addr.port = "6380";
36
37 auto conn = std::make_shared<connection>(co_await net::this_coro::executor);
38 conn->async_run(cfg, {}, net::consign(net::detached, conn));
39
40 request req;
41 req.push("PING");
42
43 response<std::string> resp;
44
45 conn->next_layer().set_verify_mode(net::ssl::verify_peer);
46 conn->next_layer().set_verify_callback(verify_certificate);
47
48 co_await conn->async_exec(req, resp, net::deferred);
49 conn->cancel();
50
51 std::cout << "Response: " << std::get<0>(resp).value() << std::endl;
52}
53
54#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)
A basic_connection that type erases the executor.
Definition: connection.hpp:308
Logger class.
Definition: logger.hpp:23
Creates Redis requests.
Definition: request.hpp:46
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