PokIsemaine commented on code in PR #2262:
URL: https://github.com/apache/kvrocks/pull/2262#discussion_r1590666739


##########
src/storage/redis_db.h:
##########
@@ -21,15 +21,46 @@
 #pragma once
 
 #include <map>
+#include <optional>
 #include <string>
 #include <utility>
+#include <variant>
 #include <vector>
 
 #include "redis_metadata.h"
+#include "server/redis_reply.h"
 #include "storage.h"
 
 namespace redis {
 
+struct SortArgument {
+  std::string sortby;                    // BY
+  bool dontsort = false;                 // DONT SORT
+  int offset = 0;                        // LIMIT OFFSET
+  int count = -1;                        // LIMIT COUNT
+  std::vector<std::string> getpatterns;  // GET
+  bool desc = false;                     // ASC/DESC
+  bool alpha = false;                    // ALPHA
+  std::string storekey;                  // STORE
+};
+
+struct RedisSortObject {
+  std::string obj;
+  std::variant<double, std::string> v;
+
+  /// SortCompare is a helper function that enables `RedisSortObject` to be 
sorted based on `SortArgument`.
+  ///
+  /// It can assist in implementing the third parameter `Compare comp` 
required by `std::sort`
+  ///
+  /// \param args The basis used to compare two RedisSortObjects.
+  /// If `args.alpha` is false, `RedisSortObject.v` will be taken as double 
for comparison
+  /// If `args.alpha` is true and `args.sortby` is not empty, 
`RedisSortObject.v` will be taken as string for comparison
+  /// If `args.alpha` is true and `args.sortby` is empty, the comparison is by 
`RedisSortObject.obj`.

Review Comment:
   I think it is feasible to only use `std::variant<std::string, double>`, but 
this may require distinguishing between two types of `std::string`: 
BY(RedisSortObject.v) and the sort key itself(RedisSortObject.obj), resulting 
in unclear sorting logic.



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