Skip to content

Commit d620cde

Browse files
authored
Merge pull request #71 from boostorg/70-rename-node-to-basic_node-and-add-typedef-for-nodestdstring
70 rename node to basic node and add typedef for nodestdstring
2 parents a850a6e + 5f07b73 commit d620cde

35 files changed

+365
-400
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
boost_version: ["1.80.0"]
15+
boost_version: ["1.81.0"]
1616
os: [windows-2019, windows-2022]
1717
toolset: [v142, v143]
1818
build_type: [Release]
@@ -25,7 +25,7 @@ jobs:
2525
- { os: windows-2019, generator: "Visual Studio 17 2022" }
2626
- { os: windows-2022, generator: "Visual Studio 16 2019" }
2727
# The following combinations are not available through install-boost
28-
- { boost_version: "1.80.0", toolset: v143 }
28+
- { boost_version: "1.81.0", toolset: v143 }
2929

3030
steps:
3131
- name: Checkout
@@ -34,7 +34,7 @@ jobs:
3434
fetch-depth: 0
3535

3636
- name: Add boost toolset to environment
37-
if: contains(fromJson('["1.80.0"]'), matrix.boost_version)
37+
if: contains(fromJson('["1.81.0"]'), matrix.boost_version)
3838
run: echo BOOST_TOOLSET=$(echo "msvc") >> $GITHUB_ENV
3939

4040
# The platform_version passed to boost-install determines the msvc toolset version for which static libs are installed.
@@ -120,7 +120,7 @@ jobs:
120120
uses: MarkusJx/[email protected]
121121
id: install-boost
122122
with:
123-
boost_version: 1.80.0
123+
boost_version: 1.81.0
124124
platform_version: 22.04
125125
- name: Run CMake
126126
run: |

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
uses: MarkusJx/[email protected]
3131
id: install-boost
3232
with:
33-
boost_version: 1.80.0
33+
boost_version: 1.81.0
3434
platform_version: 22.04
3535
- name: Run CMake
3636
run: |

CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ if (MSVC)
134134
target_compile_definitions(cpp20_resolve_with_sentinel PRIVATE _WIN32_WINNT=0x0601)
135135
endif()
136136

137-
add_executable(cpp20_serialization examples/cpp20_serialization.cpp)
138-
target_compile_features(cpp20_serialization PUBLIC cxx_std_20)
139-
target_link_libraries(cpp20_serialization common)
140-
add_test(cpp20_serialization cpp20_serialization)
137+
add_executable(cpp20_json_serialization examples/cpp20_json_serialization.cpp)
138+
target_compile_features(cpp20_json_serialization PUBLIC cxx_std_20)
139+
target_link_libraries(cpp20_json_serialization common)
140+
add_test(cpp20_json_serialization cpp20_json_serialization)
141141
if (MSVC)
142-
target_compile_options(cpp20_serialization PRIVATE /bigobj)
143-
target_compile_definitions(cpp20_serialization PRIVATE _WIN32_WINNT=0x0601)
142+
target_compile_options(cpp20_json_serialization PRIVATE /bigobj)
143+
target_compile_definitions(cpp20_json_serialization PRIVATE _WIN32_WINNT=0x0601)
144144
endif()
145145

146146
add_executable(cpp20_subscriber examples/cpp20_subscriber.cpp)
@@ -161,7 +161,7 @@ if (MSVC)
161161
target_compile_definitions(cpp20_intro_tls PRIVATE _WIN32_WINNT=0x0601)
162162
endif()
163163

164-
add_executable(cpp20_low_level_async examples/cpp20_low_level_async.cpp)
164+
add_executable(cpp20_low_level_async tests/cpp20_low_level_async.cpp)
165165
target_compile_features(cpp20_low_level_async PUBLIC cxx_std_20)
166166
add_test(cpp20_low_level_async cpp20_low_level_async)
167167
target_link_libraries(cpp20_low_level_async common)
@@ -184,7 +184,7 @@ if (MSVC)
184184
target_compile_definitions(echo_server_direct PRIVATE _WIN32_WINNT=0x0601)
185185
endif()
186186

