Yangsx-1 commented on code in PR #1704:
URL: https://github.com/apache/kvrocks/pull/1704#discussion_r1310455430
##########
src/commands/cmd_stream.cc:
##########
@@ -205,6 +206,88 @@ class CommandXDel : public Commander {
std::vector<redis::StreamEntryID> ids_;
};
+class CommandXGroup : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 1);
+ subcommand_ = util::ToLower(GET_OR_RET(parser.TakeStr()));
+ stream_name_ = GET_OR_RET(parser.TakeStr());
+ group_name_ = GET_OR_RET(parser.TakeStr());
+
+ if (subcommand_ == "create") {
+ if (args.size() < 5 || args.size() > 8) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+
+ xgroup_create_options_.last_id = GET_OR_RET(parser.TakeStr());
+
+ while (parser.Good()) {
+ if (parser.EatEqICase("mkstream")) {
+ xgroup_create_options_.mkstream = true;
+ } else if (parser.EatEqICase("entriesread")) {
+ auto parse_result = parser.TakeInt<int64_t>();
+ if (!parse_result.IsOK()) {
+ return {Status::RedisParseErr, errValueNotInteger};
+ }
+ if (parse_result.GetValue() < 0 && parse_result.GetValue() != -1) {
+ return {Status::RedisParseErr, "value for ENTRIESREAD must be
positive or -1"};
+ }
+ xgroup_create_options_.entries_read = parse_result.GetValue();
+ } else {
+ return parser.InvalidSyntax();
+ }
+ }
+
+ return Status::OK();
+ }
+
+ if (subcommand_ == "destroy") {
+ if (args.size() != 4) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+
+ return Status::OK();
+ }
+
+ return {Status::RedisParseErr, "unknown subcommand"};
+ }
+
+ Status Execute(Server *svr, Connection *conn, std::string *output) override {
+ redis::Stream stream_db(svr->storage, conn->GetNamespace());
+
+ if (subcommand_ == "create") {
+ auto s = stream_db.CreateGroup(stream_name_, xgroup_create_options_,
group_name_);
+ if (!s.ok()) {
+ return {Status::RedisExecErr, s.ToString()};
+ }
+
+ *output = redis::SimpleString("OK");
+ }
+
+ if (subcommand_ == "destroy") {
+ uint64_t delete_cnt = 0;
+ auto s = stream_db.DestroyGroup(stream_name_, group_name_, &delete_cnt);
+ if (!s.ok()) {
+ return {Status::RedisExecErr, s.ToString()};
+ }
+
+ if (delete_cnt > 0) {
Review Comment:
It can only be 0 or 1.
--
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]