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