187-
add_executable(cpp17_low_level_sync examples/cpp17_low_level_sync.cpp)
187+
add_executable(cpp17_low_level_sync tests/cpp17_low_level_sync.cpp)
188188
target_compile_features(cpp17_low_level_sync PUBLIC cxx_std_17)
189189
add_test(cpp17_low_level_sync cpp17_low_level_sync)
190190
if (MSVC)

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ concerned with only three library entities
2020
In the next sections we will cover all those points in detail with
2121
examples. The requirements for using Boost.Redis are
2222

23-
* Boost 1.80 or greater.
23+
* Boost 1.81 or greater.
2424
* C++17 minimum.
2525
* Redis 6 or higher (must support RESP3).
2626
* Gcc (10, 11, 12), Clang (11, 13, 14) and Visual Studio (16 2019, 17 2022).
@@ -844,7 +844,11 @@ in no more than one source file in your applications. To build the
844844
examples and tests cmake is supported, for example
845845

846846
```cpp
847-
BOOST_ROOT=/opt/boost_1_80_0 cmake --preset dev
847+
# Linux
848+
$ BOOST_ROOT=/opt/boost_1_81_0 cmake --preset dev
849+
850+
# Windows
851+
$ cmake -G "Visual Studio 17 2022" -A x64 -B bin64 -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
848852
```
849853
## Acknowledgement
850854

@@ -862,21 +866,16 @@ Acknowledgement to people that helped shape Boost.Redis
862866
### master (incorporates many suggestions from the boost review)
863867

864868
* Renames the project to Boost.Redis and moves the code into namespace `boost::redis`.
865-
* As pointed out in the reviews `to_buld` and `from_buld` were too generic for ADL customization. They gained the prefix `boost_redis_`.
869+
* As pointed out in the reviews the `to_buld` and `from_buld` names were too generic for ADL customization points. They gained the prefix `boost_redis_`.
866870
* Moves `boost::redis::resp3::request` to `boost::redis::request`.
867871
* Adds new typedef `boost::redis::response` that should be used instead of `std::tuple`.
868872
* Adds new typedef `boost::redis::generic_response` that should be used instead of `std::vector<resp3::node<std::string>>`.
869873
* Renames `redis::ignore` to `redis::ignore_t`.
870874
* Changes the signature from `async_exec` to receive a `redis::response` instead of an adapter.
871-
* Adds `boost::redis::adapter::result` to store responses to commands
872-
including possible resp3 errors without losing the error diagnostic
873-
part. Basicaly instead of accessing values as `std::get<N>(resp)`
874-
users have to type `std::get<N>(resp).value()`
875-
* Implements full-duplex communication. Before these changes the
876-
connection would wait for a response to arrive before sending the
877-
next. Now requests are continuously coalesced and written to the
878-
socket. This made the request::coalesce unnecessary and threfore it
879-
was removed.
875+
* Adds `boost::redis::adapter::result` to store responses to commands including possible resp3 errors without losing the error diagnostic part. Basicaly instead of accessing values as `std::get<N>(resp)` users have to type `std::get<N>(resp).value()`
876+
* Implements full-duplex communication. Before these changes the connection would wait for a response to arrive before sending the next one. Now requests are continuously coalesced and written to the socket. This made the request::coalesce unnecessary and threfore it was removed.
877+
* Adds native json support for Boost.Describe'd classes, see cpp20_json_serialization.cpp for how to use it.
878+
* Upgrades to Boost 1.81.0.
880879

881880
### v1.4.0-1
882881

examples/common/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ auto redir(boost::system::error_code& ec)
2424
{ return net::redirect_error(net::use_awaitable, ec); }
2525
}
2626

27-
auto healthy_checker(std::shared_ptr<connection> conn) -> net::awaitable<void>
27+
auto health_check(std::shared_ptr<connection> conn) -> net::awaitable<void>
2828
{
2929
try {
3030
request req;

examples/common/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ connect(
2626
std::string const& host,
2727
std::string const& port) -> boost::asio::awaitable<void>;
2828

29-
auto healthy_checker(std::shared_ptr<connection> conn) -> boost::asio::awaitable<void>;
29+
auto health_check(std::shared_ptr<connection> conn) -> boost::asio::awaitable<void>;
3030

3131
auto run(boost::asio::awaitable<void> op) -> int;
3232

examples/common/serialization.hpp

Lines changed: 0 additions & 105 deletions
This file was deleted.

examples/cpp20_chat_room.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ auto co_main(std::string host, std::string port) -> net::awaitable<void>
6060

6161
co_await connect(conn, host, port);
6262
co_await ((conn->async_run() || publisher(stream, conn) || receiver(conn) ||
63-
healthy_checker(conn) || sig.async_wait()) && conn->async_exec(req));
63+
health_check(conn) || sig.async_wait()) && conn->async_exec(req));
6464
}
6565

