@@ -4,41 +4,39 @@ Boost.Redis is a high-level [Redis](https://redis.io/) client library built on t
4
4
[ Boost.Asio] ( https://www.boost.org/doc/libs/release/doc/html/boost_asio.html )
5
5
that implements the Redis protocol
6
6
[ RESP3] ( https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md ) .
7
- The requirements for using Boost.Redis are:
7
+ The requirements for using Boost.Redis are
8
8
9
- * Boost. The library is included in Boost distributions starting with 1.84.
9
+ * Boost 1.84 or higher .
10
10
* C++17 or higher.
11
11
* Redis 6 or higher (must support RESP3).
12
- * Gcc (11, 12), Clang (11, 13, 14) and Visual Studio (16 2019, 17 2022).
12
+ * GCC (11, 12), Clang (11, 13, 14) and Visual Studio (16 2019, 17 2022).
13
13
* Have basic-level knowledge about [ Redis] ( https://redis.io/docs/ )
14
14
and [ Boost.Asio] ( https://www.boost.org/doc/libs/1_82_0/doc/html/boost_asio/overview.html ) .
15
15
16
- The latest release can be downloaded on
17
- https://github.com/boostorg/redis/releases . The library headers can be
18
- found in the ` include ` subdirectory and a compilation of the source
16
+ To use the library it is necessary to include
19
17
20
18
``` cpp
21
19
#include < boost/redis/src.hpp>
22
20
```
23
21
24
- is required. The simplest way to do it is to included this header in
25
- no more than one source file in your applications. To build the
26
- examples and tests cmake is supported, for example
22
+ in no more than one source file in your applications. To build the
23
+ examples and tests with cmake run
27
24
28
25
``` cpp
29
26
# Linux
30
- $ BOOST_ROOT=/opt/boost_1_84_0 cmake --preset g++- 11
27
+ $ BOOST_ROOT=/opt/boost_1_84_0 cmake -S <source-dir> -B <binary-dir>
31
28
32
29
# Windows
33
30
$ cmake -G " Visual Studio 17 2022" -A x64 -B bin64 -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
34
31
```
35
32
33
+ For more details see https://github.com/boostorg/cmake .
34
+
36
35
<a name =" connection " ></a >
37
36
## Connection
38
37
39
- Let us start with a simple application that uses a short-lived
40
- connection to send a [ ping] ( https://redis.io/commands/ping/ ) command
41
- to Redis
38
+ The code below uses a short-lived connection to
39
+ [ ping] ( https://redis.io/commands/ping/ ) the Redis server
42
40
43
41
``` cpp
44
42
auto co_main (config const& cfg) -> net::awaitable<void >
@@ -50,7 +48,7 @@ auto co_main(config const& cfg) -> net::awaitable<void>
50
48
request req;
51
49
req.push("PING", "Hello world");
52
50
53
- // Response where the PONG response will be stored .
51
+ // Response object .
54
52
response< std::string > resp;
55
53
56
54
// Executes the request.
@@ -145,21 +143,18 @@ req.push_range("SUBSCRIBE", std::cbegin(list), std::cend(list));
145
143
req.push_range("HSET", "key", map);
146
144
```
147
145
148
- Sending a request to Redis is performed with `boost::redis::connection::async_exec` as already stated.
149
-
150
- ### Config flags
151
-
152
- The `boost::redis::request::config` object inside the request dictates how the
153
- `boost::redis::connection` should handle the request in some important situations. The
154
- reader is advised to read it carefully.
146
+ Sending a request to Redis is performed with `boost::redis::connection::async_exec` as already stated. The
147
+ `boost::redis::request::config` object inside the request dictates how
148
+ the `boost::redis::connection` the request is handled in some
149
+ situations. The reader is advised to read it carefully.
155
150
156
151
<a name="responses"></a>
157
152
## Responses
158
153
159
- Boost.Redis uses the following strategy to support Redis responses
154
+ Boost.Redis uses the following strategy to deal with Redis responses
160
155
161
- * `boost::redis::request` is used for requests whose number of commands are not dynamic.
162
- * **Dynamic**: Otherwise use `boost::redis::generic_response`.
156
+ * `boost::redis::request` used for requests whose number of commands are not dynamic.
157
+ * `boost::redis::generic_response` used when the size is dynamic .
163
158
164
159
For example, the request below has three commands
165
160
@@ -170,8 +165,8 @@ req.push("INCR", "key");
170
165
req.push("QUIT");
171
166
```
172
167
173
- and its response also has three commands and can be read in the
174
- following response object
168
+ and therefore its response will also contain three elements which can
169
+ be read in the following reponse object
175
170
176
171
``` cpp
177
172
response<std::string, int , std::string>
@@ -186,7 +181,7 @@ To ignore responses to individual commands in the request use the tag
186
181
187
182
``` cpp
188
183
// Ignore the second and last responses.
189
- response<std::string, boost::redis:: ignore_t , std::string, boost::redis:: ignore_t >
184
+ response<std::string, ignore_t , std::string, ignore_t >
190
185
```
191
186
192
187
The following table provides the resp3-types returned by some Redis
@@ -230,7 +225,7 @@ req.push("QUIT");
230
225
231
226
```
232
227
233
- can be read in the tuple below
228
+ can be read in the response object below
234
229
235
230
``` cpp
236
231
response<
@@ -243,7 +238,8 @@ response<
243
238
> resp;
244
239
```
245
240
246
- Where both are passed to ` async_exec ` as showed elsewhere
241
+ Then, to execute the request and read the response use ` async_exec ` as
242
+ shown below
247
243
248
244
``` cpp
249
245
co_await conn->async_exec (req, resp);
@@ -279,27 +275,23 @@ req.push("SUBSCRIBE", "channel");
279
275
req.push(" QUIT" );
280
276
```
281
277
282
- must be read in this tuple ` response<std::string, std::string> ` ,
283
- that has static size two.
278
+ must be read in the response object ` response<std::string, std::string> ` .
284
279
285
280
### Null
286
281
287
- It is not uncommon for apps to access keys that do not exist or
288
- that have already expired in the Redis server, to deal with these
289
- cases Boost.Redis provides support for ` std::optional ` . To use it,
290
- wrap your type around ` std::optional ` like this
282
+ It is not uncommon for apps to access keys that do not exist or that
283
+ have already expired in the Redis server, to deal with these usecases
284
+ wrap the type with an ` std::optional ` as shown below
291
285
292
286
``` cpp
293
287
response<
294
288
std::optional<A>,
295
289
std::optional<B>,
296
290
...
297
291
> resp;
298
-
299
- co_await conn->async_exec (req, resp);
300
292
```
301
293
302
- Everything else stays pretty much the same.
294
+ Everything else stays the same.
303
295
304
296
### Transactions
305
297
@@ -321,22 +313,18 @@ use the following response type
321
313
``` cpp
322
314
using boost::redis::ignore;
323
315
324
- using exec_resp_type =
316
+
317
+ response<
318
+ ignore_t , // multi
319
+ ignore_t , // QUEUED
320
+ ignore_t , // QUEUED
321
+ ignore_t , // QUEUED
325
322
response<
326
323
std::optional<std::string>, // get
327
324
std::optional<std::vector<std::string>>, // lrange
328
325
std::optional<std::map<std::string, std::string>> // hgetall
329
- >;
330
-
331
- response<
332
- boost::redis::ignore_t , // multi
333
- boost::redis::ignore_t , // get
334
- boost::redis::ignore_t , // lrange
335
- boost::redis::ignore_t , // hgetall
336
- exec_resp_type, // exec
326
+ > // exec
337
327
> resp;
338
-
339
- co_await conn->async_exec (req, resp);
340
328
```
341
329
342
330
For a complete example see cpp20_containers.cpp.
@@ -350,7 +338,7 @@ commands won't fit in the model presented above, some examples are
350
338
351
339
* Commands (like ` set ` ) whose responses don't have a fixed
352
340
RESP3 type. Expecting an ` int ` and receiving a blob-string
353
- will result in error.
341
+ results in an error.
354
342
* RESP3 aggregates that contain nested aggregates can't be read in STL containers.
355
343
* Transactions with a dynamic number of commands can't be read in a ` response ` .
356
344
@@ -411,7 +399,7 @@ the following customization points
411
399
void boost_redis_to_bulk (std::string& to, mystruct const& obj);
412
400
413
401
// Deserialize
414
- void boost_redis_from_bulk(mystruct& obj, char const* p, std::size_t size, boost::system::error_code& ec )
402
+ void boost_redis_from_bulk(mystruct& u, node_view const& node, boost::system::error_code&)
415
403
```
416
404
417
405
These functions are accessed over ADL and therefore they must be
@@ -676,6 +664,28 @@ https://lists.boost.org/Archives/boost/2023/01/253944.php.
676
664
677
665
## Changelog
678
666
667
+ ### Boost 1.88
668
+
669
+ * (Issue [ 233] ( https://github.com/boostorg/redis/issues/233 ) )
670
+ To deal with keys that might not exits in the Redis server, the
671
+ library supports ` std::optional ` , for example
672
+ ` response<std::optional<std::vector<std::string>>> ` . In some cases
673
+ however, such as the [ MGET] ( https://redis.io/docs/latest/commands/mget/ ) command,
674
+ each element in the vector might be non exiting, now it is possible
675
+ to specify a response as ` response<std::optional<std::vector<std::optional<std::string>>>> ` .
676
+
677
+ * (Issue [ 225] ( https://github.com/boostorg/redis/issues/225 ) )
678
+ Use ` deferred ` as the connection default completion token.
679
+
680
+ * (Issue [ 128] ( https://github.com/boostorg/redis/issues/128 ) )
681
+ Adds a new ` async_exec ` overload that allows passing response
682
+ adapters. This makes it possible to receive Redis responses directly
683
+ in custom data structures thereby avoiding uncessary data copying.
684
+ Thanks to Ruben Perez (@anarthal ) for implementing this feature.
685
+
686
+ * There are also other multiple small improvements in this release,
687
+ users can refer to the git history for more details.
688
+
679
689
### Boost 1.87
680
690
681
691
* (Issue [ 205] ( https://github.com/boostorg/redis/issues/205 ) )
0 commit comments