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

[GitHub] [kvrocks] HolyLow opened a new pull request, #1737: Add the support of LMPOP command (#1526)

HolyLow opened a new pull request, #1737:
URL: https://github.com/apache/kvrocks/pull/1737

   This PR adds support for LMPOP command.
   Currently the test cases are not added yet, but will soon. This PR serves as an implementation preview.
   Any suggestions are welcomed.


-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316636595


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]

Review Comment:
   we did not use `///` in our codebase
   ```suggestion
     // format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
   ```



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316643724


##########
tests/gocase/unit/type/list/list_test.go:
##########
@@ -1000,4 +1000,100 @@ func TestList(t *testing.T) {
 			require.Empty(t, rdb.LPosCount(ctx, "mylist", "b", 10, redis.LPosArgs{Rank: 5}).Val())
 		})
 	}
+

Review Comment:
   you can do this (just issue the command with the plain Do):
   ```go
   require.NoError(t, rdb.Do(ctx, "LMPOP", "1", "mykey", "left").Err())
   ```



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315718769


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), elems_bulk});
+    }
+
+    return Status::OK();
+  }
+
+  static const inline CommandKeyRangeGen keyRangeGen = [](const std::vector<std::string> &args) {
+    CommandKeyRange range;
+    range.first_key = 2;
+    range.key_step = 1;
+    auto v = ParseInt<int32_t>(args[1], 10);

Review Comment:
   There are two reasons I didn't do the checking here. 
   
   Firstly, in the call chain, the command would be parsed before this keyRangeGen is invoked, so if the range is invalid then the parsing phase would report error. 
   
   Secondly (and most importantly...), I am not aware how to handle the exception/error if there is something wrong here. The error handling style of this project is mostly via the returned error code, and the rangeGen interface has no such error return value. I am not sure what to do if there is an error here. Should I throw some exception? 



-- 
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


[GitHub] [kvrocks] mapleFU commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316646812


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   I guess we don't need `while` because if that we need to check the count of args later?



-- 
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


[GitHub] [kvrocks] git-hulk commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315313583


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   Thank you! Redis should not care about the order in most commands if my memory works. cc @PragmaTwice 



-- 
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


[GitHub] [kvrocks] git-hulk commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316611104


##########
tests/gocase/unit/type/list/list_test.go:
##########
@@ -1000,4 +1000,100 @@ func TestList(t *testing.T) {
 			require.Empty(t, rdb.LPosCount(ctx, "mylist", "b", 10, redis.LPosArgs{Rank: 5}).Val())
 		})
 	}
+

Review Comment:
   @HolyLow Can use the go-redis client's Do function which can pass the command arguments instead of encapsulating one.



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316638906


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), std::move(elems_bulk)});
+    }
+
+    return Status::OK();
+  }
+
+  static const inline CommandKeyRangeGen keyRangeGen = [](const std::vector<std::string> &args) {
+    CommandKeyRange range;
+    range.first_key = 2;
+    range.key_step = 1;
+    auto v = ParseInt<int32_t>(args[1], 10);

Review Comment:
   Is there any special reason for writing this? i see all the range in our codebase is using this format
   ```suggestion
       int num_key = *ParseInt<int>(args[1], 10);
   ```



-- 
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


[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315313564


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   IMHO here we do not need a `while` loop.
   
   ```c++
   CommandParser parser(args, 1);
   
   auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
   for (uint32_t i = 0; i < num_keys; ++i) keys_.emplace(GET_OR_RET(parser.TakeStr())); // or you can choose to not have a key vector.
   
   auto left_or_right = GET_OR_RET(parser.TakeStr());
   // do something about left_or_right 
   
   if (parser.Good()) {
     if (parser.EatEqICase("count")) count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
     else return parser.InvalidSyntax();
   }
   
   if (parser.Good()) return parser.InvalidSyntax();
   ```
   
   To your questions:
   
   > as the CommandParser has no order semantic by design.
   
   Nope. Whether there is an order is **entirely up to you**, not the CommandParser.
   
   Your code contains **so many magic index numbers**, which makes it very hard to maintain and scale.



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316699037


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   Redis's optional args for old commands are indeed, some can be repeated. But actually that is not very important, or the Redis community is not willing to spend energy to modify it, it will cost time and introduce the changes or break the git blame log
   
   For the new commands, like LMPOP, it was introduced in Redis 7.0, or in fact, i am the one who introduced it. normally, a new `is_count_parsed` is indeed ugly. In redis, the count will be init to -1, and use something like `if (count == -1 && parser.EatEqICase("count"))` format to handle the repeat issue, and in the last, do a `if (count == -1) count = 1;` before the execute



-- 
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


[GitHub] [kvrocks] torwig commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "torwig (via GitHub)" <gi...@apache.org>.
torwig commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315783322


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else

Review Comment:
   I'd use curly braces with the `else` part of the statement. 



##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();

Review Comment:
   Is this call redundant?



##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();

Review Comment:
   What does it mean to check `parser.Good()` 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


[GitHub] [kvrocks] mapleFU commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315789818


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();

Review Comment:
   I guess it means to check "no argument left"



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316677161


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   i did see the disscussion below
   
   > LMPOP's keywords MUST have strict order
   
   what do you mean that Redis's LMPOP must have the strict order? The COUNT is an optional arg, it dose not require the order. what happen if Redis's LMPOP have more optional args in the future?



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316593936


##########
tests/gocase/unit/type/list/list_test.go:
##########
@@ -1000,4 +1000,100 @@ func TestList(t *testing.T) {
 			require.Empty(t, rdb.LPosCount(ctx, "mylist", "b", 10, redis.LPosArgs{Rank: 5}).Val())
 		})
 	}
