From 20c593815abc1f9e7d4a49d6ad5cf550f80945eb Mon Sep 17 00:00:00 2001 From: Charles Zinn Date: Sat, 20 Aug 2022 09:58:40 -0400 Subject: [PATCH 1/3] Support commands returning vector --- include/redox/client.hpp | 1 + src/client.cpp | 7 +++++++ src/command.cpp | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/include/redox/client.hpp b/include/redox/client.hpp index 12a95bc..c70a51b 100644 --- a/include/redox/client.hpp +++ b/include/redox/client.hpp @@ -372,6 +372,7 @@ class Redox { std::unordered_map *> commands_long_long_int_; std::unordered_map *> commands_null_; std::unordered_map> *> commands_vector_string_; + std::unordered_map> *> commands_vector_int_; std::unordered_map> *> commands_set_string_; std::unordered_map> *> commands_unordered_set_string_; diff --git a/src/client.cpp b/src/client.cpp index 4401035..e34f0fd 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -459,6 +459,7 @@ void Redox::processQueuedCommands(struct ev_loop *loop, ev_async *async, int rev } else if (rdx->processQueuedCommand(id)) { } else if (rdx->processQueuedCommand(id)) { } else if (rdx->processQueuedCommand>(id)) { + } else if (rdx->processQueuedCommand>(id)) { } else if (rdx->processQueuedCommand>(id)) { } else if (rdx->processQueuedCommand>(id)) { } else @@ -483,6 +484,7 @@ void Redox::freeQueuedCommands(struct ev_loop *loop, ev_async *async, int revent } else if (rdx->freeQueuedCommand(id)) { } else if (rdx->freeQueuedCommand(id)) { } else if (rdx->freeQueuedCommand>(id)) { + } else if (rdx->freeQueuedCommand>(id)) { } else if (rdx->freeQueuedCommand>(id)) { } else if (rdx->freeQueuedCommand>(id)) { } else { @@ -515,6 +517,7 @@ long Redox::freeAllCommands() { freeAllCommandsOfType() + freeAllCommandsOfType() + freeAllCommandsOfType() + freeAllCommandsOfType() + freeAllCommandsOfType>() + freeAllCommandsOfType>() + + freeAllCommandsOfType>() + freeAllCommandsOfType>(); } @@ -579,6 +582,10 @@ template <> unordered_map> *> &Redox::getCommandMap return commands_vector_string_; } +template <> unordered_map> *> &Redox::getCommandMap>() { + return commands_vector_int_; +} + template <> unordered_map> *> &Redox::getCommandMap>() { return commands_set_string_; } diff --git a/src/command.cpp b/src/command.cpp index 95907b8..408df5a 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -236,6 +236,17 @@ template <> void Command>::parseReplyObject() { } } +template <> void Command>::parseReplyObject() { + + if (!isExpectedReply(REDIS_REPLY_ARRAY)) + return; + + for (size_t i = 0; i < reply_obj_->elements; i++) { + redisReply *r = *(reply_obj_->element + i); + reply_val_.push_back(r->integer); + } +} + template <> void Command>::parseReplyObject() { if (!isExpectedReply(REDIS_REPLY_ARRAY)) @@ -268,6 +279,7 @@ template class Command; template class Command; template class Command; template class Command>; +template class Command>; template class Command>; template class Command>; From bad0de78db10b164341c8ca6abc3d32777b93058 Mon Sep 17 00:00:00 2001 From: Charles Zinn Date: Sat, 20 Aug 2022 10:07:03 -0400 Subject: [PATCH 2/3] Add example of SMISMEMBER returning a vector --- examples/data_types.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/data_types.cpp b/examples/data_types.cpp index c39fb7f..18bdec1 100644 --- a/examples/data_types.cpp +++ b/examples/data_types.cpp @@ -46,6 +46,18 @@ int main(int argc, char* argv[]) { for (const string& s : c.reply()) cout << s << " "; cout << endl; } + } + ); + + rdx.del("myset"); + rdx.commandSync(rdx.strToVec("SADD myset 2 3 5 7 11 13 17 19")); + rdx.command>(rdx.strToVec("SMISMEMBER myset 1 2 3 4 5"), + [&rdx](Command>& c) { + if(c.ok()) { + cout << "Are {1, 2, 3, 4, 5} in the set, respectively: "; + for (int i : c.reply()) cout << i << " "; + cout << endl; + } rdx.stop(); } ); From 6db3a4bb668b93736a42b6b8c55e88d1adc524c1 Mon Sep 17 00:00:00 2001 From: Charles Zinn Date: Sat, 20 Aug 2022 10:12:44 -0400 Subject: [PATCH 3/3] Update README.md to mention arrays of integers --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0452b95..6fde986 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,7 @@ a `WRONG_TYPE` or `NIL_REPLY` status. * `>`: Arrays of Simple Strings or Bulk Strings (in received order) * `>`: Arrays of Simple Strings or Bulk Strings (in sorted order) * `>`: Arrays of Simple Strings or Bulk Strings (in no order) + * `>`: Arrays of integers (in received order) ## Installation Instructions provided are for Ubuntu, but all components are platform-independent.