You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "PragmaTwice (via GitHub)" <gi...@apache.org> on 2023/08/09 03:24:19 UTC

[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1655: Add dynamic flag generator to replace adhoc logic in ExecuteCommands

PragmaTwice commented on code in PR #1655:
URL: https://github.com/apache/kvrocks/pull/1655#discussion_r1287888313


##########
src/commands/commander.cc:
##########
@@ -77,30 +77,55 @@ void GetCommandsInfo(std::string *info, const std::vector<std::string> &cmd_name
   }
 }
 
-Status GetKeysFromCommand(const std::string &cmd_name, int argc, std::vector<int> *keys_indexes) {
-  auto cmd_iter = command_details::original_commands.find(util::ToLower(cmd_name));
-  if (cmd_iter == command_details::original_commands.end()) {
-    return {Status::RedisUnknownCmd, "Invalid command specified"};
+void DumpKeyRange(std::vector<int> &keys_index, int argc, const CommandKeyRange &range) {
+  auto last = range.last_key;
+  if (last < 0) last = argc + last;
+
+  for (int i = range.first_key; i <= last; i += range.key_step) {
+    keys_index.emplace_back(i);
   }
+}
 
-  auto command_attribute = cmd_iter->second;
-  if (command_attribute->key_range.first_key == 0) {
+Status GetKeysFromCommand(const CommandAttributes *attributes, int argc, std::vector<int> *keys_index) {
+  if (attributes->key_range.first_key == 0) {
     return {Status::NotOK, "The command has no key arguments"};
   }
 
-  if (command_attribute->key_range.first_key < 0) {
+  if (attributes->key_range.first_key < 0) {
     return {Status::NotOK, "The command has dynamic positions of key arguments"};
   }
 
-  if ((command_attribute->arity > 0 && command_attribute->arity != argc) || argc < -command_attribute->arity) {
+  if ((attributes->arity > 0 && attributes->arity != argc) || argc < -attributes->arity) {
     return {Status::NotOK, "Invalid number of arguments specified for command"};
   }
 
-  auto last = command_attribute->key_range.last_key;
-  if (last < 0) last = argc + last;
+  DumpKeyRange(*keys_index, argc, attributes->key_range);
+
+  return Status::OK();
+}
+
+Status GetKeysFromCommand(const CommandAttributes *attributes, const std::vector<std::string> &cmd_tokens,

Review Comment:
   there is no cmd_tokens here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org