tdv/redis-cpp

bad cast while execute "hset"

Closed this issue · 1 comments

while execute hset , the type cast will fail and throw exception "bad cast" while cast to string, because the value type of response is integer, I should use as_integer() to cast properly.
But I was developing an app that accept the input from user, so the response from redis will be various, so I need to judge the type of type, it's so inconvenient.
Why not add a method to automatically judge the type and convert it, instead of letting the programmer to judge.

tdv commented

Hi.

The library has developed in order to use in many different cases therefore there are a few inconveniences at first glance, but on the other hand that gives more flexibility for tailoring the library according to your requirements.

For instance, you can't directly cast results from string to int (by design). For solving this issue you have to use methods that start from "is_" having known the type of the response or use std::visit likewise in RESP example and other. And of course, you can fork the library, and will tailor to your needs. Why not?

Nevertheless, I can help you with your issue and maybe include the solution to the library. Please, publish here your code and the solution which you would prefer to have. I'll try to work out something convenient and common to use.

Regards.