+

Review Comment:
   Sure, I am not familiar with go-redis, so have no idea how to strip the 'count' argument. But now it occurs that I could simply copy-and-modify the go-redis's LMPOP function... Will do it, thank you.



-- 
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


[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315313564


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   IMHO here we do not need a `while` loop.
   
   ```c++
   CommandParser parser(args, 1);
   
   auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
   for (uint32_t i = 0; i < num_keys; ++i) keys_.emplace(GET_OR_RET(parser.TakeStr()));
   
   auto left_or_right = GET_OR_RET(parser.TakeStr());
   // do something about left_or_right 
   
   if (parser.Good()) {
     if (parser.EatEqICase("count")) count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
     else return parser.InvalidSyntax();
   }
   
   if (parser.Good()) return parser.InvalidSyntax();
   ```
   
   To your questions:
   
   > as the CommandParser has no order semantic by design.
   
   Nope. Whether there is an order is entirely up to you, not the CommandParser.
   
   Your code contains so many magic index numbers, which makes it very hard to maintain and extend.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315300509


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   @git-hulk I have some questions on the usage of CommandParser.
   The common usage of CommandParser is like:
   `
   while (cmdParser.isGood()) {
   
     if (eatCase0()) { doSomething(); }
   
     else if (eatCase1()) { doSomething(); }
   
     else { return ParseError(kInvalidSyntax); }
   
   }
   `
   But this schema assumes no strict order constraint and no strict repeat constraint. For example, the standard LMPOP command is like: 
   
   *LMPOP 2 key1 key2 LEFT COUNT 2*; 
   
   but with the parsing schema above, this command is also considered as valid: 
   
   *LMPOP 2 key1 key2 LEFT RIGHT COUNT 2 COUNT 4 RIGHT*. 
   
   The repeat and the order of keywords are not constrained by the isGood() loop.  Even though we could constrain the repeat by checking args.size(), the order of keywords is not constrained.
   
   So should I constrain the order of the keywords, or leave it loose? If the orders of the keywords SHOULD be constrained, the existing parsers using CommandParser might have parsing bugs, as the CommandParser has no order semantic by design.



##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   @git-hulk I have some questions on the usage of CommandParser.
   The common usage of CommandParser is like:
   ```
   while (cmdParser.isGood()) {
   
     if (eatCase0()) { doSomething(); }
   
     else if (eatCase1()) { doSomething(); }
   
     else { return ParseError(kInvalidSyntax); }
   
   }
   ```
   But this schema assumes no strict order constraint and no strict repeat constraint. For example, the standard LMPOP command is like: 
   
   *LMPOP 2 key1 key2 LEFT COUNT 2*; 
   
   but with the parsing schema above, this command is also considered as valid: 
   
   *LMPOP 2 key1 key2 LEFT RIGHT COUNT 2 COUNT 4 RIGHT*. 
   
   The repeat and the order of keywords are not constrained by the isGood() loop.  Even though we could constrain the repeat by checking args.size(), the order of keywords is not constrained.
   
   So should I constrain the order of the keywords, or leave it loose? If the orders of the keywords SHOULD be constrained, the existing parsers using CommandParser might have parsing bugs, as the CommandParser has no order semantic by design.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316665285


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), std::move(elems_bulk)});
+    }
+
+    return Status::OK();
+  }
+
+  static const inline CommandKeyRangeGen keyRangeGen = [](const std::vector<std::string> &args) {
+    CommandKeyRange range;
+    range.first_key = 2;
+    range.key_step = 1;
+    auto v = ParseInt<int32_t>(args[1], 10);

Review Comment:
   I think this is just trying to remind the programmer and reviewer that this parsing might fail, thus we should always be careful about it.



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316638906


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), std::move(elems_bulk)});
+    }
+
+    return Status::OK();
+  }
+
+  static const inline CommandKeyRangeGen keyRangeGen = [](const std::vector<std::string> &args) {
+    CommandKeyRange range;
+    range.first_key = 2;
+    range.key_step = 1;
+    auto v = ParseInt<int32_t>(args[1], 10);

Review Comment:
   Is there any special reason for writing this? i see all the range in our codebase is using this format.
   
   Please consider consistent with the original code style, or at least, use a meaningful name instead of v
   ```suggestion
       int num_key = *ParseInt<int>(args[1], 10);
   ```



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316661250


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else

Review Comment:
   Done.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316664204


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   Please refer to the discussion of bulk, pragmaTwice and me above. 
   
   The while loop has no order semantic, and cannot guarantee the orders of keywords. However, as aligned to redis behavior, the LMPOP's keywords MUST have strict order. So I choose to not to adopt the CommandParser's while() loop schema.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316693421


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   I could see your point, but the while loop here would bring another problem: what if the COUNT keyword is repeated?
   For redis, the command "LMPOP 1 mylist RIGHT COUNT 1 COUNT 2" is considered invalid. If we use while loop to parse the COUNT keyword here, the repeated COUNT keywords would be accepted.
   Sure we could use another flag like "is_count_parsed" to check if we have seen the COUNT before. But for what? These additional checking already brought more complexity than the "return isGood() ? caseA : caseB"!
   I do try to modify the code as you suggest, but it really looks even uglier to me. If more optional keywords are added, then the parsing could be modified, but the repeat problem still exists.
   I've tested other commands such as "LPOS", and their optional keywords could be repeated with only the last one works. But for LMPOP, the COUNT keyword could not be repeated. I don't know if this is a redis bug or redis feature.



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316678936


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   the keys and the left_or_right dose require the order (and you already handle it), but the rest of the args are the optional, although now it only have one COUNT arg



-- 
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


[GitHub] [kvrocks] git-hulk commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315732973


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), elems_bulk});
+    }
+
+    return Status::OK();
+  }
+
+  static const inline CommandKeyRangeGen keyRangeGen = [](const std::vector<std::string> &args) {
+    CommandKeyRange range;
+    range.first_key = 2;
+    range.key_step = 1;
+    auto v = ParseInt<int32_t>(args[1], 10);

Review Comment:
   ok, it makes sense, thank you.



-- 
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


[GitHub] [kvrocks] PragmaTwice merged pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice merged PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737


-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316597169


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else

Review Comment:
   Well, this code is refactored by the naughty clang-format with "./x.py format". I personally don't like this no-brace style as well. Will try to add it back, but if the clang-format still says no, I have to follow its instruction to pass the format checking.



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316633631


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   i prefer using the while loop (though we now only have one arg), so that we can remove the parser.Good() in `return parser.Good() ? parser.InvalidSyntax() : Status::OK();`
   ```suggestion
       while (parser.Good()) {
   ```



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315300509


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   @git-hulk I have some questions on the usage of CommandParser.
   The common usage of CommandParser is like:
   `
   while (cmdParser.isGood()) {
     if (eatCase0()) { doSomething(); }
     else if (eatCase1()) { doSomething(); }
     else { return ParseError(kInvalidSyntax); }
   }
   `
   But this schema assumes no strict order constraint and no strict repeat constraint. For example, the standard LMPOP command is like: 
   
   *LMPOP 2 key1 key2 LEFT COUNT 2*; 
   
   but with the parsing schema above, this command is also considered as valid: 
   
   *LMPOP 2 key1 key2 LEFT RIGHT COUNT 2 COUNT 4 RIGHT*. 
   
   The repeat and the order of keywords are not constrained by the isGood() loop.  Even though we could constrain the repeat by checking args.size(), the order of keywords is not constrained.
   
   So should I constrain the order of the keywords, or leave it loose? If the orders of the keywords SHOULD be constrained, the existing parsers using CommandParser might have parsing bugs, as the CommandParser has no order semantic by design.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315342197


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   @PragmaTwice you are right about the order issue, it's the user's responsibility to charge for the order rather than CommandParser. Besides, the GET_OR_RET macro makes the err handling much easier.
   
   @git-hulk I've refactored the code and tested the redis behavior. Seems for most commands (e.g. LPOS) the ordering of different keywords doesn't matter, but for LMPOP, the ordering must be fixed, otherwise redis reports "syntax error". So our discussion here is not for nothing.



-- 
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


[GitHub] [kvrocks] git-hulk commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315709711


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), elems_bulk});
+    }
+
+    return Status::OK();
+  }
+
+  static const inline CommandKeyRangeGen keyRangeGen = [](const std::vector<std::string> &args) {
+    CommandKeyRange range;
+    range.first_key = 2;
+    range.key_step = 1;
+    auto v = ParseInt<int32_t>(args[1], 10);

Review Comment:
   Guess we should check the range of `v` 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


[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315749939


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), elems_bulk});
+    }
+
+    return Status::OK();
+  }
+
+  static const inline CommandKeyRangeGen keyRangeGen = [](const std::vector<std::string> &args) {
+    CommandKeyRange range;
+    range.first_key = 2;
+    range.key_step = 1;
+    auto v = ParseInt<int32_t>(args[1], 10);

Review Comment:
   Yeah, the parsing will be invoked before this method, so technically the ParseInt will always succeed.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316661141


##########
tests/gocase/unit/type/list/list_test.go:
##########
@@ -1000,4 +1000,100 @@ func TestList(t *testing.T) {
 			require.Empty(t, rdb.LPosCount(ctx, "mylist", "b", 10, redis.LPosArgs{Rank: 5}).Val())
 		})
 	}
