1
- # Boost.Redis
1
+ # boost_redis
2
2
3
3
Boost.Redis is a [ Redis] ( https://redis.io/ ) client library built on top of
4
4
[ Boost.Asio] ( https://www.boost.org/doc/libs/release/doc/html/boost_asio.html )
@@ -13,7 +13,7 @@ concerned with only three library entities
13
13
high-level functions to execute Redis commands, receive server
14
14
pushes and support for automatic command
15
15
[ pipelines] ( https://redis.io/docs/manual/pipelining/ ) .
16
- * ` boost::redis::resp3:: request ` : A container of Redis commands that supports
16
+ * ` boost::redis::request ` : A container of Redis commands that supports
17
17
STL containers and user defined data types.
18
18
* ` boost::redis::adapt() ` : A function that adapts data structures to receive responses.
19
19
@@ -54,15 +54,15 @@ auto co_main() -> net::awaitable<void>
54
54
co_await connect(conn, "127.0.0.1", "6379");
55
55
56
56
// A request can contain multiple commands.
57
- resp3:: request req;
57
+ request req;
58
58
req.push("HELLO", 3);
59
59
req.push("HGETALL", "hset-key");
60
60
req.push("QUIT");
61
61
62
62
// The tuple elements will store the responses to each individual
63
63
// command. The responses to HELLO and QUIT are being ignored for
64
64
// simplicity.
65
- std::tuple <ignore, std::map<std::string, std::string>, ignore> resp;
65
+ response <ignore, std::map<std::string, std::string>, ignore> resp;
66
66
67
67
// Executes the request. See below why we are using operator ||.
68
68
co_await (conn.async_run() || conn.async_exec(req, adapt(resp)));
@@ -108,25 +108,25 @@ auto run(std::shared_ptr<connection> conn) -> net::awaitable<void>
108
108
109
109
auto hello(std::shared_ptr<connection > conn) -> net::awaitable<void >
110
110
{
111
- resp3:: request req;
111
+ request req;
112
112
req.push("HELLO", 3);
113
113
114
114
co_await conn->async_exec(req);
115
115
}
116
116
117
117
auto ping(std::shared_ptr<connection > conn) -> net::awaitable<void >
118
118
{
119
- resp3:: request req;
119
+ request req;
120
120
req.push("PING", "Hello world");
121
121
122
- std::tuple < std::string > resp;
122
+ response < std::string > resp;
123
123
co_await conn->async_exec(req, adapt(resp));
124
124
// Use the response ...
125
125
}
126
126
127
127
auto quit(std::shared_ptr<connection > conn) -> net::awaitable<void >
128
128
{
129
- resp3:: request req;
129
+ request req;
130
130
req.push("QUIT");
131
131
132
132
co_await conn->async_exec(req);
@@ -178,8 +178,7 @@ to used it
178
178
``` cpp
179
179
auto receiver (std::shared_ptr<connection > conn) -> net::awaitable<void >
180
180
{
181
- using resp_type = std::vector< resp3::node<std::string > >;
182
- for (resp_type resp;;) {
181
+ for (generic_response resp;;) {
183
182
co_await conn->async_receive(adapt(resp));
184
183
// Use resp and clear the response for a new push.
185
184
resp.clear();
@@ -263,7 +262,7 @@ co_await (conn.async_exec(...) || conn.async_exec(...) || ... || conn.async_exec
263
262
```
264
263
265
264
* This works but is unnecessary. Unless the user has set
266
- ` boost::redis::resp3:: request::config::coalesce ` to ` false ` , and he
265
+ ` boost::redis::request::config::coalesce ` to ` false ` , and he
267
266
usually shouldn't, the connection will automatically merge the
268
267
individual requests into a single payload.
269
268
@@ -301,7 +300,7 @@ Sending a request to Redis is performed with `boost::redis::connection::async_ex
301
300
302
301
### Serialization
303
302
304
- The `resp3:: request::push` and `resp3:: request::push_range` member functions work
303
+ The `request::push` and `request::push_range` member functions work
305
304
with integer data types e.g. `int` and `std::string` out of the box.
306
305
To send your own data type define a `boost_redis_to_bulk` function like this
307
306
@@ -334,17 +333,16 @@ Example cpp20_serialization.cpp shows how store json strings in Redis.
334
333
335
334
### Config flags
336
335
337
- The `boost::redis::resp3:: request::config` object inside the request dictates how the
336
+ The `boost::redis::request::config` object inside the request dictates how the
338
337
`boost::redis::connection` should handle the request in some important situations. The
339
338
reader is advised to read it carefully.
340
339
341
340
## Responses
342
341
343
342
Boost.Redis uses the following strategy to support Redis responses
344
343
345
- * **Static**: For `boost::redis::resp3::request` whose sizes are known at compile time
346
- `std::tuple` is supported.
347
- * **Dynamic**: Otherwise use `std::vector<boost::redis::resp3::node<std::string>>`.
344
+ * **Static**: For `boost::redis::request` whose sizes are known at compile time use the `response` type.
345
+ * **Dynamic**: Otherwise use `boost::redis::generic_response`.
348
346
349
347
For example, below is a request with a compile time size
350
348
@@ -358,7 +356,7 @@ req.push("QUIT");
358
356
To read the response to this request users can use the following tuple
359
357
360
358
``` cpp
361
- std::tuple <std::string, int , std::string>
359
+ response <std::string, int , std::string>
362
360
```
363
361
364
362
The pattern might have become apparent to the reader: the tuple must
@@ -370,7 +368,7 @@ To ignore responses to individual commands in the request use the tag
370
368
371
369
``` cpp
372
370
// Ignore the second and last responses.
373
- std::tuple <std::string, boost::redis::ignore, std::string, boost::redis::ignore>
371
+ response <std::string, boost::redis::ignore, std::string, boost::redis::ignore>
374
372
```
375
373
376
374
The following table provides the resp3-types returned by some Redis
@@ -417,7 +415,7 @@ req.push("QUIT");
417
415
can be read in the tuple below
418
416
419
417
``` cpp
420
- std::tuple <
418
+ response <
421
419
redis::ignore, // hello
422
420
int , // rpush
423
421
int , // hset
@@ -467,7 +465,7 @@ req.push("SUBSCRIBE", "channel");
467
465
req.push(" QUIT" );
468
466
```
469
467
470
- must be read in this tuple ` std::tuple <std::string, std::string>` ,
468
+ must be read in this tuple ` response <std::string, std::string>` ,
471
469
that has size two.
472
470
473
471
### Null
@@ -478,7 +476,7 @@ cases Boost.Redis provides support for `std::optional`. To use it,
478
476
wrap your type around ` std::optional ` like this
479
477
480
478
``` cpp
481
- std::tuple <
479
+ response <
482
480
std::optional<A>,
483
481
std::optional<B>,
484
482
...
@@ -510,13 +508,13 @@ use the following response type
510
508
using boost::redis::ignore;
511
509
512
510
using exec_resp_type =
513
- std::tuple <
511
+ response <
514
512
std::optional<std::string>, // get
515
513
std::optional<std::vector<std::string>>, // lrange
516
514
std::optional<std::map<std::string, std::string>> // hgetall
517
515
>;
518
516
519
- std::tuple <
517
+ response <
520
518
boost::redis::ignore, // multi
521
519
boost::redis::ignore, // get
522
520
boost::redis::ignore, // lrange
@@ -559,7 +557,7 @@ commands won't fit in the model presented above, some examples are
559
557
RESP3 type. Expecting an ` int ` and receiving a blob-string
560
558
will result in error.
561
559
* RESP3 aggregates that contain nested aggregates can't be read in STL containers.
562
- * Transactions with a dynamic number of commands can't be read in a ` std::tuple ` .
560
+ * Transactions with a dynamic number of commands can't be read in a ` response ` .
563
561
564
562
To deal with these cases Boost.Redis provides the ` boost::redis::resp3::node ` type
565
563
abstraction, that is the most general form of an element in a
@@ -584,20 +582,20 @@ struct node {
584
582
```
585
583
586
584
Any response to a Redis command can be received in a
587
- `std::vector<node<std::string>> `. The vector can be seen as a
585
+ `boost::redis::generic_response `. The vector can be seen as a
588
586
pre-order view of the response tree. Using it is not different than
589
587
using other types
590
588
591
589
```cpp
592
590
// Receives any RESP3 simple or aggregate data type.
593
- std::vector<node<std::string>> resp;
591
+ boost::redis::generic_response resp;
594
592
co_await conn->async_exec(req, adapt(resp));
595
593
```
596
594
597
595
For example, suppose we want to retrieve a hash data structure
598
596
from Redis with ` HGETALL ` , some of the options are
599
597
600
- * ` std::vector<node<std::string> ` : Works always.
598
+ * ` boost::redis::generic_response ` : Works always.
601
599
* ` std::vector<std::string> ` : Efficient and flat, all elements as string.
602
600
* ` std::map<std::string, std::string> ` : Efficient if you need the data as a ` std::map ` .
603
601
* ` std::map<U, V> ` : Efficient if you are storing serialized data. Avoids temporaries and requires ` boost_redis_from_bulk ` for ` U ` and ` V ` .
@@ -863,11 +861,13 @@ Acknowledgement to people that helped shape Boost.Redis
863
861
864
862
## Changelog
865
863
866
- ### master
864
+ ### master (incorporates many suggestions from the boost review)
867
865
868
866
* Renames the project to Boost.Redis and moves the code into namespace ` boost::redis ` .
869
- * As pointed out in the reviews ` to_buld ` and ` from_buld ` were too generic
870
- for ADL customization. They gained the prefix ` boost_redis_ ` .
867
+ * As pointed out in the reviews ` to_buld ` and ` from_buld ` were too generic for ADL customization. They gained the prefix ` boost_redis_ ` .
868
+ * Moves ` boost::redis::resp3::request ` to ` boost::redis::request ` .
869
+ * Adds new typedef ` boost::redis::response ` that should be used instead of ` std::tuple ` .
870
+ * Adds new typedef ` boost::redis::generic_response ` that should be used instead of ` std::vector<resp3::node<std::string>> ` .
871
871
872
872
### v1.4.0-1
873
873
@@ -883,7 +883,7 @@ Acknowledgement to people that helped shape Boost.Redis
883
883
implemented properly without bloating the connection class. It is
884
884
now a user responsibility to send HELLO. Requests that contain it have
885
885
priority over other requests and will be moved to the front of the
886
- queue, see ` aedis::resp3:: request::config `
886
+ queue, see ` aedis::request::config `
887
887
888
888
* Automatic name resolving and connecting have been removed from
889
889
` aedis::connection::async_run ` . Users have to do this step manually
@@ -914,21 +914,21 @@ Acknowledgement to people that helped shape Boost.Redis
914
914
asio::error::eof is received. This makes it easier to write
915
915
composed operations with awaitable operators.
916
916
917
- * Adds allocator support in the ` aedis::resp3:: request ` (a
917
+ * Adds allocator support in the ` aedis::request ` (a
918
918
contribution from Klemens Morgenstern).
919
919
920
- * Renames ` aedis::resp3:: request::push_range2 ` to ` push_range ` . The
920
+ * Renames ` aedis::request::push_range2 ` to ` push_range ` . The
921
921
suffix 2 was used for disambiguation. Klemens fixed it with SFINAE.
922
922
923
923
* Renames ` fail_on_connection_lost ` to
924
- ` aedis::resp3:: request::config::cancel_on_connection_lost ` . Now, it will
924
+ ` aedis::request::config::cancel_on_connection_lost ` . Now, it will
925
925
only cause connections to be canceled when ` async_run ` completes.
926
926
927
- * Introduces ` aedis::resp3:: request::config::cancel_if_not_connected ` which will
927
+ * Introduces ` aedis::request::config::cancel_if_not_connected ` which will
928
928
cause a request to be canceled if ` async_exec ` is called before a
929
929
connection has been established.
930
930
931
- * Introduces new request flag ` aedis::resp3:: request::config::retry ` that if
931
+ * Introduces new request flag ` aedis::request::config::retry ` that if
932
932
set to true will cause the request to not be canceled when it was
933
933
sent to Redis but remained unresponded after ` async_run ` completed.
934
934
It provides a way to avoid executing commands twice.
@@ -958,7 +958,7 @@ Acknowledgement to people that helped shape Boost.Redis
958
958
### v1.1.0-1
959
959
960
960
* Removes ` coalesce_requests ` from the ` aedis::connection::config ` , it
961
- became a request property now, see ` aedis::resp3:: request::config::coalesce ` .
961
+ became a request property now, see ` aedis::request::config::coalesce ` .
962
962
963
963
* Removes ` max_read_size ` from the ` aedis::connection::config ` . The maximum
964
964
read size can be specified now as a parameter of the
0 commit comments