Skip to content

Commit 15deaa6

Browse files
committed
Doc improvements.
1 parent bb8ff90 commit 15deaa6

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

README.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ It makes communication with a Redis server easy by hiding low-level
99
Asio-related code away from the user, which, in the majority of the
1010
cases will be concerned with only three library entities
1111

12-
* `aedis::connection`: A connection to the Redis server.
13-
* `aedis::resp3::request`: A container of Redis commands.
12+
* `aedis::connection`: A connection to the Redis server that
13+
implements automatic
14+
[pipelining](https://redis.io/docs/manual/pipelining/) and which can
15+
handle requests and server pushes concurrently.
16+
* `aedis::resp3::request`: A container of Redis commands that supports
17+
STL containers and user defined data types.
1418
* `aedis::adapt()`: A function that adapts data structures to receive responses.
1519

16-
The requirements for using Aedis are
20+
In the next sections we will cover all those points in detail and with
21+
examples. The requirements for using Aedis are
1722

1823
* Boost 1.80 or greater.
1924
* C++17 minimum.
@@ -54,9 +59,9 @@ auto co_main() -> net::awaitable<void>
5459
req.push("HGETALL", "hset-key");
5560
req.push("QUIT");
5661

57-
// The tuple elements below will store the responses to each
58-
// individual command. The responses to HELLO and QUIT are being
59-
// ignored for simplicity.
62+
// The tuple elements will store the responses to each individual
63+
// command. The responses to HELLO and QUIT are being ignored for
64+
// simplicity.
6065
std::tuple<ignore, std::map<std::string, std::string>, ignore> resp;
6166

6267
// Executes the request. See below why we are using operator ||.
@@ -65,10 +70,11 @@ auto co_main() -> net::awaitable<void>
6570
}
6671
```
6772

68-
The example above uses the Asio awaitable `operator ||` to launch
69-
`connection::async_exec` and `connection::async_run` in parallel and
70-
to cancel one of the operations when the other completes. The role
71-
played by these functions are
73+
The example above uses the Asio awaitable `operator ||` to compose
74+
`connection::async_exec` and `connection::async_run` in a single
75+
operation we can `co_await` on. It also provides cancelation one of
76+
the operations when the other completes. The role played by these
77+
functions are
7278

7379
* `connection::async_exec`: Execute commands by queuing the request
7480
for writing and wait for the response sent back by
@@ -85,6 +91,8 @@ The example above is also available in other programming styles for comparison
8591
* cpp20_intro.cpp: Does not use awaitable operators.
8692
* cpp20_intro_tls.cpp: Communicates over TLS.
8793
* cpp17_intro.cpp: Uses callbacks and requires C++17.
94+
* cpp17_intro_sync.cpp: Runs `async_run` in a separate thread and
95+
performs synchronous calls to `async_exec`.
8896

8997
For performance reasons we will usually want to perform multiple
9098
requests with the same connection. We can do this in the example above
@@ -141,8 +149,7 @@ auto co_main() -> net::awaitable<void>
141149
142150
With this separation, it is now easy to incorporate other long-running
143151
operations in our application, for example, the run coroutine below
144-
adds signal handling and a healthy checker (see cpp20_echo_server.cpp
145-
for example)
152+
adds signal handling and a healthy checker (see cpp20_echo_server.cpp)
146153
147154
```cpp
148155
auto run(std::shared_ptr<connection> conn) -> net::awaitable<void>
@@ -219,11 +226,11 @@ auto run(std::shared_ptr<connection> conn) -> net::awaitable<void>
219226
220227
This feature results in considerable simplification of backend code
221228
and makes it easier to write failover-safe applications. For example,
222-
a HTTP server might have a 100 sessions communicating with Redis at
229+
a Websocket server might have a 10k sessions communicating with Redis at
223230
the time the connection is lost (or maybe killed by the server admin
224-
to force a failover). It would be annoying if each individual section
231+
to force a failover). It would be concerning if each individual section
225232
were to throw exceptions and handle error. With the pattern shown
226-
above the only place that has to managed is the run function.
233+
above the only place that has to manage the error is the run function.
227234
228235
### Cancellation
229236
@@ -246,7 +253,9 @@ co_await (conn.async_exec(...) || time.async_wait(...))
246253
247254
* Provides a way to limit how long the execution of a single request
248255
should last.
249-
* WARNING: It is usually a better idea to have a healthy checker than adding
256+
* WARNING: If the timer fires after the request has been sent but before the
257+
response has been received, the connection will be closed.
258+
* It is usually a better idea to have a healthy checker than adding
250259
per request timeout, see cpp20_subscriber.cpp for an example.
251260
252261
```cpp
@@ -601,6 +610,9 @@ and other data structures in general.
601610

602611
The examples below show how to use the features discussed so far
603612

613+
* cpp20_intro_awaitable_ops.cpp: The version shown above.
614+
* cpp20_intro.cpp: Does not use awaitable operators.
615+
* cpp20_intro_tls.cpp: Communicates over TLS.
604616
* cpp20_containers.cpp: Shows how to send and receive STL containers and how to use transactions.
605617
* cpp20_serialization.cpp: Shows how to serialize types using Boost.Json.
606618
* cpp20_resolve_with_sentinel.cpp: Shows how to resolve a master address using sentinels.
@@ -609,6 +621,8 @@ The examples below show how to use the features discussed so far
609621
* cpp20_chat_room.cpp: A command line chat built on Redis pubsub.
610622
* cpp20_low_level_async.cpp: Sends a ping asynchronously using the low-level API.
611623
* cpp17_low_level_sync.cpp: Sends a ping synchronously using the low-level API.
624+
* cpp17_intro.cpp: Uses callbacks and requires C++17.
625+
* cpp17_intro_sync.cpp: Runs `async_run` in a separate thread and performs synchronous calls to `async_exec`.
612626

613627
To avoid repetition code that is common to some examples has been
614628
grouped in common.hpp. The main function used in some async examples

examples/cpp17_intro_sync.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,16 @@ auto main(int argc, char * argv[]) -> int
4545
net::io_context ioc{1};
4646

4747
auto conn = std::make_shared<connection>(ioc);
48+
49+
// Resolves the address
4850
net::ip::tcp::resolver resv{ioc};
4951
auto const res = resv.resolve(host, port);
52+
53+
// Connect to Redis
5054
net::connect(conn->next_layer(), res);
55+
56+
// Starts a thread that will can io_context::run on which
57+
// the connection will run.
5158
std::thread t{[conn, &ioc]() {
5259
conn->async_run(logger);
5360
ioc.run();
@@ -59,6 +66,8 @@ auto main(int argc, char * argv[]) -> int
5966
req.push("QUIT");
6067

6168
std::tuple<aedis::ignore, std::string, aedis::ignore> resp;
69+
70+
// Executes commands synchronously.
6271
exec(conn, req, adapt(resp));
6372

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

0 commit comments

Comments
 (0)