Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

94 unify redisconnection and redissslconnection #98

Merged
merged 3 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 47 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,21 @@ find_package(OpenSSL REQUIRED)
enable_testing()
include_directories(include)

#=======================================================================

add_library(boost_redis_src STATIC examples/boost_redis.cpp)
target_compile_features(boost_redis_src PUBLIC cxx_std_20)
if (MSVC)
target_compile_options(boost_redis_src PRIVATE /bigobj)
target_compile_definitions(boost_redis_src PRIVATE _WIN32_WINNT=0x0601)
endif()

# Main function for the examples.
#=======================================================================

add_library(test_common STATIC
tests/common.cpp
)
add_library(test_common STATIC)
target_sources(test_common PUBLIC tests/common.cpp)
target_link_libraries(test_common PUBLIC OpenSSL::Crypto OpenSSL::SSL boost_redis_src)
target_compile_features(test_common PUBLIC cxx_std_17)
if (MSVC)
target_compile_options(test_common PRIVATE /bigobj)
Expand All @@ -69,22 +78,19 @@ endif()

#=======================================================================

add_library(common STATIC
examples/start.cpp
examples/main.cpp
examples/boost_redis.cpp
)
target_compile_features(common PUBLIC cxx_std_20)
add_library(examples_common STATIC examples/main.cpp)
target_compile_features(examples_common PUBLIC cxx_std_20)
target_link_libraries(examples_common PRIVATE boost_redis_src)
if (MSVC)
target_compile_options(common PRIVATE /bigobj)
target_compile_definitions(common PRIVATE _WIN32_WINNT=0x0601)
target_compile_options(examples_common PRIVATE /bigobj)
target_compile_definitions(examples_common PRIVATE _WIN32_WINNT=0x0601)
endif()

# Executables
#=======================================================================

