Boost.Redis 1.84.0 A redis client library

Loading...
Searching...
No Matches
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
12 using boost::redis::sync_connection;
13 using boost::redis::request;
14 using boost::redis::response;
15 using boost::redis::config;
16
17 auto main(int argc, char * argv[]) -> int
18{
19 try {
20 config cfg;
21
22 if (argc == 3) {
23 cfg.addr.host = argv[1];
24 cfg.addr.port = argv[2];
25 }
26
27 sync_connection conn;
28 conn.run(cfg);
29
30 request req;
31 req.push("PING");
32
33 response<std::string> resp;
34
35 conn.exec(req, resp);
36 conn.stop();
37
38 std::cout << "Response: " << std::get<0>(resp).value() << std::endl;
39
40 } catch (std::exception const& e) {
41 std::cerr << e.what() << std::endl;
42 }
43}
boost::redis::request
Creates Redis requests.
Definition: request.hpp:46
boost::redis::request::push
void push(std::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
Definition: request.hpp:146
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::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