Comments (5)
Hello Giorgio,
There is no generic answer to your question, as the array response in Redis is recursive structure, i.e. it might be array of arrays of arrays of mixture string/ints/arrays etc.
So, you should know your redis command, and it's expected output. Here are a few examples. Let's assume that array is flat array of strings, that for debug we'd like to dump all of them into cout
. It can be done as:
template <typename Iterator>
struct my_dumper : public boost::static_visitor<void> {
template <typename T> void operator()(const T & /*value*/) const {
/* NOOP */
}
void
operator()(const r::markers::array_holder_t<Iterator> &value) const {
for(auto& item: value.elements) {
auto* str = boost::get<r::markers::string_t<Iterator>>(&item);
if (str) {
std::string copy{str->from, str->to};
std::cout << "item = " << copy << "\n";
}
}
}
};
If you'd like to concatenate all strings are return as std::string
it can be done as
template <typename Iterator>
struct my_extractor : public boost::static_visitor<std::string> {
template <typename T> std::string operator()(const T & /*value*/) const { return ""; }
std::string operator()(const r::markers::array_holder_t<Iterator> &value) const {
std::string result;
for(auto& item: value.elements) {
auto* str = boost::get<r::markers::string_t<Iterator>>(&item);
if (str) {
std::string copy{str->from, str->to};
result += copy;
}
}
return result;
}
};
The operators defined above then needs to be applied like :
my_dumper<Iterator> dumper;
boost::apply_visitor(dumper, r.result);
my_extractor<Iterator> extractor;
auto str = boost::apply_visitor(extractor, r.result);
Please note, there is always the "fail-branch", in the operators (my_dumper
and my_extractor
) above, i.e. some default behavior when redis replied with error, or, when you expected string
but it replied with int
(its probably bug in your code).
from cpp-bredis.
Thanks. Ok. I will try and help out to use it. Your library is pretty good and fast. I have another issue, i want to send out a custom promise and give the possibility to use multiple threads. At the current moment, i set a context and set the value of the promise after the read. Is it the best approach or is it better use your promise example?
for (size_t i = 0; i < workers_count; i++) {
threadpool_.emplace_back(std::thread([this]()
{
io_context_.run();
}));
}
from cpp-bredis.
You should do strand
-protection of your connection. As soon as it is safe in MT-environment, you can safely read/write to it using bredis
from cpp-bredis.
Currently my problem is to parse the redisgraph module result. Before starting, do you support https://redis.io/topics/protocol ? How can i log the response structure to standard output? Do you provide already something?
from cpp-bredis.
Yes, bredis complies redis-protocol. If it not, please send an example.
There are a few techniques for logging/development:
-
You can try use an proxying socket like here
https://github.com/basiliscos/cpp-bredis/blob/master/t/SocketWithLogging.hpp
andhttps://github.com/basiliscos/cpp-bredis/blob/master/t/12-basic-types.cpp#L23
-
Another, more simple way, is to use
Wireshark
tool to log what's going on. (i.e. get actual bits) -
I'm not sure what is
redisgraph
, I assume it is other protocol. So, generally, you should write your own layer ofredisgraph
on top of thebredis
, and only then you it in your final app. Otherwise, mixing app-logic and protocol logic might lead to bad code style.
from cpp-bredis.
Related Issues (20)
- Add `conan` package manager support
- Mac build failure HOT 4
- Redis Stream example HOT 1
- Unclear how to use drop_result. HOT 13
- Connection does not support reconnect HOT 1
- Add a short cut header include file maybe? HOT 3
- performance improvements ideas HOT 1
- Consider (minimal) C++11 support HOT 4
- Fix CMake warning while using CMake > 2.6.0 HOT 2
- Doesn compile on WSL2 (Linux ubuntu gcc-8) HOT 3
- wrong command_size on empty value HOT 1
- Add `hunter` package manager support HOT 1
- why do we need boost 1.69 ? how about boost 1.66 HOT 4
- Wrapping sockets with Bredis::Connection HOT 4
- Boost 1.74 and BOOST_ASIO_NO_DEPRECATED HOT 2
- cmake boost on windows HOT 1
- subscriptions to multiple channels issue HOT 2
- Clarification regarding multiple messages HOT 5
- Alternative Redis client proposed for inclusion in Boost
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpp-bredis.