Boost.Redis: example/cpp20_intro_tls.cpp Source File

Boost.Redis 1.84.0 A redis client library

Loading...
Searching...
No Matches
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 asio = boost::asio;
17using boost::redis::request;
18using boost::redis::response;
19using boost::redis::config;
20using boost::redis::logger;
21using boost::redis::connection;
22
23auto verify_certificate(bool, asio::ssl::verify_context&) -> bool
24{
25 std::cout << "set_verify_callback" << std::endl;
26 return true;
27}
28
29auto co_main(config cfg) -> asio::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 asio::this_coro::executor);
38 conn->async_run(cfg, {}, asio::consign(asio::detached, conn));
39
40 request req;
41 req.push("PING");
42
43 response<std::string> resp;
44
45 conn->next_layer().set_verify_mode(asio::ssl::verify_peer);
46 conn->next_layer().set_verify_callback(verify_certificate);
47
48 co_await conn->async_exec(req, resp, asio::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)
boost::redis::connection
A basic_connection that type erases the executor.
Definition: connection.hpp:339
boost::redis::logger
Logger class.
Definition: logger.hpp:27
boost::redis::request
Creates Redis requests.
Definition: request.hpp:46
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