Skip to content

Commit 11807c8

Browse files
committed
Improves documentations of the connection class.
1 parent 24a215d commit 11807c8

File tree

10 files changed

+160
-158
lines changed

10 files changed

+160
-158
lines changed

CHANGELOG.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Changelog
22

3-
## master
3+
## v1.0.0
44

55
* Adds experimental cmake support for windows users.
66

7-
* Adds new class `sync` that wraps a `connection` and offers a
8-
thread-safe synchronous API. All free functions from the `sync.hpp`
9-
are now member functions of the `sync` class.
7+
* Adds new class `aedis::sync` that wraps an `aedis::connection` in
8+
a thread-safe and synchronous API. All free functions from the
9+
`sync.hpp` are now member functions of `aedis::sync`.
1010

11-
* Split `connection::async_receive_event` in two functions, one to
12-
receive events and another for server side pushes.
11+
* Split `aedis::connection::async_receive_event` in two functions, one
12+
to receive events and another for server side pushes, see
13+
`aedis::connection::async_receive_push`.
1314

1415
* Removes collision between `aedis::adapter::adapt` and
1516
`aedis::adapt`.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14)
55

66
project(
77
Aedis
8-
VERSION 0.3.0
8+
VERSION 1.0.0
99
DESCRIPTION "An async redis client designed for performance and scalability"
1010
HOMEPAGE_URL "https://mzimbres.github.io/aedis"
1111
LANGUAGES CXX

INSTALL

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ Distributed under the [Boost Software License, Version 1.0](http://www.boost.org
1414

1515
* See the official github-pages for documentation: https://mzimbres.github.io/aedis
1616

17+
### Installation
18+
19+
See https://mzimbres.github.io/aedis/#using-aedis
20+

benchmarks/benchmarks.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,3 @@ The code used in the benchmarks can be found at
8585
## Running the benchmarks
8686

8787
Run one of the echo-server programs in one terminal and the [echo-server-client](https://github.com/mzimbres/aedis/blob/42880e788bec6020dd018194075a211ad9f339e8/benchmarks/cpp/asio/echo_server_client.cpp) in another.
88-
89-
## Contributing
90-
91-
If your spot any performance improvement in any of the example or
92-
would like to include other clients, please open a PR and I will
93-
gladly merge it.

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AC_PREREQ([2.69])
2-
AC_INIT([Aedis], [0.3.0], [[email protected]])
2+
AC_INIT([Aedis], [1.0.0], [[email protected]])
33
AC_CONFIG_MACRO_DIR([m4])
44
AC_CONFIG_HEADERS([config.h])
55
AC_CONFIG_SRCDIR(include/aedis.hpp)

include/aedis.hpp

Lines changed: 51 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
2323
Aedis is a high-level [Redis](https://redis.io/) client library
2424
built on top of
25-
[Asio](https://www.boost.org/doc/libs/release/doc/html/boost_asio.html),
26-
some of its distinctive features are
25+
[Asio](https://www.boost.org/doc/libs/release/doc/html/boost_asio.html).
26+
Some of its distinctive features are
2727
2828
\li Support for the latest version of the Redis communication protocol [RESP3](https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md).
2929
\li First class support for STL containers and C++ built-in types.
3030
\li Serialization and deserialization of your own data types.
3131
\li Healthy checks, back pressure and low latency.
3232
\li Hides most of the low level asynchronous operations away from the user.
3333
34-
Let us start with an overview of asynchronous code.
34+
Let us have a look a some code snippets
3535
3636
@subsection Async
3737
38-
The code below sends a ping command to Redis (see intro.cpp)
38+
The code below sends a ping command to Redis and quits (see intro.cpp)
3939
4040
@code
4141
int main()
@@ -56,9 +56,9 @@
5656
}
5757
@endcode
5858
59-
The connection class maintains a healthy connection with
60-
Redis over which users can execute their commands, without any
61-
need of queuing. For example, to execute more than one command
59+
The connection class maintains a healthy connection with Redis
60+
over which users can execute their commands, without any need of
61+
queuing. For example, to execute more than one request
6262
6363
@code
6464
int main()
@@ -78,7 +78,7 @@
7878
}
7979
@endcode
8080
81-
The `async_exec` functions above can be called from different
81+
The `connection::async_exec` functions above can be called from different
8282
places in the code without knowing about each other, see for
8383
example echo_server.cpp. Server-side pushes are supported on the
8484
same connection where commands are executed, a typical subscriber
@@ -88,55 +88,42 @@
8888
@code
8989
net::awaitable<void> reader(std::shared_ptr<connection> db)
9090
{
91-
request req;
92-
req.push("SUBSCRIBE", "channel");
93-
9491
for (std::vector<node_type> resp;;) {
95-
auto ev = co_await db->async_receive_event(aedis::adapt(resp));
96-
97-
switch (ev) {
98-
case connection::event::push:
99-
// Use resp and clear it.
100-
resp.clear();
101-
break;
102-
103-
default:;
104-
}
92+
co_await db->async_receive_event(adapt(resp));
93+
// Use resp and clear it.
94+
resp.clear();
10595
}
10696
}
10797
@endcode
10898
10999
@subsection Sync
110100
111-
The `connection` class is async-only, many users however need to
112-
interact with it synchronously, this is also supported by Aedis as long
113-
as this interaction occurs across threads, for example (see
114-
intro_sync.cpp)
101+
The `connection` class offers only an asynchronous API.
102+
Synchronous communications with redis is provided by the `aedis::sync`
103+
wrapper class. (see intro_sync.cpp)
115104
116105
@code
117106
int main()
118107
{
119-
try {
120-
net::io_context ioc{1};
121-
connection conn{ioc};
122-
123-
std::thread thread{[&]() {
124-
conn.async_run(net::detached);
125-
ioc.run();
126-
}};
127-
128-
request req;
129-
req.push("PING");
130-
req.push("QUIT");
131-
132-
std::tuple<std::string, aedis::ignore> resp;
133-
exec(conn, req, adapt(resp));
134-
thread.join();
135-
136-
std::cout << "Response: " << std::get<0>(resp) << std::endl;
137-
} catch (std::exception const& e) {
138-
std::cerr << e.what() << std::endl;
139-
}
108+
net::io_context ioc{1};
109+
auto work = net::make_work_guard(ioc);
110+
std::thread t1{[&]() { ioc.run(); }};
111+
112+
sync<connection> conn{work.get_executor()};
113+
std::thread t2{[&]() { boost::system::error_code ec; conn.run(ec); }};
114+
115+
request req;
116+
req.push("PING");
117+
req.push("QUIT");
118+
119+
std::tuple<std::string, aedis::ignore> resp;
120+
conn.exec(req, adapt(resp));
121+
std::cout << "Response: " << std::get<0>(resp) << std::endl;
122+
123+
work.reset();
124+
125+
t1.join();
126+
t2.join();
140127
}
141128
@endcode
142129
@@ -151,23 +138,27 @@
151138
For a simple installation run
152139
153140
```
154-
# Clone the repository and checkout the lastest release tag.
155-
$ git clone --branch v0.3.0 https://github.com/mzimbres/aedis.git
141+
$ git clone --branch v1.0.0 https://github.com/mzimbres/aedis.git
156142
$ cd aedis
157143
158-
# Build an example
144+
# Option 1: Direct compilation.
159145
$ g++ -std=c++17 -pthread examples/intro.cpp -I./include -I/path/boost_1_79_0/include/
146+
147+
# Option 2: Use cmake.
148+
$ BOOST_ROOT=/opt/boost_1_79_0/ cmake -DCMAKE_CXX_FLAGS=-std=c++20 .
160149
```
161150
151+
@note CMake support is still experimental.
152+
162153
For a proper full installation on the system run
163154
164155
```
165156
# Download and unpack the latest release
166-
$ wget https://github.com/mzimbres/aedis/releases/download/v0.3.0/aedis-0.3.0.tar.gz
167-
$ tar -xzvf aedis-0.3.0.tar.gz
157+
$ wget https://github.com/mzimbres/aedis/releases/download/v1.0.0/aedis-1.0.0.tar.gz
158+
$ tar -xzvf aedis-1.0.0.tar.gz
168159
169160
# Configure, build and install
170-
$ CXXFLAGS="-std=c++17" ./configure --prefix=/opt/aedis-0.3.0 --with-boost=/opt/boost_1_78_0
161+
$ CXXFLAGS="-std=c++17" ./configure --prefix=/opt/aedis-1.0.0 --with-boost=/opt/boost_1_78_0
171162
$ sudo make install
172163
```
173164
@@ -177,12 +168,6 @@
177168
$ make
178169
```
179170
180-
There is also experimental support cmake, for example
181-
182-
@code
183-
$ BOOST_ROOT=/opt/boost_1_79_0/ cmake -DCMAKE_CXX_FLAGS=-std=c++20 .
184-
@endcode
185-
186171
@subsubsection using_aedis Using Aedis
187172
188173
When writing you own applications include the following header
@@ -380,7 +365,7 @@
380365
381366
To read the response to transactions we have to observe that Redis
382367
queues the commands as they arrive and sends the responses back to
383-
the user in a single array, in the response to the @c exec command.
368+
the user as an array, in the response to the @c exec command.
384369
For example, to read the response to the this request
385370
386371
@code
@@ -397,7 +382,7 @@
397382
using aedis::ignore;
398383
using boost::optional;
399384
400-
using tresp_type =
385+
using exec_resp_type =
401386
std::tuple<
402387
optional<std::string>, // get
403388
optional<std::vector<std::string>>, // lrange
@@ -409,7 +394,7 @@
409394
ignore, // get
410395
ignore, // lrange
411396
ignore, // hgetall
412-
tresp_type, // exec
397+
exec_resp_type, // exec
413398
> resp;
414399
415400
co_await db->async_exec(req, adapt(resp));
@@ -443,7 +428,7 @@
443428
There are cases where responses to Redis
444429
commands won't fit in the model presented above, some examples are
445430
446-
@li Commands (like \c set) whose response don't have a fixed
431+
@li Commands (like \c set) whose responses don't have a fixed
447432
RESP3 type. Expecting an \c int and receiving a blob-string
448433
will result in error.
449434
@li RESP3 aggregates that contain nested aggregates can't be read in STL containers.
@@ -487,14 +472,14 @@
487472
@endcode
488473
489474
For example, suppose we want to retrieve a hash data structure
490-
from Redis with \c hgetall, some of the options are
475+
from Redis with `HGETALL`, some of the options are
491476
492477
@li \c std::vector<node<std::string>: Works always.
493478
@li \c std::vector<std::string>: Efficient and flat, all elements as string.
494479
@li \c std::map<std::string, std::string>: Efficient if you need the data as a \c std::map
495480
@li \c std::map<U, V>: Efficient if you are storing serialized data. Avoids temporaries and requires \c from_bulk for \c U and \c V.
496481
497-
In addition to the above users can also use unordered versions of the containers. The same reasoning also applies to sets e.g. \c smembers.
482+
In addition to the above users can also use unordered versions of the containers. The same reasoning also applies to sets e.g. `SMEMBERS`.
498483
499484
\section examples Examples
500485
@@ -503,8 +488,8 @@
503488
@li intro.cpp: Basic steps with Aedis.
504489
@li intro_sync.cpp: Synchronous version of intro.cpp.
505490
@li containers.cpp: Shows how to send and receive stl containers.
506-
@li serialization.cpp: Shows the \c request support to serialization of user types.
507-
@li subscriber.cpp: Shows how to subscribe to a channel and how to reconnect when connection is lost.
491+
@li serialization.cpp: Shows how to serialize your own types.
492+
@li subscriber.cpp: Shows how to use pubsub.
508493
@li subscriber_sync.cpp: Synchronous version of subscriber.cpp.
509494
@li echo_server.cpp: A simple TCP echo server that uses coroutines.
510495
@li chat_room.cpp: A simple chat room that uses coroutines.

include/aedis/adapt.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace aedis {
2222

23-
/** @brief Tag used tp ignore responses.
23+
/** @brief Tag used to ignore responses.
2424
* @ingroup any
2525
*
2626
* For example

0 commit comments

Comments
 (0)