Skip to content

Commit 801f60a

Browse files
committed
Readme improvements.
1 parent c37fcb6 commit 801f60a

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Documentation
2+
# Aedis
33

44
## Overview
55

@@ -50,7 +50,7 @@ that ensures that one operation is cancelled as soon as the other
5050
completes, these functions play the following roles
5151

5252
* `connection::async_exec`: Execute commands (i.e. write the request and reads the response).
53-
* `connection::async_run`: Start read and write operations and remains suspended until the connection is lost.
53+
* `connection::async_run`: Coordinate read and write operations and remains suspended until the connection is lost.
5454

5555
Let us dig in.
5656

@@ -126,7 +126,7 @@ auto run(std::shared_ptr<connection> conn) -> net::awaitable<void>
126126

127127
The definition of `receiver` and `healthy_checker` above can be found
128128
in subscriber.cpp. Adding a loop around `async_run` produces a simple
129-
way to support reconnection _while there are pending operations on the connection_
129+
way to support reconnection _while there are pending operations on the connection_,
130130
for example, to reconnect to the same address
131131

132132
```cpp
@@ -155,7 +155,7 @@ For failover with sentinels see `resolve_with_sentinel.cpp`. At
155155
this point the reasons for why `async_run` was introduced in Aedis
156156
might have become apparent to the reader
157157
158-
* Provide a quick reaction to disconnections and hence faster failovers.
158+
* Provide quick reaction to disconnections and hence faster failovers.
159159
* Support server pushes and requests in the same connection object, concurrently.
160160
* Separate requests, handling of server pushes and reconnection operations.
161161
@@ -171,9 +171,7 @@ like those that may happen when using Asio awaitable operators && and
171171
co_await (conn.async_run(...) && conn.async_exec(...))
172172
```
173173

174-
* Useful when implementing reconnection.
175-
* `async_exec` is responsible for sending the `HELLO` command and
176-
optionally for subscribing to channels.
174+
* Provide a simple way to send HELLO and perform channel subscription.
177175

178176
```cpp
179177
co_await (conn.async_run(...) || conn.async_exec(...))
@@ -203,10 +201,10 @@ co_await (conn.async_run(...) || time.async_wait(...))
203201
co_await (conn.async_exec(...) || conn.async_exec(...) || ... || conn.async_exec(...))
204202
```
205203

206-
* This works but is considered an anti-pattern. Unless
207-
the user has set `aedis::resp3::request::config::coalesce` to
208-
`false`, and he shouldn't, the connection will automatically merge
209-
the individual requests into a single payload anyway.
204+
* This works but is unnecessary. Unless the user has set
205+
`aedis::resp3::request::config::coalesce` to `false`, and he
206+
shouldn't, the connection will automatically merge the individual
207+
requests into a single payload anyway.
210208

211209
<a name="requests"></a>
212210
## Requests

examples/chat_room.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ auto publisher(std::shared_ptr<stream_descriptor> in, std::shared_ptr<connection
4646
}
4747
}
4848

49-
auto subscriber(std::shared_ptr<connection> conn) -> net::awaitable<void>
50-
{
51-
resp3::request req;
52-
req.push("HELLO", 3);
53-
req.push("SUBSCRIBE", "chat-channel");
54-
55-
co_await conn->async_exec(req);
56-
}
57-
5849
// Called from the main function (see main.cpp)
5950
auto async_main() -> net::awaitable<void>
6051
{
@@ -63,9 +54,13 @@ auto async_main() -> net::awaitable<void>
6354
auto stream = std::make_shared<stream_descriptor>(ex, ::dup(STDIN_FILENO));
6455
signal_set sig{ex, SIGINT, SIGTERM};
6556

57+
resp3::request req;
58+
req.push("HELLO", 3);
59+
req.push("SUBSCRIBE", "chat-channel");
60+
6661
co_await connect(conn, "127.0.0.1", "6379");
6762
co_await ((conn->async_run() || publisher(stream, conn) || receiver(conn) ||
68-
healthy_checker(conn) || sig.async_wait()) && subscriber(conn));
63+
healthy_checker(conn) || sig.async_wait()) && conn->async_exec(req));
6964
}
7065

7166
#else // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)

examples/subscriber.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,22 @@ auto receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
4444
}
4545
}
4646

47-
auto subscriber(std::shared_ptr<connection> conn) -> net::awaitable<void>
48-
{
49-
resp3::request req;
50-
req.push("HELLO", 3);
51-
req.push("SUBSCRIBE", "channel");
52-
53-
co_await conn->async_exec(req);
54-
}
55-
5647
auto async_main() -> net::awaitable<void>
5748
{
5849
auto ex = co_await net::this_coro::executor;
5950
auto conn = std::make_shared<connection>(ex);
6051
signal_set sig{ex, SIGINT, SIGTERM};
6152
steady_timer timer{ex};
6253

54+
resp3::request req;
55+
req.push("HELLO", 3);
56+
req.push("SUBSCRIBE", "channel");
57+
6358
// The loop will reconnect on connection lost. To exit type Ctrl-C twice.
6459
for (;;) {
6560
co_await connect(conn, "127.0.0.1", "6379");
6661
co_await ((conn->async_run() || healthy_checker(conn) || sig.async_wait() ||
67-
receiver(conn)) && subscriber(conn));
62+
receiver(conn)) && conn->async_exec(req));
6863

6964
conn->reset_stream();
7065
timer.expires_after(std::chrono::seconds{1});

0 commit comments

Comments
 (0)