Loading...
Searching...
No Matches
main.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/config.hpp>
8#include <boost/redis/connection.hpp>
9
10#include <boost/asio/co_spawn.hpp>
11#include <boost/asio/io_context.hpp>
12#include <boost/asio/use_awaitable.hpp>
13
14#include <iostream>
15
16namespace asio = boost::asio;
19
20#if defined(BOOST_ASIO_HAS_CO_AWAIT)
21
22extern asio::awaitable<void> co_main(config);
23
24auto main(int argc, char* argv[]) -> int
25{
26 try {
27 config cfg;
28
29 if (argc == 3) {
30 cfg.addr.host = argv[1];
31 cfg.addr.port = argv[2];
32 }
33
34 asio::io_context ioc;
35 asio::co_spawn(ioc, co_main(cfg), [](std::exception_ptr p) {
36 if (p)
37 std::rethrow_exception(p);
38 });
39 ioc.run();
40
41 } catch (std::exception const& e) {
42 std::cerr << "(main) " << e.what() << std::endl;
43 return 1;
44 }
45}
46
47#else // defined(BOOST_ASIO_HAS_CO_AWAIT)
48
49auto main() -> int
50{
51 std::cout << "Requires coroutine support." << std::endl;
52 return 0;
53}
54
55#endif // defined(BOOST_ASIO_HAS_CO_AWAIT)
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
Configure parameters used by the connection classes.
Definition config.hpp:30
Defines logging configuration.
Definition logger.hpp:20