@@ -9,11 +9,16 @@ It makes communication with a Redis server easy by hiding low-level
9
9
Asio-related code away from the user, which, in the majority of the
10
10
cases will be concerned with only three library entities
11
11
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.
14
18
* ` aedis::adapt() ` : A function that adapts data structures to receive responses.
15
19
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
17
22
18
23
* Boost 1.80 or greater.
19
24
* C++17 minimum.
@@ -54,9 +59,9 @@ auto co_main() -> net::awaitable<void>
54
59
req.push("HGETALL", "hset-key");
55
60
req.push("QUIT");
56
61
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.
60
65
std::tuple<ignore, std::map<std::string, std::string>, ignore> resp;
61
66
62
67
// Executes the request. See below why we are using operator ||.
@@ -65,10 +70,11 @@ auto co_main() -> net::awaitable<void>
65
70
}
66
71
```
67
72
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
72
78
73
79
* ` connection::async_exec ` : Execute commands by queuing the request
74
80
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
85
91
* cpp20_intro.cpp: Does not use awaitable operators.
86
92
* cpp20_intro_tls.cpp: Communicates over TLS.
87
93
* 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 ` .
88
96
89
97
For performance reasons we will usually want to perform multiple
90
98
requests with the same connection. We can do this in the example above
@@ -141,8 +149,7 @@ auto co_main() -> net::awaitable<void>
141
149
142
150
With this separation, it is now easy to incorporate other long-running
143
151
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)
146
153
147
154
```cpp
148
155
auto run(std::shared_ptr<connection> conn) -> net::awaitable<void>
@@ -219,11 +226,11 @@ auto run(std::shared_ptr<connection> conn) -> net::awaitable<void>
219
226
220
227
This feature results in considerable simplification of backend code
221
228
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
223
230
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
225
232
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.
227
234
228
235
### Cancellation
229
236
@@ -246,7 +253,9 @@ co_await (conn.async_exec(...) || time.async_wait(...))
246
253
247
254
* Provides a way to limit how long the execution of a single request
248
255
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
250
259
per request timeout, see cpp20_subscriber.cpp for an example.
251
260
252
261
```cpp
@@ -601,6 +610,9 @@ and other data structures in general.
601
610
602
611
The examples below show how to use the features discussed so far
603
612
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.
604
616
* cpp20_containers.cpp: Shows how to send and receive STL containers and how to use transactions.
605
617
* cpp20_serialization.cpp: Shows how to serialize types using Boost.Json.
606
618
* 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
609
621
* cpp20_chat_room.cpp: A command line chat built on Redis pubsub.
610
622
* cpp20_low_level_async.cpp: Sends a ping asynchronously using the low-level API.
611
623
* 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 ` .
612
626
613
627
To avoid repetition code that is common to some examples has been
614
628
grouped in common.hpp. The main function used in some async examples
0 commit comments