Skip to content

Commit e34f90f

Browse files
committed
Update docs
1 parent e9e090b commit e34f90f

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

README.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ can be done on the socket object outside of the connector)
5757

5858
Results achieved with `examples/speed_test_async_multi.cpp` for 1 thread, Intel Core i7-4800MQ, gentoo linux
5959

60-
| bredis (commands/s) | redox (commands/s) |
61-
|----------------------------|------------------------------|
62-
| 1.30257e+06 | 1.19214e+06 |
60+
| bredis (commands/s) | bredis(*) (commands/s) | redox (commands/s)
61+
|---------------------+------------------------+--------------------
62+
| 1.59325e+06 | 2.50826e+06 | 0.999375+06
6363

6464
These results are not completely fair, because of the usage of different semantics in the
6565
APIs; however they are still interesting, as they are using different
6666
underlying event libraries ([Boost::ASIO](http://www.boost.org/doc/libs/release/libs/asio/) vs [libev](http://software.schmorp.de/pkg/libev.html)) as well as redis protocol
6767
parsing libraries (written from scratch vs [hiredis](https://github.com/redis/hiredis))
6868

69+
`(*)` bredis with drop_result policy, i.e. replies from redis server are
70+
scanned only for formal correctness and never delivered to the caller.
71+
72+
6973
## Work with the result
7074

7175
The general idea is that the result of trying to parse a redis reply can be either: not enough data, protocol error (in an extreme case) or some positive parse result. The last one is just **markers** of the result, which is actually stored in the *receive buffer* (i.e. outside of markers, and outside of the bredis-connection).
@@ -386,7 +390,7 @@ boost::asio::spawn(
386390
## Steams
387391
388392
There is no specific support for streams (appeared in redis 5.0) in bredis,
389-
they are just usual `XADD`, `XRANGE` etc. commands and corresponding replies.
393+
they are just usual `XADD`, `XRANGE` etc. commands and corresponding replies.
390394
391395
```cpp
392396
...
@@ -410,7 +414,7 @@ rx_buff.consume(parse_result3.consumed);
410414
auto& outer_arr = boost::get<r::extracts::array_holder_t>(extract3);
411415
auto& inner_arr1 = boost::get<r::extracts::array_holder_t>(outer_arr.elements[0]);
412416
auto& inner_arr2 = boost::get<r::extracts::array_holder_t>(outer_arr.elements[1]);
413-
...
417+
...
414418
415419
```
416420

@@ -448,6 +452,28 @@ and used buffers are usually not thread-safe. To handle that in multi-thead
448452
environment the access to those objects should be sequenced via
449453
`asio::io_context::strand` . See the `examples/multi-threads-1.cpp`.
450454
455+
456+
## parsing_policy::drop_result
457+
The performance still can be boosted if it is known beforehand that the response from
458+
redis server is not needed at all. For example, the only possible response to `PING`
459+
command is `PONG` reply, usually there is no sense it validating that `PONG` reply,
460+
as soon as it is known, that redis-server alredy delivered us **some** reply
461+
(in practice it is `PONG`). Another example is `SET` command, when redis-server
462+
**usually** replies with `OK`.
463+
464+
With `parsing_policy::drop_result` the reply result is just verified with formal
465+
compliance to redis protocol, and then it is discarded.
466+
467+
It should be noted, that redis can reply back with error, which aslo correct
468+
reply, but the caller side isn't able to see it when `parsing_policy::drop_result`.
469+
So, it should be used with care, when you know what your are doing. You have
470+
been warned.
471+
472+
It is safe, however, to mix different parsing policies on the same connection,
473+
i.e. write `SET` command and read it's reply with `parsing_policy::drop_result` and
474+
then write `GET` command and read it's reply with `parsing_policy::keep_result`.
475+
See the `examples/speed_test_async_multi.cpp`.
476+
451477
## API
452478
453479
There's a convenience header include/bredis.hpp, doing `#include "bredis.hpp"` will include
@@ -682,7 +708,7 @@ The asynchronous read has the following signature:
682708
```cpp
683709
void-or-deduced
684710
async_read(DynamicBuffer &rx_buff, ReadCallback read_callback,
685-
std::size_t replies_count = 1);
711+
std::size_t replies_count = 1, Policy = bredis::parsing_policy::keep_result{});
686712
```
687713

688714
It reads `replies_count` replies from the *next_layer* stream, which will be

examples/speed_test_async_multi.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
//
1010
// Results (1 thread, Intel Core i7-8550U, void-linux, gcc 8.3.0)
1111
//
12-
// bredis (commands/s) | redox (commands/s)
13-
// -----------------------+-----------------------
14-
// 1.59325e+06 | 0.999375+06
12+
// bredis (commands/s) | bredis(*) (commands/s) | redox (commands/s)
13+
// ---------------------+------------------------+---------------------
14+
// 1.59325e+06 | 2.50826e+06 | 0.999375+06
1515
//
1616
// Results are not completely fair, because of usage of different semantics in
1717
// APIs; however they are still interesting, as there are used different
1818
// underlying event libraries (Boost::ASIO vs libev) as well redis protocol
1919
// parsing library (written from scratch vs hiredis)
20+
//
21+
// (*) bredis with drop_result policy, i.e. replies from redis server are
22+
// scanned only for formal correctness and never delivered to the caller
23+
2024

2125
#include <algorithm>
2226
#include <atomic>

0 commit comments

Comments
 (0)