Last active
September 22, 2022 13:28
-
-
Save bjosv/6b61dbb11193fdfd36cbcc82473d1036 to your computer and use it in GitHub Desktop.
FetchContent example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake -DDISABLE_TESTS=OFF -DREDIS_PLUS_PLUS_BUILD_TEST=OFF .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.24) | |
project(examples LANGUAGES CXX) | |
include(FetchContent) | |
FetchContent_Declare( | |
hiredis | |
GIT_REPOSITORY https://github.com/redis/hiredis | |
GIT_TAG origin/master | |
GIT_SHALLOW TRUE | |
# Set path where source is placed | |
SOURCE_DIR _deps/hiredis | |
# Make sure redis++ finds fetched content with its find_package() | |
OVERRIDE_FIND_PACKAGE | |
) | |
FetchContent_MakeAvailable(hiredis) | |
# Set include directory to enable redis++ to find it | |
include_directories(${CMAKE_BINARY_DIR}/_deps) | |
FetchContent_Declare( | |
redis-plus-plus | |
GIT_REPOSITORY https://github.com/sewenew/redis-plus-plus | |
GIT_TAG origin/master | |
GIT_SHALLOW TRUE | |
) | |
FetchContent_MakeAvailable(redis-plus-plus) | |
add_executable(test | |
main.cc | |
) | |
target_link_libraries(test | |
redis++ | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#include <sw/redis++/redis++.h> | |
#include <redis++.h> | |
#include <iostream> | |
int main() | |
{ | |
auto redis = sw::redis::Redis("tcp://127.0.0.1:6379"); | |
redis.set("key", "value"); | |
auto val = redis.get("key"); | |
if (val) { | |
std::cout << "Got: " << *val << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment