This is an automated email from the ASF dual-hosted git repository.

tison pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 36bab87c Fix parse BITCOUNT (#1979)
36bab87c is described below

commit 36bab87c5e529ed2ae57f9977f015932a302ffe7
Author: tison <[email protected]>
AuthorDate: Wed Jan 3 12:31:13 2024 +0800

    Fix parse BITCOUNT (#1979)
    
    Signed-off-by: tison <[email protected]>
---
 src/commands/cmd_bit.cc        | 16 +++++++++++++++-
 src/commands/commander.h       |  3 ++-
 src/commands/error_constants.h |  1 +
 src/types/redis_bitmap.cc      |  1 -
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/commands/cmd_bit.cc b/src/commands/cmd_bit.cc
index c1d72462..88341c84 100644
--- a/src/commands/cmd_bit.cc
+++ b/src/commands/cmd_bit.cc
@@ -91,6 +91,7 @@ class CommandSetBit : public Commander {
   bool bit_ = false;
 };
 
+// BITCOUNT key [start end [BYTE | BIT]]
 class CommandBitCount : public Commander {
  public:
   Status Parse(const std::vector<std::string> &args) override {
@@ -98,7 +99,11 @@ class CommandBitCount : public Commander {
       return {Status::RedisParseErr, errInvalidSyntax};
     }
 
-    if (args.size() == 4) {
+    if (args.size() > 5) {
+      return {Status::RedisParseErr, errInvalidSyntax};
+    }
+
+    if (args.size() >= 4) {
       auto parse_start = ParseInt<int64_t>(args[2], 10);
       if (!parse_start) {
         return {Status::RedisParseErr, errValueNotInteger};
@@ -113,6 +118,15 @@ class CommandBitCount : public Commander {
       stop_ = *parse_stop;
     }
 
+    if (args.size() == 5) {
+      if (util::EqualICase(args[4], "BYTE")) {
+      } else if (util::EqualICase(args[4], "BIT")) {
+        return {Status::RedisExecErr, errNotImplemented};
+      } else {
+        return {Status::RedisParseErr, errInvalidSyntax};
+      }
+    }
+
     return Commander::Parse(args);
   }
 
diff --git a/src/commands/commander.h b/src/commands/commander.h
index 1cb4d221..3330337c 100644
--- a/src/commands/commander.h
+++ b/src/commands/commander.h
@@ -38,6 +38,7 @@
 #include <vector>
 
 #include "cluster/cluster_defs.h"
+#include "error_constants.h"
 #include "parse_util.h"
 #include "server/redis_reply.h"
 #include "status.h"
@@ -73,7 +74,7 @@ class Commander {
   virtual Status Parse() { return Parse(args_); }
   virtual Status Parse(const std::vector<std::string> &args) { return 
Status::OK(); }
   virtual Status Execute(Server *srv, Connection *conn, std::string *output) {
-    return {Status::RedisExecErr, "not implemented"};
+    return {Status::RedisExecErr, errNotImplemented};
   }
 
   virtual ~Commander() = default;
diff --git a/src/commands/error_constants.h b/src/commands/error_constants.h
index df650fab..43c7440d 100644
--- a/src/commands/error_constants.h
+++ b/src/commands/error_constants.h
@@ -22,6 +22,7 @@
 
 namespace redis {
 
+inline constexpr const char *errNotImplemented = "not implemented";
 inline constexpr const char *errInvalidSyntax = "syntax error";
 inline constexpr const char *errInvalidExpireTime = "invalid expire time";
 inline constexpr const char *errWrongNumOfArguments = "wrong number of 
arguments";
diff --git a/src/types/redis_bitmap.cc b/src/types/redis_bitmap.cc
index 37fcc0e3..31cd55ba 100644
--- a/src/types/redis_bitmap.cc
+++ b/src/types/redis_bitmap.cc
@@ -22,7 +22,6 @@
 
 #include <algorithm>
 #include <memory>
-#include <utility>
 #include <vector>
 
 #include "db_util.h"

Reply via email to