22
33Boost.Redis is a high-level [ Redis] ( https://redis.io/ ) client library built on top of
44[ Boost.Asio] ( https://www.boost.org/doc/libs/release/doc/html/boost_asio.html )
5- that implements Redis plain text protocol
5+ that implements the Redis protocol
66[ RESP3] ( https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md ) .
7- It can multiplex any number of client
8- requests, responses, and server pushes onto a single active socket
9- connection to the Redis server. The requirements for using Boost.Redis are:
7+ The requirements for using Boost.Redis are:
108
119* Boost. The library is included in Boost distributions starting with 1.84.
1210* C++17 or higher.
@@ -82,8 +80,9 @@ them are
8280* [Client-side caching](https://redis.io/docs/manual/client-side-caching/)
8381
8482The connection class supports server pushes by means of the
85- `boost::redis::connection::async_receive` function, the coroutine shows how
86- to used it
83+ `boost::redis::connection::async_receive` function, which can be
84+ called in the same connection that is being used to execute commands.
85+ The coroutine below shows how to used it
8786
8887```cpp
8988auto
@@ -92,14 +91,17 @@ receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
9291 request req;
9392 req.push("SUBSCRIBE", "channel");
9493
94+ generic_response resp;
95+ conn->set_receive_response(resp);
96+
9597 // Loop while reconnection is enabled
9698 while (conn->will_reconnect()) {
9799
98100 // Reconnect to channels.
99101 co_await conn->async_exec(req, ignore, net::deferred);
100102
101103 // Loop reading Redis pushes.
102- for (generic_response resp ;;) {
104+ for (;;) {
103105 error_code ec;
104106 co_await conn->async_receive(resp, net::redirect_error(net::use_awaitable, ec));
105107 if (ec)
@@ -108,7 +110,7 @@ receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
108110 // Use the response resp in some way and then clear it.
109111 ...
110112
111- resp.value().clear( );
113+ consume_one(resp );
112114 }
113115 }
114116}
0 commit comments