6666
#else // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)

examples/cpp20_echo_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ auto co_main(std::string host, std::string port) -> net::awaitable<void>
5454
req.push("HELLO", 3);
5555

5656
co_await connect(conn, host, port);
57-
co_await ((conn->async_run() || listener(conn) || healthy_checker(conn) ||
57+
co_await ((conn->async_run() || listener(conn) || health_check(conn) ||
5858
sig.async_wait()) && conn->async_exec(req));
5959
}
6060

examples/cpp20_serialization.cpp renamed to examples/cpp20_json_serialization.cpp

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@
66

77
#include <boost/asio.hpp>
88
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
9+
#define BOOST_JSON_NO_LIB
10+
#define BOOST_CONTAINER_NO_LIB
911
#include <boost/redis.hpp>
10-
#include <iostream>
12+
#include <boost/describe.hpp>
13+
#include <boost/redis/json.hpp>
1114
#include <set>
1215
#include <string>
16+
#include <iostream>
1317
#include "common/common.hpp"
14-
#include "common/serialization.hpp"
1518

1619
// Include this in no more than one .cpp file.
1720
#include <boost/json/src.hpp>
1821

1922
namespace net = boost::asio;
2023
namespace redis = boost::redis;
24+
using namespace boost::describe;
2125
using boost::redis::request;
2226
using boost::redis::response;
23-
using boost::redis::ignore_t;
2427
using boost::redis::operation;
28+
using boost::redis::ignore_t;
2529

2630
struct user {
2731
std::string name;
@@ -41,46 +45,34 @@ auto run(std::shared_ptr<connection> conn, std::string host, std::string port) -
4145
co_await conn->async_run();
4246
}
4347

44-
auto hello(std::shared_ptr<connection> conn) -> net::awaitable<void>
48+
net::awaitable<void> co_main(std::string host, std::string port)
4549
{
46-
request req;
47-
req.push("HELLO", 3);
48-
49-
co_await conn->async_exec(req);
50-
}
50+
auto ex = co_await net::this_coro::executor;
51+
auto conn = std::make_shared<connection>(ex);
52+
net::co_spawn(ex, run(conn, host, port), net::detached);
5153

52-
auto sadd(std::shared_ptr<connection> conn) -> net::awaitable<void>
53-
{
54+
// A set of users that will be automatically serialized to json.
5455
std::set<user> users
5556
{{"Joao", "58", "Brazil"} , {"Serge", "60", "France"}};
5657

58+
// To simplify we send the set and retrieve it in the same
59+
// resquest.
5760
request req;
58-
req.push_range("SADD", "sadd-key", users); // Sends
59-
60-
co_await conn->async_exec(req);
61-
}
62-
63-
auto smembers(std::shared_ptr<connection> conn) -> net::awaitable<void>
64-
{
65-
request req;
61+
req.push("HELLO", 3);
62+
req.push_range("SADD", "sadd-key", users);
6663
req.push("SMEMBERS", "sadd-key");
6764

68-
response<std::set<user>> resp;
65+
// The response will contain the deserialized set, which should
66+
// match the one we sent.
67+
response<ignore_t, ignore_t, std::set<user>> resp;
6968

69+
// Sends the request and receives the response.
7070
co_await conn->async_exec(req, resp);
7171

72-
for (auto const& e: std::get<0>(resp).value())
73-
std::cout << e << "\n";
74-
}
72+
// Print.
73+
for (auto const& e: std::get<2>(resp).value())
74+
std::cout << e.name << " " << e.age << " " << e.country << "\n";
7575

76-
net::awaitable<void> co_main(std::string host, std::string port)
77-
{
78-
auto ex = co_await net::this_coro::executor;
79-
auto conn = std::make_shared<connection>(ex);
80-
net::co_spawn(ex, run(conn, host, port), net::detached);
81-
co_await hello(conn);
82-
co_await sadd(conn);
83-
co_await smembers(conn);
8476
conn->cancel(operation::run);
8577
}
8678

0 commit comments

Comments
 (0)