@@ -17,7 +17,7 @@ Some of its distinctive features are
17
17
18
18
In addition to that, Aedis hides most of the low-level Asio code away
19
19
from the user, which in the majority of the cases will be concerned
20
- with three library entities
20
+ with only three library entities
21
21
22
22
* ` aedis::resp3::request ` : A container of Redis commands.
23
23
* ` aedis::adapt() ` : A function that adapts data structures to receive Redis responses.
@@ -36,7 +36,7 @@ auto hgetall() -> net::awaitable<void>
36
36
co_await connect(conn, "127.0.0.1", "6379");
37
37
38
38
// A request contains multiple Redis commands.
39
- request req;
39
+ resp3:: request req;
40
40
req.get_config().cancel_on_connection_lost = true;
41
41
req.push("HELLO", 3);
42
42
req.push("HGETALL", "hset-key");
@@ -61,8 +61,9 @@ socket. The rationale behind this design is
61
61
* Support server pushes and requests in the same connection object,
62
62
concurrently.
63
63
64
- Long-lived connections follow the same principle and will be discussed
65
- more later. Before we go to the next sections, users might find it
64
+ The need for this design becomes more apparent in long-lived
65
+ connections which we will discuss later (see subscriber.cpp for an
66
+ example). Before we go to the next sections, users might find it
66
67
useful to skim over the examples in order to gain a better feeling
67
68
about the library capabilities.
68
69
@@ -113,7 +114,7 @@ Sending a request to Redis is performed with `aedis::connection::async_exec` as
113
114
114
115
<a name="serialization"></a>
115
116
116
- #### Serialization
117
+ ### Serialization
117
118
118
119
The `resp3::request::push` and `resp3::request::push_range` member functions work
119
120
with integer data types e.g. `int` and `std::string` out of the box.
@@ -146,6 +147,12 @@ Example serialization.cpp shows how store json strings in Redis.
146
147
147
148
<a name="responses"></a>
148
149
150
+ ### Config flags
151
+
152
+ The `aedis::resp3::request::config` object inside the request dictates how the
153
+ `aedis::connection` should handle the request in some important situations. The
154
+ reader is advised to have a read it carefully.
155
+
149
156
## Responses
150
157
151
158
Aedis uses the following strategy to support Redis responses
@@ -258,7 +265,7 @@ of this writing, not all RESP3 types are used by the Redis server,
258
265
which means in practice users will be concerned with a reduced
259
266
subset of the RESP3 specification.
260
267
261
- #### Pushes
268
+ ### Pushes
262
269
263
270
Commands that have push response like
264
271
@@ -278,7 +285,7 @@ req.push("QUIT");
278
285
must be read in this tuple ` std::tuple<std::string, std::string> ` ,
279
286
that has size two.
280
287
281
- #### Null
288
+ ### Null
282
289
283
290
It is not uncommon for apps to access keys that do not exist or
284
291
that have already expired in the Redis server, to deal with these
@@ -297,7 +304,7 @@ co_await conn->async_exec(req, adapt(resp));
297
304
298
305
Everything else stays pretty much the same.
299
306
300
- #### Transactions
307
+ ### Transactions
301
308
302
309
To read responses to transactions we must first observe that Redis will
303
310
queue the transaction commands and send their individual responses as elements
@@ -337,14 +344,14 @@ co_await conn->async_exec(req, adapt(resp));
337
344
338
345
For a complete example see containers.cpp.
339
346
340
- #### Deserialization
347
+ ### Deserialization
341
348
342
- As mentioned in \ref serialization, it is common practice to
343
- serialize data before sending it to Redis e.g. as json strings.
344
- For performance and convenience reasons, we may also want to
345
- deserialize responses directly in their final data structure. Aedis
346
- supports this use case by calling a user provided `from_bulk` function
347
- while parsing the response. For example
349
+ As mentioned in the serialization section , it is common practice to
350
+ serialize data before sending it to Redis e.g. as json strings. For
351
+ performance and convenience reasons, we may also want to deserialize
352
+ responses directly in their final data structure. Aedis supports this
353
+ use case by calling a user provided `from_bulk` function while parsing
354
+ the response. For example
348
355
349
356
```cpp
350
357
void from_bulk(mystruct& obj, char const* p, std::size_t size, boost::system::error_code& ec)
@@ -358,7 +365,7 @@ types e.g. `mystruct`, `std::map<std::string, mystruct>` etc.
358
365
359
366
<a name =" the-general-case " ></a >
360
367
361
- #### The general case
368
+ ### The general case
362
369
363
370
There are cases where responses to Redis
364
371
commands won't fit in the model presented above, some examples are
@@ -440,7 +447,7 @@ Each of these operations can be performed without regards to the
440
447
others as they are independent from each other. Below we will cover
441
448
the points above with more detail.
442
449
443
- #### Run
450
+ ### Run
444
451
445
452
The code snippet in the overview section has shown us an example that
446
453
used ` connection::async_run ` in short-lived connection, in the general
@@ -489,7 +496,7 @@ send a `HELLO 3` command every time a connection is established.
489
496
Another common scenario for reconnection is, for example, a failover
490
497
with sentinels, covered in ` resolve_with_sentinel.cpp ` example.
491
498
492
- #### Execute
499
+ ### Execute
493
500
494
501
The basic idea about ` async_exec ` was stated above already: execute
495
502
Redis commands. One of the most important things about it however is
@@ -548,7 +555,7 @@ Notice also how the session above provides back-pressure as the
548
555
coroutine won't read the next message from the socket until a cycle is
549
556
complete.
550
557
551
- #### Receive
558
+ ### Receive
552
559
553
560
Receiving Redis pushes works similar to the `async_exec` discussed
554
561
above but without the request. The example below was taken from
@@ -570,7 +577,7 @@ In general, it is advisable to all apps to keep a coroutine calling
570
577
and eventually timeout. Notice that the same connection that is being
571
578
used to send requests can be also used to receive server-side pushes.
572
579
573
- #### Cancellation
580
+ ### Cancellation
574
581
575
582
Aedis supports both implicit and explicit cancellation of connection
576
583
operations. Explicit cancellation is supported by means of the
@@ -752,7 +759,7 @@ terminal and the
752
759
[ echo-server-client] ( https://github.com/mzimbres/aedis/blob/42880e788bec6020dd018194075a211ad9f339e8/benchmarks/cpp/asio/echo_server_client.cpp )
753
760
in another.
754
761
755
- #### Without Redis
762
+ ### Without Redis
756
763
757
764
First I tested a pure TCP echo server, i.e. one that sends the messages
758
765
directly to the client without interacting with Redis. The result can
@@ -779,7 +786,7 @@ The code used in the benchmarks can be found at
779
786
* [ Nodejs] ( https://github.com/mzimbres/aedis/tree/3fb018ccc6138d310ac8b73540391cdd8f2fdad6/benchmarks/nodejs/echo_server_direct )
780
787
* [ Go] ( https://github.com/mzimbres/aedis/blob/3fb018ccc6138d310ac8b73540391cdd8f2fdad6/benchmarks/go/echo_server_direct.go )
781
788
782
- #### With Redis
789
+ ### With Redis
783
790
784
791
This is similar to the echo server described above but messages are
785
792
echoed by Redis and not by the echo-server itself, which acts
@@ -816,7 +823,7 @@ The code used in the benchmarks can be found at
816
823
817
824
<a name =" api-reference " ></a >
818
825
819
- #### Conclusion
826
+ ### Conclusion
820
827
821
828
Redis clients have to support automatic pipelining to have competitive performance. For updates to this document follow https://github.com/mzimbres/aedis .
822
829
@@ -870,8 +877,7 @@ Acknowledgement to people that helped shape Aedis
870
877
871
878
### 1.4.0
872
879
873
- * Removes dependency on Boost.Hana.
874
- * Removes dependency on ` boost::string_view ` , now using ` std::string_view ` .
880
+ * Removes dependency on Boost.Hana, boost::string_view, Boost.Variant2 and Boost.Spirit.
875
881
* Fixes build and setup CI on windows.
876
882
877
883
### v1.3.0-1
0 commit comments