Boost.Redis: example/main.cpp Source File

Boost.Redis 1.84.0 A redis client library

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/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 asio = boost::asio;
15using boost::redis::config;
16using boost::redis::logger;
17
18#if defined(BOOST_ASIO_HAS_CO_AWAIT)
19
20extern asio::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 asio::io_context ioc;
33 asio::co_spawn(ioc, 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)
boost::redis::logger
Logger class.
Definition logger.hpp:27
boost::redis::config::addr
address addr
Address of the Redis server.
Definition config.hpp:35
boost::redis::address::port
std::string port
Redis port.
Definition config.hpp:24
boost::redis::address::host
std::string host
Redis host.
Definition config.hpp:22
boost::redis::config
Configure parameters used by the connection classes.
Definition config.hpp:30