sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.64k stars 351 forks source link

[QUESTION] #510

Closed mike1821 closed 1 year ago

mike1821 commented 1 year ago

Describe the problem Hello I am trying to use the provided ReplyUPtr as a return value for an async interface implementation which I am working on.

m_db_client.command<ReplyUPtr>(command , [this]
            (std::future<ReplyUPtr> &&fut) {    

                try {
                    ...
                }
               catch{
                   ...
               }
          });

However, I am getting the following compilation error.

reply.h:74:17: error: no matching function for call to 'parse(sw::redis::reply::ParseTag<std::unique_ptr<redisReply, sw::redis::ReplyDeleter> >, redisReply&)'
     return parse(ParseTag<T>(), reply);
            ~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/sw/redis++/reply.h:73:10: note: candidate: 'template<class T> T sw::redis::reply::parse(redisReply&)'
 inline T parse(redisReply &reply) {
          ^~~~~
/usr/include/sw/redis++/reply.h:73:10: note:   template argument deduction/substitution failed:
/usr/include/sw/redis++/reply.h:74:17: note:   candidate expects 1 argument, 2 provided
     return parse(ParseTag<T>(), reply);
            ~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/sw/redis++/reply.h:441:3: note: candidate: 'template<class T, typename std::enable_if<sw::redis::IsAssociativeContainer<T>::value, int>::type <anonymous> > T sw::redis::reply::parse(sw::redis::reply::ParseTag<T>, redisReply&)'
 T parse(ParseTag<T>, redisReply &reply) {
   ^~~~~
/usr/include/sw/redis++/reply.h:441:3: note:   template argument deduction/substitution failed:
/usr/include/sw/redis++/reply.h:114:94: error: no type named 'type' in 'struct std::enable_if<false, int>'
 template <typename T, typename std::enable_if<IsAssociativeContainer<T>::value, int>::type = 0>
                                                                              ^

Did someone experienced a similar issue? Is there an example of using ReplyUPtr?

Environment:

sewenew commented 1 year ago

This is not supported.

Why do you want to parse it as a ReplyUPtr? Normally, you should specify the type you want to parse to. Say the return value is a number, you can parse it to a long long, if it's a completed type, you can parse it to a tuple or variant or STL container.

Regards

mike1821 commented 1 year ago

Hi, thank you for your reply.

The thing is that the return value is not the same in all cases. The command is processing a LUA script which in some cases might return an integer while on some other it might return a string...

Anyway, I suppose I will have to adapt the scripts in order to use the same return value in all scenarios.

Regards

sewenew commented 1 year ago

In that case, you can parse it as a std::variant, if you're using c++17. Check this for detail.

Regards

mike1821 commented 1 year ago

Much appreciated, I will check this