+

Review Comment:
   The LMPOP test cases with no COUNT keyword are added now.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316674903


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), std::move(elems_bulk)});
+    }
+
+    return Status::OK();
+  }
+
+  static const inline CommandKeyRangeGen keyRangeGen = [](const std::vector<std::string> &args) {
+    CommandKeyRange range;
+    range.first_key = 2;
+    range.key_step = 1;
+    auto v = ParseInt<int32_t>(args[1], 10);

Review Comment:
   Modified as requested.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315308804


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   Sure, we could find out some way to handle the order/repeat issue, but I just think that these workarounds lose the elegancy brought by CommandParser. Maybe the better way is to refactor CommandParser to support order/repeat checking semantic (which is painful...). Well this might be another issue.
   
   I would refactor the parsing with the CommandParser and check if redis cares about keyword repeat/order.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316596053


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();

Review Comment:
   This call is some kind of "defensive programming". If the Parse() function is called more than once, the keys_ vector would has too many args (accumulates a batch each time called). 
   Besides, the following Execute() relies on keys_.size(), so we don't want the keys_ vector to be polluted. 
   Lastly, this calling has almost no overhead. 
   So I tend to leave it there.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315300509


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   @git-hulk I have some questions on the usage of CommandParser.
   The common usage of CommandParser is like:
   ```
   while (cmdParser.isGood()) {
     if (eatCase0()) { doSomething(); }
     else if (eatCase1()) { doSomething(); }
     else { return ParseError(kInvalidSyntax); }
   }
   ```
   But this schema assumes no strict order constraint and no strict repeat constraint. For example, the standard LMPOP command is like: 
   
   *LMPOP 2 key1 key2 LEFT COUNT 2*; 
   
   but with the parsing schema above, this command is also considered as valid: 
   
   *LMPOP 2 key1 key2 LEFT RIGHT COUNT 2 COUNT 4 RIGHT*. 
   
   The repeat and the order of keywords are not constrained by the isGood() loop.  Even though we could constrain the repeat by checking args.size(), the order of keywords is not constrained.
   
   So should I constrain the order of the keywords, or leave it loose? If the orders of the keywords SHOULD be constrained, the existing parsers using CommandParser might have parsing bugs, as the CommandParser has no order semantic by design.



-- 
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


[GitHub] [kvrocks] git-hulk commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315304041


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   We can align the behavior with Redis, I'm not sure if Redis allows the duplicate keyword like you mentioned.
   
   > The repeat and the order of keywords are not constrained by the isGood() loop.
   
   We can work around this by checking if the variable has already been set. For example:
   
   ```
   direction = DirectionNone
   while (cmdParser.isGood()) {
     if (eatCase0()) { doSomething(); }
     else if (eatCase1("LEFT")) {
        if (direction != DirectionNone) {
           // throw error
        }
        direction = DirectionLeft
     } else { return ParseError(kInvalidSyntax); }
   }
   ``` 



##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   We can align the behavior with Redis, I'm not sure if Redis allows the duplicate keyword like you mentioned.
   
   > The repeat and the order of keywords are not constrained by the isGood() loop.
   
   We can work around this by checking if the variable has already been set. For example:
   
   ```c
   direction = DirectionNone
   while (cmdParser.isGood()) {
     if (eatCase0()) { doSomething(); }
     else if (eatCase1("LEFT")) {
        if (direction != DirectionNone) {
           // throw error
        }
        direction = DirectionLeft
     } else { return ParseError(kInvalidSyntax); }
   }
   ``` 



-- 
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


[GitHub] [kvrocks] git-hulk commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315056969


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   @HolyLow Can use the CommandParser to parse arguments.



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316670152


##########
tests/gocase/unit/type/list/list_test.go:
##########
@@ -1000,4 +1000,100 @@ func TestList(t *testing.T) {
 			require.Empty(t, rdb.LPosCount(ctx, "mylist", "b", 10, redis.LPosArgs{Rank: 5}).Val())
 		})
 	}
