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


##########
src/commands/cmd_server.cc:
##########
@@ -1265,6 +1265,64 @@ class CommandDump : public Commander {
   }
 };
 
+class CommandPollUpdates : public Commander {
+ public:
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+    sequence_ = GET_OR_RET(parser.TakeInt<uint64_t>());
+
+    while (parser.Good()) {
+      if (parser.EatEqICase("MAX")) {
+        max_ = GET_OR_RET(parser.TakeInt<int64_t>(NumericRange<int64_t>{1, 
1000}));
+      } else if (parser.EatEqICase("STRICT")) {
+        is_strict_ = true;
+      } else if (parser.EatEqICase("FORMAT")) {
+        auto format = GET_OR_RET(parser.TakeStr());
+        if (util::EqualICase(format, "RAW")) {
+          format_ = Format::Raw;
+        } else {
+          return {Status::RedisParseErr, "invalid FORMAT option, only support 
RAW"};
+        }
+      } else {
+        return {Status::RedisParseErr, errInvalidSyntax};
+      }
+    }
+    return Status::OK();
+  }
+
+  Status Execute(Server *srv, Connection *conn, std::string *output) override {
+    // sequence + 1 is for excluding the current sequence to avoid getting 
duplicate updates
+    auto batches = GET_OR_RET(srv->PollUpdates(sequence_ + 1, max_, 
is_strict_));
+
+    *output = redis::MultiLen(8);
+    *output += redis::BulkString("latest_sequence");
+    *output += redis::Integer(srv->storage->LatestSeqNumber());
+    *output += redis::BulkString("format");
+    *output += redis::BulkString("RAW");
+    *output += redis::BulkString("updates");
+    *output += redis::MultiLen(batches.size());
+    uint64_t next_sequence = sequence_;
+    for (const auto &batch : batches) {
+      *output += 
redis::BulkString(util::StringToHex(batch.writeBatchPtr->Data()));
+      // It might contain more than one sequence in a batch
+      next_sequence = batch.sequence + batch.writeBatchPtr->Count() - 1;
+    }
+    *output += redis::BulkString("next_sequence");
+    *output += redis::Integer(next_sequence);

Review Comment:
   yeah



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