zncleon commented on code in PR #1710:
URL: https://github.com/apache/kvrocks/pull/1710#discussion_r1311152338


##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -104,14 +105,86 @@ class CommandBFExists : public Commander {
     redis::BloomChain bloom_db(svr->storage, conn->GetNamespace());
     int ret = 0;
     auto s = bloom_db.Exist(args_[1], args_[2], &ret);
+    if (s.IsNotFound()) return {Status::RedisExecErr, "key is not found"};
     if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
 
     *output = redis::Integer(ret);
     return Status::OK();
   }
 };
 
+class CommandBFInfo : public Commander {
+ public:
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 2);
+    while (parser.Good()) {
+      if (parser.EatEqICase("capacity")) {
+        type_ = BloomInfoType::kCapacity;
+      } else if (parser.EatEqICase("size")) {
+        type_ = BloomInfoType::kSize;
+      } else if (parser.EatEqICase("filters")) {
+        type_ = BloomInfoType::kFilters;
+      } else if (parser.EatEqICase("items")) {
+        type_ = BloomInfoType::kItems;
+      } else if (parser.EatEqICase("expansion")) {
+        type_ = BloomInfoType::kExpansion;
+      } else {
+        return {Status::RedisParseErr, "Invalid info argument"};
+      }
+    }
+
+    return Commander::Parse(args);
+  }
+
+  Status Execute(Server *svr, Connection *conn, std::string *output) override {
+    redis::BloomChain bloom_db(svr->storage, conn->GetNamespace());
+    BloomFilterInfo info;
+    auto s = bloom_db.Info(args_[1], &info);
+    if (s.IsNotFound()) return {Status::RedisExecErr, "key is not found"};
+    if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
+
+    switch (type_) {
+      case BloomInfoType::kAll:
+        *output = redis::MultiLen(2 * 5);
+        *output += redis::SimpleString("Capacity");
+        *output += redis::Integer(info.capacity);
+        *output += redis::SimpleString("Size");
+        *output += redis::Integer(info.bloom_bytes);
+        *output += redis::SimpleString("Number of filters");
+        *output += redis::Integer(info.n_filters);
+        *output += redis::SimpleString("Number of items inserted");
+        *output += redis::Integer(info.size);
+        *output += redis::SimpleString("Expansion rate");
+        *output += redis::Integer(info.expansion);
+        break;
+      case BloomInfoType::kCapacity:
+        *output = redis::Integer(info.capacity);
+        break;
+      case BloomInfoType::kSize:
+        *output = redis::Integer(info.bloom_bytes);
+        break;
+      case BloomInfoType::kFilters:
+        *output = redis::Integer(info.n_filters);
+        break;
+      case BloomInfoType::kItems:
+        *output = redis::Integer(info.size);
+        break;
+      case BloomInfoType::kExpansion:
+        *output = redis::Integer(info.expansion);
+        break;
+      default:
+        LOG(ERROR) << "Failed to parse the type of BF.INFO command";

Review Comment:
    If I add a return here, lint would be error: "Unreachable 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to