boost_redis 1.4.2
A redis client library
cpp17_intro_sync.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 "sync_connection.hpp"
8
9#include <string>
10#include <iostream>
11
12namespace net = boost::asio;
13using boost::redis::sync_connection;
17
18auto main(int argc, char * argv[]) -> int
19{
20 try {
21 config cfg;
22
23 if (argc == 3) {
24 cfg.addr.host = argv[1];
25 cfg.addr.port = argv[2];
26 }
27
28 sync_connection conn;
29 conn.run(cfg);
30
31 request req;
32 req.push("PING");
33
34 response<std::string> resp;
35
36 conn.exec(req, resp);
37 conn.stop();
38
39 std::cout << "Response: " << std::get<0>(resp).value() << std::endl;
40
41 } catch (std::exception const& e) {
42 std::cerr << e.what() << std::endl;
43 }
44}
Creates Redis requests.
Definition: request.hpp:46
void push(std::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
Definition: request.hpp:141
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
std::tuple< adapter::result< Ts >... > response
Response with compile-time size.
Definition: response.hpp:23
Configure parameters used by the connection classes.
Definition: config.hpp:30