@@ -16,15 +16,21 @@ Some of its distinctive features are
16
16
* Back pressure, cancellation and low latency.
17
17
18
18
In addition to that, Aedis hides most of the low-level Asio code away
19
- from the user. For example, the coroutine below retrieves Redis hashes
19
+ from the user, which in the majority of the case will be concerned
20
+ with three library entities
21
+
22
+ * ` aedis::resp3::request ` : A container of Redis commands.
23
+ * ` aedis::adapt() ` : A function that adapts data structures to receive Redis responses.
24
+ * ` aedis::connection ` : A connection to the Redis server.
25
+
26
+ For example, the coroutine below reads Redis [ hashes] ( https://redis.io/docs/data-types/hashes/ )
20
27
in a ` std::map ` and quits the connection (see containers.cpp)
21
28
22
29
``` cpp
23
30
auto hgetall (std::shared_ptr<connection > conn) -> net::awaitable<void >
24
31
{
25
32
// A request contains multiple Redis commands.
26
33
request req;
27
- req.get_config().cancel_on_connection_lost = true;
28
34
req.push("HELLO", 3);
29
35
req.push("HGETALL", "hset-key");
30
36
req.push("QUIT");
@@ -39,11 +45,10 @@ auto hgetall(std::shared_ptr<connection> conn) -> net::awaitable<void>
39
45
}
40
46
```
41
47
42
- The execution of `connection::async_exec` as shown above is
43
- triggered by the `connection::async_run` member function, which is
44
- required to be running concurrently for as long as the connection
45
- stands. For example, the code below uses a short-lived connection to
46
- execute the coroutine above
48
+ The execution of `connection::async_exec` as shown above must
49
+ still be triggered by the `connection::async_run` member function. For
50
+ example, the code below uses a short-lived connection to execute the
51
+ coroutine above
47
52
48
53
```cpp
49
54
net::awaitable<void> async_main()
@@ -53,7 +58,7 @@ net::awaitable<void> async_main()
53
58
// Resolves and connects (from examples/common.hpp to avoid vebosity)
54
59
co_await connect(conn, "127.0.0.1", "6379");
55
60
56
- // Runs and executes the request .
61
+ // Runs hgetall (previous example) .
57
62
co_await (conn->async_run() || hgetall(conn));
58
63
}
59
64
```
@@ -67,32 +72,25 @@ reading from the socket. The reationale behind this design is
67
72
* Support server pushes and requests in the same connection object,
68
73
concurrently.
69
74
70
- In the following sections we will discuss with more details the main
71
- code entities Aedis users are concerned with, namely
72
-
73
- * ` aedis::resp3::request ` : A container of Redis commands.
74
- * ` aedis::adapt() ` : A function that adapts data structures to receive Redis responses.
75
- * ` aedis::connection ` : A connection to the Redis server.
76
-
77
- before that however, users might find it helpful to skim over the
78
- examples, to gain a better feeling about the library capabilities.
75
+ Before we see with more detail how connections, requests and responses
76
+ work, users might find it helpful to skim over the examples, to gain a
77
+ better feeling about the library capabilities.
79
78
80
79
* intro.cpp: The Aedis hello-world program. Sends one command to Redis and quits the connection.
81
80
* intro_tls.cpp: Same as intro.cpp but over TLS.
81
+ * intro_sync.cpp: Shows how to use the conneciton class synchronously.
82
82
* containers.cpp: Shows how to send and receive STL containers and how to use transactions.
83
83
* serialization.cpp: Shows how to serialize types using Boost.Json.
84
84
* resolve_with_sentinel.cpp: Shows how to resolve a master address using sentinels.
85
85
* subscriber.cpp: Shows how to implement pubsub with reconnection re-subscription.
86
86
* echo_server.cpp: A simple TCP echo server.
87
87
* chat_room.cpp: A command line chat built on Redis pubsub.
88
-
89
- The next two examples uses the Aedis low-level API
90
-
91
- * low_level_sync.cpp: Sends a ping synchronously.
92
- * low_level_async.cpp: Sends a ping asynchronously
88
+ * low_level_sync.cpp: Sends a ping synchronously using the low-level API.
89
+ * low_level_async.cpp: Sends a ping asynchronously using the low-level API.
93
90
94
91
To avoid repetition code that is common to all examples have been
95
- grouped in common.hpp.
92
+ grouped in common.hpp. The main function is defined in main.cpp and
93
+ used by all examples.
96
94
97
95
<a name =" requests " ></a >
98
96
### Requests
@@ -498,7 +496,7 @@ auto async_main() -> net::awaitable<void>
498
496
It is important to emphasize that Redis servers use the old
499
497
communication protocol RESP2 by default, therefore it is necessary to
500
498
send a ` HELLO 3 ` command everytime a connection is established.
501
- Another common scenarios for reconnection is, for example, a failover
499
+ Another common scenario for reconnection is, for example, a failover
502
500
with sentinels, covered in ` resolve_with_sentinel.cpp ` example.
503
501
504
502
#### Execute
@@ -613,7 +611,7 @@ co_await (conn.async_exec(...) || time.async_wait(...))
613
611
should last.
614
612
* The cancellation will be ignored if the request has already
615
613
been written to the socket.
616
- * It is usually a better idea to have a healthy checker that adding
614
+ * It is usually a better idea to have a healthy checker than adding
617
615
per request timeout, see subscriber.cpp for an example.
618
616
619
617
```cpp
0 commit comments