+
+	for _, direction := range []string{"LEFT", "RIGHT"} {
+		key1 := "lmpop-list1"
+		key2 := "lmpop-list2"
+		rdb.Del(ctx, key1, key2)
+		require.EqualValues(t, 5, rdb.LPush(ctx, key1, "one", "two", "three", "four", "five").Val())
+		require.EqualValues(t, 5, rdb.LPush(ctx, key2, "ONE", "TWO", "THREE", "FOUR", "FIVE").Val())
+		t.Run(fmt.Sprintf("LMPOP-test-oneKey-countSingle-%s", direction), func(t *testing.T) {
+			result := rdb.LMPop(ctx, direction, 1, key1)
+			resultKey, resultVal := result.Val()
+			require.NoError(t, result.Err())
+			require.EqualValues(t, key1, resultKey)
+			if direction == "LEFT" {
+				require.Equal(t, []string{"five"}, resultVal)
+			} else {
+				require.Equal(t, []string{"one"}, resultVal)
+			}
+		})
+		t.Run(fmt.Sprintf("LMPOP-test-oneKey-countMulti-%s", direction), func(t *testing.T) {

Review Comment:
   Refactored to meet your suggestions.



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316699037


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   Redis's optional args for old commands are indeed, some can be repeated. But actually that is not very important, or the Redis community is not willing to spend energy to modify it, it will cost time and introduce the changes or break the git blame log
   
   For the new commands, like LMPOP, it was introduce in Redis 7.0, or in fact, i am the one introduced it. normally, a new `is_count_parsed` is indeed ugly. In redis, the count will be init   to -1, and use something like `if (count == -1 && parser.EatEqICase("count"))` format to handle the repeat issue, and in the last, do a `if (count == -1) count = 1;` before the execute



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316755771


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   Refactored as suggested.



-- 
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


[GitHub] [kvrocks] PragmaTwice commented on pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#issuecomment-1708512839

   Thanks for your contribution!


-- 
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


[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315313564


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   IMHO here we do not need a `while` loop.
   
   ```c++
   CommandParser parser(args, 1);
   
   auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
   for (uint32_t i = 0; i < num_keys; ++i) keys_.emplace(GET_OR_RET(parser.TakeStr())); // or you can choose to not have a key vector.
   
   auto left_or_right = GET_OR_RET(parser.TakeStr());
   // do something about left_or_right 
   
   if (parser.Good()) {
     if (parser.EatEqICase("count")) count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
     else return parser.InvalidSyntax();
   }
   
   if (parser.Good()) return parser.InvalidSyntax();
   ```
   
   To your questions:
   
   > as the CommandParser has no order semantic by design.
   
   Nope. Whether there is an order is entirely up to you, not the CommandParser.
   
   Your code contains so many magic index numbers, which makes it very hard to maintain and extend.



-- 
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


[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315313564


##########
src/commands/cmd_list.cc:
##########
@@ -167,11 +167,11 @@ class CommandLMPop : public Commander {
     }
     num_keys_ = *v;
 
-    if ((args.size() != 3 + num_keys_) && (args.size() != 5 + num_keys_)) {
+    if ((args.size() != num_keys_ + 3) && (args.size() != num_keys_ + 5)) {
       return {Status::RedisParseErr, errWrongNumOfArguments};
     }
 
-    std::string left_or_right = util::ToLower(args[1 + num_keys_]);
+    std::string left_or_right = util::ToLower(args[num_keys_ + 2]);

Review Comment:
   IMHO here we do not need a `while` loop.
   
   ```c++
   CommandParser parser(args, 1);
   
   auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
   for (uint32_t i = 0; i < num_keys; ++i) keys_.emplace(GET_OR_RET(parser.TakeStr())); // or you can choose to not have a key vector.
   
   auto left_or_right = GET_OR_RET(parser.TakeStr());
   // do something about left_or_right 
   
   if (parser.Good()) {
     if (parser.EatEqICase("count")) count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
     else return parser.InvalidSyntax();
   }
   
   if (parser.Good()) return parser.InvalidSyntax();
   ```
   
   To your questions:
   
   > as the CommandParser has no order semantic by design.
   
   Nope. Whether there is an order is **entirely up to you**, not the CommandParser.
   
   Your code contains **so many magic index numbers**, which makes it very hard to maintain and extend.



-- 
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


[GitHub] [kvrocks] PragmaTwice commented on pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#issuecomment-1704543069

   Thanks for your contribution!
   
   Please refer to https://kvrocks.apache.org/community/contributing/ to format, lint and test your code : )


-- 
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


[GitHub] [kvrocks] mapleFU commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315764398


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::List list_db(svr->storage, conn->GetNamespace());
+
+    std::vector<std::string> elems;
+    std::string chosen_key;
+    for (auto &key : keys_) {
+      auto s = list_db.PopMulti(key, left_, count_, &elems);
+      if (!s.ok() && !s.IsNotFound()) {
+        return {Status::RedisExecErr, s.ToString()};
+      }
+      if (!elems.empty()) {
+        chosen_key = key;
+        break;
+      }
+    }
+
+    if (elems.empty()) {
+      *output = redis::NilString();
+    } else {
+      std::string elems_bulk = redis::MultiBulkString(elems);
+      *output = redis::Array({redis::BulkString(chosen_key), elems_bulk});

Review Comment:
   ```suggestion
         *output = redis::Array({redis::BulkString(chosen_key), std::move(elems_bulk)});
   ```



##########
tests/gocase/unit/type/list/list_test.go:
##########
@@ -1000,4 +1000,100 @@ func TestList(t *testing.T) {
 			require.Empty(t, rdb.LPosCount(ctx, "mylist", "b", 10, redis.LPosArgs{Rank: 5}).Val())
 		})
 	}
+

Review Comment:
   ```go
   // LMPop Pops one or more elements from the first non-empty list key from the list of provided key names.
   // direction: left or right, count: > 0
   // example: client.LMPop(ctx, "left", 3, "key1", "key2")
   func (c cmdable) LMPop(ctx context.Context, direction string, count int64, keys ...string) *KeyValuesCmd {
   	args := make([]interface{}, 2+len(keys), 5+len(keys))
   	args[0] = "lmpop"
   	args[1] = len(keys)
   	for i, key := range keys {
   		args[2+i] = key
   	}
   	args = append(args, strings.ToLower(direction), "count", count)
   	cmd := NewKeyValuesCmd(ctx, args...)
   	_ = c(ctx, cmd)
   	return cmd
   }
   ```
   
   Seems `go-redis` `LMPOP` will force a `COUNT` argument? should we try to test without `COUNT`?



-- 
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


[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1315872587


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {
+      if (parser.EatEqICase("count")) {
+        count_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+      } else
+        return parser.InvalidSyntax();
+    }
+
+    return parser.Good() ? parser.InvalidSyntax() : Status::OK();

Review Comment:
   > I guess it means to check "no argument left"
   
   Exactly.



-- 
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


[GitHub] [kvrocks] enjoy-binbin commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "enjoy-binbin (via GitHub)" <gi...@apache.org>.
enjoy-binbin commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316645345


##########
tests/gocase/unit/type/list/list_test.go:
##########
@@ -1000,4 +1000,100 @@ func TestList(t *testing.T) {
 			require.Empty(t, rdb.LPosCount(ctx, "mylist", "b", 10, redis.LPosArgs{Rank: 5}).Val())
 		})
 	}
+
+	for _, direction := range []string{"LEFT", "RIGHT"} {
+		key1 := "lmpop-list1"
+		key2 := "lmpop-list2"
+		rdb.Del(ctx, key1, key2)
+		require.EqualValues(t, 5, rdb.LPush(ctx, key1, "one", "two", "three", "four", "five").Val())
+		require.EqualValues(t, 5, rdb.LPush(ctx, key2, "ONE", "TWO", "THREE", "FOUR", "FIVE").Val())
+		t.Run(fmt.Sprintf("LMPOP-test-oneKey-countSingle-%s", direction), func(t *testing.T) {
+			result := rdb.LMPop(ctx, direction, 1, key1)
+			resultKey, resultVal := result.Val()
+			require.NoError(t, result.Err())
+			require.EqualValues(t, key1, resultKey)
+			if direction == "LEFT" {
+				require.Equal(t, []string{"five"}, resultVal)
+			} else {
+				require.Equal(t, []string{"one"}, resultVal)
+			}
+		})
+		t.Run(fmt.Sprintf("LMPOP-test-oneKey-countMulti-%s", direction), func(t *testing.T) {

Review Comment:
   please try to remove the `-` in the test name, also, please leave a newline between the each test
   ```suggestion
   
   		t.Run(fmt.Sprintf("LMPOP test-oneKey-countMulti-%s", direction), func(t *testing.T) {
   ```



-- 
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


[GitHub] [kvrocks] HolyLow commented on a diff in pull request #1737: Add the support of LMPOP command

Posted by "HolyLow (via GitHub)" <gi...@apache.org>.
HolyLow commented on code in PR #1737:
URL: https://github.com/apache/kvrocks/pull/1737#discussion_r1316693421


##########
src/commands/cmd_list.cc:
##########
@@ -154,6 +154,79 @@ class CommandRPop : public CommandPop {
   CommandRPop() : CommandPop(false) {}
 };
 
+class CommandLMPop : public Commander {
+ public:
+  /// format: LMPOP #numkeys key0 [key1 ...] <LEFT | RIGHT> [COUNT count]
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+
+    auto num_keys = GET_OR_RET(parser.TakeInt<uint32_t>());
+    keys_.clear();
+    keys_.reserve(num_keys);
+    for (uint32_t i = 0; i < num_keys; ++i) {
+      keys_.emplace_back(GET_OR_RET(parser.TakeStr()));
+    }
+
+    auto left_or_right = util::ToLower(GET_OR_RET(parser.TakeStr()));
+    if (left_or_right == "left") {
+      left_ = true;
+    } else if (left_or_right == "right") {
+      left_ = false;
+    } else {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (parser.Good()) {

Review Comment:
   I could see your point, but the while loop here would bring another problem: what if the COUNT keyword is repeated?
   For redis, the command "LMPOP 1 mylist RIGHT COUNT 1 COUNT 2" is considered invalid. If we use while loop to parse the COUNT keyword here, the repeated COUNT keywords would be accepted.
   Sure we could use another flag like "is_count_parsed" to check if we have seen the COUNT before. But for what? These additional checking already brought more complexity than the "return isGood() ? caseA : caseB"!
   I do try to modify the code as you suggest, but it really looks even more ugly to me. If more optional keywords are added, then the parsing could be modified, but the repeat problem still exists.
   I've tested other commands such as "LPOS", and their optional keywords could be repeated with only the last one works. But for LMPOP, the COUNT keyword could not be repeated. I don't know if this is a redis bug or redis feature.



-- 
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