add_executable(cpp20_intro examples/cpp20_intro.cpp)
target_link_libraries(cpp20_intro common)
target_link_libraries(cpp20_intro PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
target_compile_features(cpp20_intro PUBLIC cxx_std_20)
add_test(cpp20_intro cpp20_intro)
if (MSVC)
Expand All @@ -93,14 +99,15 @@ if (MSVC)
endif()

add_executable(cpp20_streams examples/cpp20_streams.cpp)
target_link_libraries(cpp20_streams common)
target_link_libraries(cpp20_streams PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
target_compile_features(cpp20_streams PUBLIC cxx_std_20)
if (MSVC)
target_compile_options(cpp20_streams PRIVATE /bigobj)
target_compile_definitions(cpp20_streams PRIVATE _WIN32_WINNT=0x0601)
endif()

add_executable(cpp17_intro examples/cpp17_intro.cpp)
target_link_libraries(cpp17_intro PRIVATE OpenSSL::Crypto OpenSSL::SSL)
target_compile_features(cpp17_intro PUBLIC cxx_std_17)
add_test(cpp17_intro cpp17_intro)
if (MSVC)
Expand All @@ -111,18 +118,19 @@ endif()
if (NOT MSVC)
add_executable(cpp17_intro_sync examples/cpp17_intro_sync.cpp)
target_compile_features(cpp17_intro_sync PUBLIC cxx_std_17)
target_link_libraries(cpp17_intro_sync PRIVATE OpenSSL::Crypto OpenSSL::SSL)
add_test(cpp17_intro_sync cpp17_intro_sync)
endif()

if (NOT MSVC)
add_executable(cpp20_chat_room examples/cpp20_chat_room.cpp)
target_compile_features(cpp20_chat_room PUBLIC cxx_std_20)
target_link_libraries(cpp20_chat_room common)
target_link_libraries(cpp20_chat_room PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
endif()

add_executable(cpp20_containers examples/cpp20_containers.cpp)
target_compile_features(cpp20_containers PUBLIC cxx_std_20)
target_link_libraries(cpp20_containers common)
target_link_libraries(cpp20_containers PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
add_test(cpp20_containers cpp20_containers)
if (MSVC)
target_compile_options(cpp20_containers PRIVATE /bigobj)
Expand All @@ -132,12 +140,12 @@ endif()
if (NOT MSVC)
add_executable(cpp20_echo_server examples/cpp20_echo_server.cpp)
target_compile_features(cpp20_echo_server PUBLIC cxx_std_20)
target_link_libraries(cpp20_echo_server common)
target_link_libraries(cpp20_echo_server PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
endif()

add_executable(cpp20_resolve_with_sentinel examples/cpp20_resolve_with_sentinel.cpp)
target_compile_features(cpp20_resolve_with_sentinel PUBLIC cxx_std_20)
target_link_libraries(cpp20_resolve_with_sentinel common)
target_link_libraries(cpp20_resolve_with_sentinel PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
#add_test(cpp20_resolve_with_sentinel cpp20_resolve_with_sentinel)
if (MSVC)
target_compile_options(cpp20_resolve_with_sentinel PRIVATE /bigobj)
Expand All @@ -146,7 +154,7 @@ endif()

add_executable(cpp20_json examples/cpp20_json.cpp)
target_compile_features(cpp20_json PUBLIC cxx_std_20)
target_link_libraries(cpp20_json common)
target_link_libraries(cpp20_json PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
add_test(cpp20_json cpp20_json)
if (MSVC)
target_compile_options(cpp20_json PRIVATE /bigobj)
Expand All @@ -157,7 +165,7 @@ if (Protobuf_FOUND)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS examples/person.proto)
add_executable(cpp20_protobuf examples/cpp20_protobuf.cpp ${PROTO_SRCS} ${PROTO_HDRS})
target_compile_features(cpp20_protobuf PUBLIC cxx_std_20)
target_link_libraries(cpp20_protobuf common ${Protobuf_LIBRARIES})
target_link_libraries(cpp20_protobuf PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common ${Protobuf_LIBRARIES})
target_include_directories(cpp20_protobuf PUBLIC ${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
add_test(cpp20_protobuf cpp20_protobuf)
if (MSVC)
Expand All @@ -168,7 +176,7 @@ endif()

add_executable(cpp20_subscriber examples/cpp20_subscriber.cpp)
target_compile_features(cpp20_subscriber PUBLIC cxx_std_20)
target_link_libraries(cpp20_subscriber common)
target_link_libraries(cpp20_subscriber PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
if (MSVC)
target_compile_options(cpp20_subscriber PRIVATE /bigobj)
target_compile_definitions(cpp20_subscriber PRIVATE _WIN32_WINNT=0x0601)
Expand All @@ -177,8 +185,7 @@ endif()
add_executable(cpp20_intro_tls examples/cpp20_intro_tls.cpp)
target_compile_features(cpp20_intro_tls PUBLIC cxx_std_20)
add_test(cpp20_intro_tls cpp20_intro_tls)
target_link_libraries(cpp20_intro_tls OpenSSL::Crypto OpenSSL::SSL)
target_link_libraries(cpp20_intro_tls common)
target_link_libraries(cpp20_intro_tls PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common)
if (MSVC)
target_compile_options(cpp20_intro_tls PRIVATE /bigobj)
target_compile_definitions(cpp20_intro_tls PRIVATE _WIN32_WINNT=0x0601)
Expand All @@ -187,7 +194,7 @@ endif()
add_executable(cpp20_low_level_async tests/cpp20_low_level_async.cpp)
target_compile_features(cpp20_low_level_async PUBLIC cxx_std_20)
add_test(cpp20_low_level_async cpp20_low_level_async)
target_link_libraries(cpp20_low_level_async common)
target_link_libraries(cpp20_low_level_async PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common boost_redis_src)
if (MSVC)
target_compile_options(cpp20_low_level_async PRIVATE /bigobj)
target_compile_definitions(cpp20_low_level_async PRIVATE _WIN32_WINNT=0x0601)
Expand All @@ -209,6 +216,7 @@ endif()

add_executable(cpp17_low_level_sync tests/cpp17_low_level_sync.cpp)
target_compile_features(cpp17_low_level_sync PUBLIC cxx_std_17)
target_link_libraries(cpp17_low_level_sync PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common boost_redis_src)
add_test(cpp17_low_level_sync cpp17_low_level_sync)
if (MSVC)
target_compile_options(cpp17_low_level_sync PRIVATE /bigobj)
Expand All @@ -217,7 +225,7 @@ endif()

add_executable(test_conn_exec tests/conn_exec.cpp)
target_compile_features(test_conn_exec PUBLIC cxx_std_20)
target_link_libraries(test_conn_exec test_common)
target_link_libraries(test_conn_exec PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common)
add_test(test_conn_exec test_conn_exec)
if (MSVC)
target_compile_options(test_conn_exec PRIVATE /bigobj)
Expand All @@ -226,7 +234,7 @@ endif()

add_executable(test_conn_exec_retry tests/conn_exec_retry.cpp)
target_compile_features(test_conn_exec_retry PUBLIC cxx_std_20)
target_link_libraries(test_conn_exec_retry test_common)
target_link_libraries(test_conn_exec_retry PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common)
add_test(test_conn_exec_retry test_conn_exec_retry)
if (MSVC)
target_compile_options(test_conn_exec_retry PRIVATE /bigobj)
Expand All @@ -235,7 +243,7 @@ endif()

add_executable(test_conn_push tests/conn_push.cpp)
target_compile_features(test_conn_push PUBLIC cxx_std_20)
target_link_libraries(test_conn_push test_common)
target_link_libraries(test_conn_push PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common)
add_test(test_conn_push test_conn_push)
if (MSVC)
target_compile_options(test_conn_push PRIVATE /bigobj)
Expand All @@ -244,6 +252,7 @@ endif()

add_executable(test_conn_quit tests/conn_quit.cpp)
target_compile_features(test_conn_quit PUBLIC cxx_std_17)
target_link_libraries(test_conn_quit PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common)
add_test(test_conn_quit test_conn_quit)
if (MSVC)
target_compile_options(test_conn_quit PRIVATE /bigobj)
Expand All @@ -252,7 +261,7 @@ endif()

add_executable(test_conn_reconnect tests/conn_reconnect.cpp)
target_compile_features(test_conn_reconnect PUBLIC cxx_std_20)
target_link_libraries(test_conn_reconnect common test_common)
target_link_libraries(test_conn_reconnect PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common)
add_test(test_conn_reconnect test_conn_reconnect)
if (MSVC)
target_compile_options(test_conn_reconnect PRIVATE /bigobj)
Expand All @@ -262,14 +271,15 @@ endif()
add_executable(test_conn_tls tests/conn_tls.cpp)
add_test(test_conn_tls test_conn_tls)
target_compile_features(test_conn_tls PUBLIC cxx_std_17)
target_link_libraries(test_conn_tls OpenSSL::Crypto OpenSSL::SSL)
target_link_libraries(test_conn_tls PRIVATE OpenSSL::Crypto OpenSSL::SSL boost_redis_src)
if (MSVC)
target_compile_options(test_conn_tls PRIVATE /bigobj)
target_compile_definitions(test_conn_tls PRIVATE _WIN32_WINNT=0x0601)
endif()

add_executable(test_low_level tests/low_level.cpp)
target_compile_features(test_low_level PUBLIC cxx_std_17)
target_link_libraries(test_low_level PRIVATE OpenSSL::Crypto OpenSSL::SSL boost_redis_src)
add_test(test_low_level test_low_level)
if (MSVC)
target_compile_options(test_low_level PRIVATE /bigobj)
Expand All @@ -279,14 +289,15 @@ endif()
add_executable(test_conn_run_cancel tests/conn_run_cancel.cpp)
target_compile_features(test_conn_run_cancel PUBLIC cxx_std_20)
add_test(test_conn_run_cancel test_conn_run_cancel)
target_link_libraries(test_conn_run_cancel PRIVATE OpenSSL::Crypto OpenSSL::SSL boost_redis_src)
if (MSVC)
target_compile_options(test_conn_run_cancel PRIVATE /bigobj)
target_compile_definitions(test_conn_run_cancel PRIVATE _WIN32_WINNT=0x0601)
endif()

add_executable(test_conn_exec_cancel tests/conn_exec_cancel.cpp)
target_compile_features(test_conn_exec_cancel PUBLIC cxx_std_20)
target_link_libraries(test_conn_exec_cancel common test_common)
target_link_libraries(test_conn_exec_cancel PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common boost_redis_src)
add_test(test_conn_exec_cancel test_conn_exec_cancel)
if (MSVC)
target_compile_options(test_conn_exec_cancel PRIVATE /bigobj)
Expand All @@ -295,7 +306,7 @@ endif()

add_executable(test_conn_exec_cancel2 tests/conn_exec_cancel2.cpp)
target_compile_features(test_conn_exec_cancel2 PUBLIC cxx_std_20)
target_link_libraries(test_conn_exec_cancel2 common test_common)
target_link_libraries(test_conn_exec_cancel2 PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common boost_redis_src)
add_test(test_conn_exec_cancel2 test_conn_exec_cancel2)
if (MSVC)
target_compile_options(test_conn_exec_cancel2 PRIVATE /bigobj)
Expand All @@ -304,7 +315,7 @@ endif()

add_executable(test_conn_exec_error tests/conn_exec_error.cpp)
target_compile_features(test_conn_exec_error PUBLIC cxx_std_17)
target_link_libraries(test_conn_exec_error common test_common)
target_link_libraries(test_conn_exec_error PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common boost_redis_src)
add_test(test_conn_exec_error test_conn_exec_error)
if (MSVC)
target_compile_options(test_conn_exec_error PRIVATE /bigobj)
Expand All @@ -313,7 +324,7 @@ endif()

add_executable(test_conn_echo_stress tests/conn_echo_stress.cpp)
target_compile_features(test_conn_echo_stress PUBLIC cxx_std_20)
target_link_libraries(test_conn_echo_stress common test_common)
target_link_libraries(test_conn_echo_stress PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common boost_redis_src)
add_test(test_conn_echo_stress test_conn_echo_stress)
if (MSVC)
target_compile_options(test_conn_echo_stress PRIVATE /bigobj)
Expand All @@ -322,6 +333,7 @@ endif()

add_executable(test_request tests/request.cpp)
target_compile_features(test_request PUBLIC cxx_std_17)
target_link_libraries(test_request PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common boost_redis_src)
add_test(test_request test_request)
if (MSVC)
target_compile_options(test_request PRIVATE /bigobj)
Expand All @@ -330,7 +342,7 @@ endif()

add_executable(test_issue_50 tests/issue_50.cpp)
target_compile_features(test_issue_50 PUBLIC cxx_std_20)
target_link_libraries(test_issue_50 common)
target_link_libraries(test_issue_50 PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common boost_redis_src)
add_test(test_issue_50 test_issue_50)
if (MSVC)
target_compile_options(test_issue_50 PRIVATE /bigobj)
Expand All @@ -339,7 +351,7 @@ endif()

add_executable(test_conn_check_health tests/conn_check_health.cpp)
target_compile_features(test_conn_check_health PUBLIC cxx_std_17)
target_link_libraries(test_conn_check_health common)
target_link_libraries(test_conn_check_health PRIVATE OpenSSL::Crypto OpenSSL::SSL examples_common boost_redis_src)
add_test(test_conn_check_health test_conn_check_health)
if (MSVC)
target_compile_options(test_conn_check_health PRIVATE /bigobj)
Expand All @@ -348,7 +360,7 @@ endif()

add_executable(test_run tests/run.cpp)
target_compile_features(test_run PUBLIC cxx_std_17)
target_link_libraries(test_run test_common)
target_link_libraries(test_run PRIVATE OpenSSL::Crypto OpenSSL::SSL test_common boost_redis_src)
add_test(test_run test_run)
if (MSVC)
target_compile_options(test_run PRIVATE /bigobj)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ Acknowledgement to people that helped shape Boost.Redis
* Mohammad Nejati ([ashtum](https://github.com/ashtum)): For pointing out scenarios where calls to `async_exec` should fail when the connection is lost.
* Klemens Morgenstern ([klemens-morgenstern](https://github.com/klemens-morgenstern)): For useful discussion about timeouts, cancellation, synchronous interfaces and general help with Asio.
* Vinnie Falco ([vinniefalco](https://github.com/vinniefalco)): For general suggestions about how to improve the code and the documentation.
* Bram Veldhoen ([bveldhoen](https://github.com/bveldhoen)): For contributing a Redis streams example.
* Bram Veldhoen ([bveldhoen](https://github.com/bveldhoen)): For contributing a Redis-streams example.

Also many thanks to all individuals that participated in the Boost
review
Expand Down
1 change: 1 addition & 0 deletions examples/cpp17_intro_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// Include this in no more than one .cpp file.
#include <boost/redis/src.hpp>

namespace net = boost::asio;
using boost::redis::sync_connection;
using boost::redis::request;
using boost::redis::response;
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp20_chat_room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
request req;
req.push("SUBSCRIBE", "channel");

while (!conn->is_cancelled()) {
while (conn->will_reconnect()) {

// Subscribe to channels.
co_await conn->async_exec(req);
Expand Down
8 changes: 4 additions & 4 deletions examples/cpp20_intro_tls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* accompanying file LICENSE.txt)
*/

#include <boost/redis/ssl/connection.hpp>
#include <boost/redis/connection.hpp>
#include <boost/asio/deferred.hpp>
#include <boost/asio/use_awaitable.hpp>
#include <boost/asio/detached.hpp>
Expand All @@ -18,7 +18,7 @@ using boost::redis::request;
using boost::redis::response;
using boost::redis::config;
using boost::redis::logger;
using connection = net::deferred_t::as_default_on_t<boost::redis::ssl::connection>;
using connection = net::deferred_t::as_default_on_t<boost::redis::connection>;

auto verify_certificate(bool, net::ssl::verify_context&) -> bool
{
Expand All @@ -28,13 +28,13 @@ auto verify_certificate(bool, net::ssl::verify_context&) -> bool

auto co_main(config cfg) -> net::awaitable<void>
{
cfg.use_ssl = true;
cfg.username = "aedis";
cfg.password = "aedis";
cfg.addr.host = "db.occase.de";
cfg.addr.port = "6380";

net::ssl::context ctx{net::ssl::context::sslv23};
auto conn = std::make_shared<connection>(co_await net::this_coro::executor, ctx);
auto conn = std::make_shared<connection>(co_await net::this_coro::executor);
conn->async_run(cfg, {}, net::consign(net::detached, conn));

request req;
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp20_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
request req;
req.push("SUBSCRIBE", "channel");

while (!conn->is_cancelled()) {
while (conn->will_reconnect()) {

// Reconnect to channels.
co_await conn->async_exec(req);
Expand Down
Loading