-
Notifications
You must be signed in to change notification settings - Fork 353
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
Initializing Redis++ on IDE #5
Comments
Hi @afifzaki Your code is the simplest way to initializing a connection to Redis. The problem is that you didn't link
See how to install hiredis for details. If you still have any problem with Regards |
Hi @afifzaki I updated the above comment. If you are using GCC, you need to specify
Also, if you link the dynamic libraries, when you running your application, you might get the following error:
Check this for solution. Regards |
Hi, I'm already following every instruction you made (the installation instruction is very clear). Why this is happening? |
Hi @afifzaki If you're using CLion, you should modify the related CMakeLists.txt file to add The CMakeLists.txt should looks like the following:
If you installed If you're using code block, this might be helpful for how to add dependencies. Regards |
Hi, Good work, keep it up. |
I'm glad that you like Thank you again for finding the documentation bug :) Regards |
hi @sewenew @afifzaki , `cmake_minimum_required(VERSION 3.12) set(CMAKE_CXX_STANDARD 14) add_executable(${PROJECT_NAME} main.cpp ) find_path(HIREDIS_INC_DIR hiredis) find_library(HIREDIS_LIB_DIR hiredis) find_path(REDIS_PLUS_PLUS_INC_DIR sw) find_library(REDIS_PLUS_PLUS_LIB_DIR redis++) I have troubled with this problem two days, but when I use the command line , it works correctly: g++ -std=c++11 -I/usr/local/app/redis-plus-plus/include -o redis main.cpp -L/usr/local/app/hiredis/lib -lhiredis -L/usr/local/app/redis-plus-plus/lib -lredis++ -pthread ps: $ENV{REDIS_PLUS_PLUS_INC_DIR} = /usr/local/app/redis-plus-plus/include Thanks |
@yitian108 Your CMakeLists.txt is incorrect. find_path and find_library will try to find the header and lib path, and save it into the variables you specified. So when you try to call target_include_directories and target_link_libraries, you should use these variables as parameters:
Also, instead of set the environment variable, you should use -DCMAKE_PREFIX_PATH command line arguments to specify the installation path of hiredis and redis++ when running cmake. So that find_path and find_library will correctly find the location and set those variables. Please check cmake's doc for more details on how to add dependency for a cmake project. Regards |
Hi @sewenew ,thank you for replying this, I set these environment variables as below, and it real works good in the command line: also , I run cmake, I used the options -DCMAKE_PREFIX_PATH -DCMAKE_INSTALL_PREFIX etc, please see below: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/app/hiredis -DCMAKE_INSTALL_PREFIX=/usr/local/app/redis-plus-plus .. that's I really don't know why it is works good with hiredis and in command line, only does not work with redis++ Regards |
I use the simple cmakelists.txt as attachment, and message() them in console, the result is the same, can't find the library redis++, I don't know whether it related with the version of clion. I think it should not. |
@yitian108 Since you install hiredis and redis-plus-plus in different paths. You should specify both path to -DCMAKE_PREFIX_PATH, and separate them with ;. Also, in your case, if you don't need to install the binary to some where, you don't need to use the -DCMAKE_INSTALL_PATH.
Again, these environment variable has nothing to do with cmake building. Regards |
Hi @sewenew , thanks for your suggestion, I found some interesting things while I reinstall the library redis++, if I use the command as you involved above, the console will report there is no the path of CMakelists.txt, last, if the app installed in default directory, the code can be built successfully in Clion, but run failed, it reported: /home/yh/dev/cpp/redis/cmake-build-debug/redis: error while loading shared libraries: libredis++.so: cannot open shared object file: No such file or directory let me check the others of the cmakelists.txt again. ps: I want to know how the cmake can identify correctly about the variables HIREDIS_HEADER, REDIS_PLUS_PLUS_HEADER, REDIS_PLUS_PLUS_LIB, etc. Does it mean I should set them first before using, some like: set (HIREDIS_HEADER /usr/local/app/hiredis/include/) Regards |
My bad. On Linux, you should use : to separate the paths. ; works for Windows. Check the doc for detail.
You should set LD_LIBRARY_PATH before running your executable. Check the doc for more info. Sorry, but I'm not an expert on cmake. If you have questions on cmake internals, or confused by comments above, you'd better ask an expert for help. Sorry again... Regards |
Great! Your suggestion really good for me, and I checked the cmakelists.txt again, and sloved it smoothly. Since I am the beginner of learning redis, I want to find a better c++ library for redis, so I choosed the redis++ as the first library. If you have some good examples for learning this, could you pls share them with me? Thanks again |
@yitian108 You can check the test code for more examples. Regards |
@sewenew , thank you sewenew, I believe the test will give me much help about learning the library, but sorry for my three questions: Regards |
Hi @sewenew, sorry for the trouble, may I know how to delete a key with pattern, i.e. if I need to delete the keys that start with "abc", so, I try to edit as redis.del("abc*"), it seems not to delete the keys like abc12, abcd, abcc etc. |
The master branch contains the test files. Check the 'test' directory.
This question is beyond the scope of redis-plus-plus. You'd better seek help from somewhere else, e.g. stackoverflow's redis topic or redis' google groups.
If you have problem with redis-plus-plus, you can open a new issue, instead of asking questions under this issue. Since these question has nothing to do with the origin problem, i.e. how to build redis-plus-plus.
Again, this is not a redis-plus-plus building problem. You'd better seek help from stackoverflow or google for it: how to remove redis keys matching a pattern. Regards |
Hi @sewenew using namespace sw::redis; but I have this result Could you help me? |
@cupid-gracer Did you install Redis-plus-plus with C++17 while compile your application code with C++11? In that case, you need to compile your application with C++17. |
Great! |
This might be related. Haven't been able to solve it yet. Error: Relevant Lines from CMakeLists.txt: Code
The undefined symbol error is emitted for both |
check out this link : https://stackoverflow.com/questions/66417946/how-to-import-package-in-cmake-from-vcpkg I think you are missing target_include_directories |
Hi, thanks for your work.
I try to compile a simple cpp program:
#include <sw/redis++/redis++.h>
using namespace sw::redis;
int main()
{
auto redis = Redis("tcp://127.0.0.1:6379");
return 0;
}
but that script generate an error:
/home/user/Developments/clang/redis_test/main.cpp:10: undefined reference to
sw::redis::Redis::Redis(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' CMakeFiles/redis_test.dir/main.cpp.o: In function
sw::redis::Connection::ContextDeleter::operator((redisContext*) const':/usr/local/include/sw/redis++/connection.h:132: undefined reference to `redisFree'
Is there a simplest example do you provide for initiating redisDB?
The text was updated successfully, but these errors were encountered: