-
Notifications
You must be signed in to change notification settings - Fork 354
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
Add function to allow std::variant of supported redis types #138
Comments
Yes, it's great! I'll put it on the TODO list. Thanks for the advice!
In fact, it also supports parsing the result to bool (integer reply that only has value 0 and 1) and double (string reply which can be converted to a double).
So far, you can do it in an ugly way, i.e. define a tuple which matches the output of memory stats:
Thanks again for the proposal! If I have any progress on it, I'll let you know:) Regards |
Thanks for picking this up! Good to hear that double and bool are also supported. C++ exception with description "Expect tuple reply with 50elements" thrown in the test body. Not sure what's wrong, as type/size mismatches seem relatively hard to debug. The data (size and types) seems to be correct in a gdb session. Another workaround that I've implemented in the mean time is through a Python wrapper function that returns a dictionary from which I can select and return the desired value(s). This call is not performance critical, so it's good enough. |
That means the number of elements in the reply is NOT 50. You'd better use redis-cli to check the exact number and format of the
Regards |
Also I've tried to implement parsing reply to variant. The code is on dev branch, and you can try it:
However, as I mentioned in previous comment, you need to check out the format of your redis server's output. If the result contains a
If you still have any problem, feel free to let me know. Regards |
Interesting... I can reproduce your case with 52 response elements. Any thoughts on this? |
Great! Will try asap. |
My testing shows that the implemented Variant functionality in the dev branch works as requested. Thanks a lot for the quick implementation! |
By the way, a more compact way to print a variant is; |
If there’s a db that is not empty, the command will show some stat on the db. That’s why you got 50 elements if you call flushall, and got 52 elements if you set some data to redis.
Thanks for the suggestion! However, instead of nullptr_t, I’m thinking about using std::monostate as a placeholder for unknown types. That might be a c++ idiom. Still need some research. Thanks again! Regards |
std::variant is also new to me, as is std::monostate. Indeed std::monostate seems to be a more generic approach towards "don't care" types. Plus, you get the functionality for free with variant. |
@chill1n I refactor the code and add monostate support. The latest code has been merged into master branch. You can take a try :) Regards |
Thanks for the quick resolution. I've tested the master branch and can confirm that variant with monostate is working as expected. I will close this issue. |
I have a specific problem with simply parsing the output of "memory stats" using the generic command("memory", "stats") call.
I've tried the obvious but it seems complicated with the current functionality.
Would it not be a generic extension to this library to add support for std::variant of supported redis types?
At this moment the current library supports STRING and INTEGER (not BOOL and DOUBLE yet), but that would suffice for most cases. An example output of "memory stats" is given below (which could be mapped to 25 pairs of either <string,long long> or <string,string>, or a single array of std::variant<string,long long>).
Any thoughts on how to approach parsing of "memory stats" with current functionality?
Any thoughts on the proposed support for std::variant?
The text was updated successfully, but these errors were encountered: