You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "PragmaTwice (via GitHub)" <gi...@apache.org> on 2023/09/21 03:20:45 UTC
[GitHub] [kvrocks] PragmaTwice commented on a diff in pull request #1768: Add the support of the BF.INSERT command
PragmaTwice commented on code in PR #1768:
URL: https://github.com/apache/kvrocks/pull/1768#discussion_r1332395938
##########
src/commands/cmd_bloom_filter.cc:
##########
@@ -147,6 +151,103 @@ class CommandBFMAdd : public Commander {
std::vector<Slice> items_;
};
+class CommandBFInsert : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 2);
+ bool is_nonscaling = false;
+ bool has_expansion = false;
+ while (parser.Good()) {
+ if (parser.EatEqICase("capacity")) {
+ auto parse_capacity = parser.TakeInt<uint32_t>();
+ if (!parse_capacity.IsOK()) {
+ return {Status::RedisParseErr, "Bad capacity"};
+ }
+ insert_options_.capacity = parse_capacity.GetValue();
+ if (insert_options_.capacity <= 0) {
+ return {Status::RedisParseErr, "capacity should be larger than 0"};
+ }
+ } else if (parser.EatEqICase("error")) {
+ auto parse_error_rate = parser.TakeFloat<double>();
+ if (!parse_error_rate.IsOK()) {
+ return {Status::RedisParseErr, "Bad error rate"};
+ }
+ insert_options_.error_rate = parse_error_rate.GetValue();
+ if (insert_options_.error_rate >= 1 || insert_options_.error_rate <= 0) {
+ return {Status::RedisParseErr, "error rate should be between 0 and 1"};
+ }
+ } else if (parser.EatEqICase("nocreate")) {
+ insert_options_.auto_create = false;
+ } else if (parser.EatEqICase("nonscaling")) {
+ is_nonscaling = true;
+ insert_options_.expansion = 0;
+ } else if (parser.EatEqICase("expansion")) {
+ has_expansion = true;
+ auto parse_expansion = parser.TakeInt<uint16_t>();
+ if (!parse_expansion.IsOK()) {
+ return {Status::RedisParseErr, "Bad expansion"};
+ }
+ insert_options_.expansion = parse_expansion.GetValue();
+ if (insert_options_.expansion < 1) {
+ return {Status::RedisParseErr, "expansion should be greater or equal to 1"};
+ }
+ } else if (parser.EatEqICase("items")) {
+ break;
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ if (is_nonscaling && has_expansion) {
+ return {Status::RedisParseErr, "nonscaling filters cannot expand"};
+ }
+
+ auto items_begin =
+ find_if(args.begin(), args.end(), [](std::string_view lhs) { return lhs == "items" || lhs == "ITEMS"; });
Review Comment:
`util::EqualICase` is a better choice.
--
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: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org