Skip to content

Commit 3a44450

Browse files
authored
Merge pull request #63 from boostorg/62-let-the-implementation-call-adaptresp-automatically
async_exec accepts response now instead of adapter.
2 parents 7e70cb4 + bfb26f2 commit 3a44450

38 files changed

+228
-232
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concerned with only three library entities
1515
[pipelines](https://redis.io/docs/manual/pipelining/).
1616
* `boost::redis::request`: A container of Redis commands that supports
1717
STL containers and user defined data types.
18-
* `boost::redis::adapt()`: A function that adapts data structures to receive responses.
18+
* `boost::redis::response`: Container of Redis responses.
1919

2020
In the next sections we will cover all those points in detail with
2121
examples. The requirements for using Boost.Redis are
@@ -62,7 +62,7 @@ auto co_main() -> net::awaitable<void>
6262
// The tuple elements will store the responses to each individual
6363
// command. The responses to HELLO and QUIT are being ignored for
6464
// simplicity.
65-
response<ignore, std::map<std::string, std::string>, ignore> resp;
65+
response<ignore_t, std::map<std::string, std::string>, ignore_t> resp;
6666

6767
// Executes the request. See below why we are using operator ||.
6868
co_await (conn.async_run() || conn.async_exec(req, adapt(resp)));
@@ -364,11 +364,11 @@ have as many elements as the request has commands (exceptions below).
364364
It is also necessary that each tuple element is capable of storing the
365365
response to the command it refers to, otherwise an error will occur.
366366
To ignore responses to individual commands in the request use the tag
367-
`boost::redis::ignore`
367+
`boost::redis::ignore_t`
368368

369369
```cpp
370370
// Ignore the second and last responses.
371-
response<std::string, boost::redis::ignore, std::string, boost::redis::ignore>
371+
response<std::string, boost::redis::ignore_t, std::string, boost::redis::ignore_t>
372372
```
373373

374374
The following table provides the resp3-types returned by some Redis
@@ -416,12 +416,12 @@ can be read in the tuple below
416416

417417
```cpp
418418
response<
419-
redis::ignore, // hello
420-
int, // rpush
421-
int, // hset
422-
std::vector<T>, // lrange
423-
std::map<U, V>, // hgetall
424-
std::string // quit
419+
redis::ignore_t, // hello
420+
int, // rpush
421+
int, // hset
422+
std::vector<T>, // lrange
423+
std::map<U, V>, // hgetall
424+
std::string // quit
425425
> resp;
426426
```
427427

@@ -515,10 +515,10 @@ using exec_resp_type =
515515
>;
516516

517517
response<
518-
boost::redis::ignore, // multi
519-
boost::redis::ignore, // get
520-
boost::redis::ignore, // lrange
521-
boost::redis::ignore, // hgetall
518+
boost::redis::ignore_t, // multi
519+
boost::redis::ignore_t, // get
520+
boost::redis::ignore_t, // lrange
521+
boost::redis::ignore_t, // hgetall
522522
exec_resp_type, // exec
523523
> resp;
524524

@@ -868,6 +868,8 @@ Acknowledgement to people that helped shape Boost.Redis
868868
* Moves `boost::redis::resp3::request` to `boost::redis::request`.
869869
* Adds new typedef `boost::redis::response` that should be used instead of `std::tuple`.
870870
* Adds new typedef `boost::redis::generic_response` that should be used instead of `std::vector<resp3::node<std::string>>`.
871+
* Renames `redis::ignore` to `redis::ignore_t`.
872+
* Changes the signature from `async_exec` to receive a `redis::response` instead of an adapter.
871873

872874
### v1.4.0-1
873875

examples/common/common.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ using namespace net::experimental::awaitable_operators;
1616
using resolver = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::resolver>;
1717
using timer_type = net::use_awaitable_t<>::as_default_on_t<net::steady_timer>;
1818
using boost::redis::request;
19-
using boost::redis::adapt;
2019
using boost::redis::operation;
2120

2221
namespace
@@ -35,7 +34,7 @@ auto healthy_checker(std::shared_ptr<connection> conn) -> net::awaitable<void>
3534

3635
for (boost::system::error_code ec;;) {
3736
timer.expires_after(std::chrono::seconds{1});
38-
co_await (conn->async_exec(req, adapt()) || timer.async_wait(redir(ec)));
37+
co_await (conn->async_exec(req) || timer.async_wait(redir(ec)));
3938

4039
if (!ec) {
4140
co_return;

examples/cpp17_intro.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace net = boost::asio;
1313
namespace redis = boost::redis;
14-
using redis::adapt;
1514
using redis::operation;
1615
using redis::request;
1716
using redis::response;
@@ -39,7 +38,7 @@ auto main(int argc, char * argv[]) -> int
3938
req.push("QUIT");
4039

4140
// The response.
42-
response<redis::ignore, std::string, redis::ignore> resp;
41+
response<redis::ignore_t, std::string, redis::ignore_t> resp;
4342

4443
net::io_context ioc;
4544

@@ -75,7 +74,7 @@ auto main(int argc, char * argv[]) -> int
7574
return log(ec, "on_connect: ");
7675

7776
conn.async_run(on_run);
78-
conn.async_exec(req, adapt(resp), on_exec);
77+
conn.async_exec(req, resp, on_exec);
7978
};
8079

8180
// Resolve callback.

examples/cpp17_intro_sync.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616

1717
namespace net = boost::asio;
1818
namespace redis = boost::redis;
19-
using redis::adapt;
2019
using connection = redis::connection;
2120
using boost::redis::request;
2221
using boost::redis::response;
2322

24-
template <class Adapter>
25-
auto exec(std::shared_ptr<connection> conn, request const& req, Adapter adapter)
23+
template <class Response>
24+
auto exec(std::shared_ptr<connection> conn, request const& req, Response& resp)
2625
{
2726
net::dispatch(
2827
conn->get_executor(),
29-
net::deferred([&]() { return conn->async_exec(req, adapter, net::deferred); }))
28+
net::deferred([&]() { return conn->async_exec(req, resp, net::deferred); }))
3029
(net::use_future).get();
3130
}
3231

@@ -67,10 +66,10 @@ auto main(int argc, char * argv[]) -> int
6766
req.push("PING");
6867
req.push("QUIT");
6968

70-
response<boost::redis::ignore, std::string, boost::redis::ignore> resp;
69+
response<boost::redis::ignore_t, std::string, boost::redis::ignore_t> resp;
7170

7271
// Executes commands synchronously.
73-
exec(conn, req, adapt(resp));
72+
exec(conn, req, resp);
7473

7574
std::cout << "Response: " << std::get<1>(resp) << std::endl;
7675

examples/cpp20_chat_room.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace net = boost::asio;
1818
using namespace net::experimental::awaitable_operators;
1919
using stream_descriptor = net::use_awaitable_t<>::as_default_on_t<net::posix::stream_descriptor>;
2020
using signal_set = net::use_awaitable_t<>::as_default_on_t<net::signal_set>;
21-
using boost::redis::adapt;
2221
using boost::redis::request;
2322
using boost::redis::generic_response;
2423

@@ -29,7 +28,7 @@ using boost::redis::generic_response;
2928
auto receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
3029
{
3130
for (generic_response resp;;) {
32-
co_await conn->async_receive(adapt(resp));
31+
co_await conn->async_receive(resp);
3332
std::cout << resp.at(1).value << " " << resp.at(2).value << " " << resp.at(3).value << std::endl;
3433
resp.clear();
3534
}

examples/cpp20_containers.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace net = boost::asio;
1717
namespace redis = boost::redis;
1818
using namespace net::experimental::awaitable_operators;
19-
using redis::adapt;
2019
using boost::redis::request;
2120
using boost::redis::response;
2221

@@ -63,10 +62,10 @@ auto hgetall(std::shared_ptr<connection> conn) -> net::awaitable<void>
6362
req.push("HGETALL", "hset-key");
6463

6564
// Responses as tuple elements.
66-
response<redis::ignore, std::map<std::string, std::string>> resp;
65+
response<redis::ignore_t, std::map<std::string, std::string>> resp;
6766

6867
// Executes the request and reads the response.
69-
co_await conn->async_exec(req, adapt(resp));
68+
co_await conn->async_exec(req, resp);
7069

7170
print(std::get<1>(resp));
7271
}
@@ -82,14 +81,14 @@ auto transaction(std::shared_ptr<connection> conn) -> net::awaitable<void>
8281
req.push("EXEC");
8382

8483
response<
85-
redis::ignore, // hello
86-
redis::ignore, // multi
87-
redis::ignore, // lrange
88-
redis::ignore, // hgetall
84+
redis::ignore_t, // hello
85+
redis::ignore_t, // multi
86+
redis::ignore_t, // lrange
87+
redis::ignore_t, // hgetall
8988
response<std::optional<std::vector<int>>, std::optional<std::map<std::string, std::string>>> // exec
9089
> resp;
9190

92-
co_await conn->async_exec(req, adapt(resp));
91+
co_await conn->async_exec(req, resp);
9392

9493
print(std::get<0>(std::get<4>(resp)).value());
9594
print(std::get<1>(std::get<4>(resp)).value());

examples/cpp20_echo_server.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@ using namespace net::experimental::awaitable_operators;
1515
using tcp_socket = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::socket>;
1616
using tcp_acceptor = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::acceptor>;
1717
using signal_set = net::use_awaitable_t<>::as_default_on_t<net::signal_set>;
18-
using boost::redis::adapt;
1918
using boost::redis::request;
2019
using boost::redis::response;
2120

2221
auto echo_server_session(tcp_socket socket, std::shared_ptr<connection> conn) -> net::awaitable<void>
2322
{
2423
request req;
25-
std::string resp;
24+
response<std::string> resp;
2625

2726
for (std::string buffer;;) {
2827
auto n = co_await net::async_read_until(socket, net::dynamic_buffer(buffer, 1024), "\n");
2928
req.push("PING", buffer);
30-
auto tmp = std::tie(resp);
31-
co_await conn->async_exec(req, adapt(tmp));
32-
co_await net::async_write(socket, net::buffer(resp));
33-
resp.clear();
29+
co_await conn->async_exec(req, resp);
30+
co_await net::async_write(socket, net::buffer(std::get<0>(resp)));
31+
std::get<0>(resp).clear();
3432
req.clear();
3533
buffer.erase(0, n);
3634
}

examples/cpp20_intro.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "common/common.hpp"
1111

1212
namespace net = boost::asio;
13-
using boost::redis::adapt;
1413
using boost::redis::operation;
1514
using boost::redis::request;
1615
using boost::redis::response;
@@ -35,7 +34,7 @@ auto ping(std::shared_ptr<connection> conn) -> net::awaitable<void>
3534
req.push("PING", "Hello world");
3635

3736
response<std::string> resp;
38-
co_await conn->async_exec(req, adapt(resp));
37+
co_await conn->async_exec(req, resp);
3938

4039
std::cout << "PING: " << std::get<0>(resp) << std::endl;
4140
}

examples/cpp20_intro_awaitable_ops.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
namespace net = boost::asio;
1414
using namespace net::experimental::awaitable_operators;
15-
using boost::redis::adapt;
1615
using boost::redis::request;
1716
using boost::redis::response;
1817

@@ -24,11 +23,11 @@ auto co_main(std::string host, std::string port) -> net::awaitable<void>
2423
req.push("PING", "Hello world");
2524
req.push("QUIT");
2625

27-
response<boost::redis::ignore, std::string, boost::redis::ignore> resp;
26+
response<boost::redis::ignore_t, std::string, boost::redis::ignore_t> resp;
2827

2928
auto conn = std::make_shared<connection>(co_await net::this_coro::executor);
3029
co_await connect(conn, host, port);
31-
co_await (conn->async_run() || conn->async_exec(req, adapt(resp)));
30+
co_await (conn->async_run() || conn->async_exec(req, resp));
3231

3332
std::cout << "PING: " << std::get<1>(resp) << std::endl;
3433
}

