[QUESTION] Link error when using Subscriber class in redis-plus-plus
hardworker0012 opened this issue · 7 comments
I built redis++, created a library and applied it to my project well. The creation of AsyncRedis worked fine and commands like ping, hset, hgetall command worked fine. I also checked the asynchronous behavior using future.then. And I tried to use pub/sub, and publish works fine,
but when I try to call the subscribe function using AsyncRedis.subscriber, I get the link error below, but even if I find and fix the suspicious part, it doesn't work. I'm writing to ask if you can help me solve it.
I've checked that the redis++ library build includes AsyncSubscriber, and there's no reason for the link error. I've been trying to build it for two days and haven't been able to solve it, so I'm posting a question.
-Link error message
"error LNK2019: "public: class boost::future __cdecl sw::redis::AsyncSubscriber::subscribe(class std::basic_string_view<char,struct std::char_traits > const &)" (?subscribe@AsyncSubscriber@redis@sw@@qeaa?AV? $future@X@boost@@aebv?$basic_string_view@DU?$char_traits@D@std@@@std@@@z)"public: bool __cdecl RedisTest::Initialize(int,unsigned char,char const *,int,char const *)" (?Initialize@RedisTest@@QEAA_NHEPEBDH0@Z)"
P.S. redis++ is a very good library. Many thanks to you.
My question was sent through a translator, so I don't know if it made sense.
Environment:
OS: Windows11
Compiler: Visual Studio 2022(17.6.5)
redis : version 7.2.1
hiredis version: version 1.2.0
redis-plus-plus version: 1.3.10
I want to use Redis++'s Subscribe feature.
I've left a comment on stackoverflow, please check it:
Looks like you used the continuation feature with boost. In that case, you should install boost first, enable the boost future support with -DREDIS_PLUS_PLUS_ASYNC_FUTURE=boost, and link boost with your application. Check this for detail.
Thank you for your help.
I solved the problem, I didn't figure out where it was working, but there seems to be some command that determines which header to use, boost or std, and copies the file.
As a result, async_utils.h, which uses std::future, was overwritten at build time, so when I tried to use boost::future as the build output lib, I got a link error.
My solution was to override the file to always overwrite async_utils.h with the boost version.
As an additional question, is using only redis++_static.lib the same as using redis++.lib and redis++.dll?
Also, if I subscribe to a channel as a "Subscriber or AsyncSubscriber" and am receiving messages, is it okay to subscribe to the channel additionally in a separate thread? The reason I ask is that I've seen it work without any issues when I've done it, but I'm wondering if this is the correct way to use it.
Redis++ is a great library that I really enjoy using. I really appreciate it.
Translated with www.DeepL.com/Translator (free version)
As an additional question, is using only redis++_static.lib the same as using redis++.lib and redis++.dll?
redis++_static_lib is static library, while others are dynamic library. You can use either. It depends on whether you want to link it statically or dynamically.
if I subscribe to a channel as a "Subscriber or AsyncSubscriber" and am receiving messages, is it okay to subscribe to the channel additionally in a separate thread?
Do you mean that you have two threads, both threads subscribe to the same channel with different Subscriber
or AsyncSubscriber
? Yes, you can do that safely. Since different subscribers are dependent objects and has nothing to do with each other.
Regards
I'm sorry. I think I may have misunderstood the meaning of my question, so let me rephrase it.
~MainThread
{
_AsyncSubscriber->on_meta([this](Subscriber::MsgType type, OptionalString OptionParamStr, long long num)
_AsyncSubscriber->on_message([this](std::string channel, std::string msg)
_AsyncSubscriber->on_pmessage([this](std::string pattern, std::string channel, std::string msg)
...
_AsyncSubscriber->psubscribe(pattern);
**// Receiving a message from an IO Thread...**
...
...
Make_SubThread()...
}
~SubThread
{
_AsyncSubscriber->psubscribe(addedPattern) //
_AsyncSubscriber->subscribe(addedChannel) //
}
After creating the _AsyncSubscriber in the main thread and registering each callback as above. subscribe to the channel, and then while it's Receiving the message I'm wondering if it's ThreadSafe to subscribe to additional channels in a subthread?
Yes, the code you given is thread-safe.
Regards
Thank you for your helpful reply. May you always be happy. Thank you so much