PokIsemaine commented on code in PR #2262:
URL: https://github.com/apache/kvrocks/pull/2262#discussion_r1577314019
##########
src/commands/cmd_key.cc:
##########
@@ -424,6 +424,111 @@ class CommandCopy : public Commander {
bool replace_ = false;
};
+template <bool ReadOnly>
+class CommandSort : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ while (parser.Good()) {
+ if (parser.EatEqICase("BY")) {
+ if (parser.Remains() < 1) {
+ return parser.InvalidSyntax();
+ }
+ sort_argument_.sortby = GET_OR_RET(parser.TakeStr());
+
+ if (sort_argument_.sortby.find('*') == std::string::npos) {
+ sort_argument_.dontsort = true;
+ } else {
+ /* TODO:
+ * If BY is specified with a real pattern, we can't accept it in
cluster mode,
+ * unless we can make sure the keys formed by the pattern are in the
same slot
+ * as the key to sort.
+ * If BY is specified with a real pattern, we can't accept
+ * it if no full ACL key access is applied for this command. */
+ }
+ } else if (parser.EatEqICase("LIMIT")) {
+ if (parser.Remains() < 2) {
+ return parser.InvalidSyntax();
+ }
+ sort_argument_.offset = GET_OR_RET(parser.template TakeInt<int>());
+ sort_argument_.count = GET_OR_RET(parser.template TakeInt<int>());
+ } else if (parser.EatEqICase("GET") && parser.Remains() >= 1) {
+ if (parser.Remains() < 1) {
+ return parser.InvalidSyntax();
+ }
+ /* TODO:
+ * If GET is specified with a real pattern, we can't accept it in
cluster mode,
+ * unless we can make sure the keys formed by the pattern are in the
same slot
+ * as the key to sort. */
+ sort_argument_.getpatterns.push_back(GET_OR_RET(parser.TakeStr()));
+ } else if (parser.EatEqICase("ASC")) {
+ sort_argument_.desc = false;
+ } else if (parser.EatEqICase("DESC")) {
+ sort_argument_.desc = true;
+ } else if (parser.EatEqICase("ALPHA")) {
+ sort_argument_.alpha = true;
+ } else if (parser.EatEqICase("STORE")) {
+ if constexpr (ReadOnly) {
+ return parser.InvalidSyntax();
+ }
+ if (parser.Remains() < 1) {
+ return parser.InvalidSyntax();
+ }
+ sort_argument_.storekey = GET_OR_RET(parser.TakeStr());
+ } else {
+ return parser.InvalidSyntax();
+ }
+ }
+
+ return Status::OK();
+ }
+
+ Status Execute(Server *srv, Connection *conn, std::string *output) override {
+ redis::Database redis(srv->storage, conn->GetNamespace());
+ RedisType type = kRedisNone;
+ auto s = redis.Type(args_[1], &type);
+ if (s.ok()) {
+ if (type >= RedisTypeNames.size()) {
+ return {Status::RedisExecErr, "Invalid type"};
+ } else if (type != RedisType::kRedisList && type != RedisType::kRedisSet
&& type != RedisType::kRedisZSet) {
Review Comment:
Yes, do you think there is anything that needs to be improved?
--
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]