examples/cpp20_intro_tls.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace net = boost::asio;
2020
namespace redis = boost::redis;
2121
using namespace net::experimental::awaitable_operators;
2222
using resolver = net::use_awaitable_t<>::as_default_on_t<net::ip::tcp::resolver>;
23-
using redis::adapt;
2423
using connection = net::use_awaitable_t<>::as_default_on_t<redis::ssl::connection>;
2524
using boost::redis::request;
2625
using boost::redis::response;
@@ -38,7 +37,7 @@ net::awaitable<void> co_main(std::string, std::string)
3837
req.push("PING");
3938
req.push("QUIT");
4039

41-
response<redis::ignore, std::string, redis::ignore> resp;
40+
response<redis::ignore_t, std::string, redis::ignore_t> resp;
4241

4342
// Resolve
4443
auto ex = co_await net::this_coro::executor;
@@ -52,7 +51,7 @@ net::awaitable<void> co_main(std::string, std::string)
5251

5352
co_await net::async_connect(conn.lowest_layer(), endpoints);
5453
co_await conn.next_layer().async_handshake(net::ssl::stream_base::client);
55-
co_await (conn.async_run() || conn.async_exec(req, adapt(resp)));
54+
co_await (conn.async_run() || conn.async_exec(req, resp));
5655

5756
std::cout << "Response: " << std::get<1>(resp) << std::endl;
5857
}

0 commit comments

Comments
 (0)