From 8cf6414295c3b1dbf96e96e586143f1fc36cabae Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 11 Jan 2022 07:40:24 -0500 Subject: [PATCH] redis: minor stylistic improvements and fixes --- lib/nodes/redis.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/nodes/redis.cpp b/lib/nodes/redis.cpp index 84d7c837c..fd952b51f 100644 --- a/lib/nodes/redis.cpp +++ b/lib/nodes/redis.cpp @@ -140,12 +140,16 @@ void RedisConnection::loop() subscriber.consume(); } catch (const sw::redis::TimeoutError &e) { + logger->debug("Timeout."); continue; } catch (const sw::redis::ReplyError &e) { + logger->error("Error: {}", e.what()); continue; } catch (const sw::redis::Error &e) { + logger->error("Error: {}. Recreating subscriber", e.what()); + /* Create a new subscriber */ subscriber = context.subscriber(); } @@ -177,9 +181,9 @@ int redis_get(NodeCompat *n, struct Sample * const smps[], unsigned cnt) case RedisMode::HASH: { struct Sample *smp = smps[0]; - for (unsigned j = 0; j < n->getInputSignals(false)->size(); j++) { - auto sig = n->getInputSignals(false)->getByIndex(j); - auto *data = &smp->data[j]; + unsigned j = 0; + for (auto sig : *n->getInputSignals(false)) { + auto *data = &smp->data[j++]; *data = sig->init; } @@ -546,6 +550,7 @@ int villas::node::redis_start(NodeCompat *n) int villas::node::redis_stop(NodeCompat *n) { + int ret; auto *r = n->getData(); r->conn->stop(); @@ -639,7 +644,8 @@ int villas::node::redis_write(NodeCompat *n, struct Sample * const smps[], unsig std::unordered_map kvs; - for (unsigned j = 0; j < MIN(smp->signals->size(), smp->length); j++) { + unsigned len = MIN(smp->signals->size(), smp->length); + for (unsigned j = 0; j < len; j++) { const auto sig = smp->signals->getByIndex(j); const auto *data = &smp->data[j];