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