mapleFU commented on code in PR #2262:
URL: https://github.com/apache/kvrocks/pull/2262#discussion_r1590676351
##########
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:
Sigh, I think maybe struct or other is ok, since the passed in argument (
`RedisSortObject` ) is defined by `args`. It cannot have another state ( like
holding a string when `!args.alpha` ), and this introduce a double-checking
here.
`std::variant` seems has same space usage as `struct {double; string;}`. But
both is ok for me
--
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]