Skip to content

Commit 1c9b12f

Browse files
author
gongna-au
committed
feat(bit): add BYTE/BIT option support for BITPOS command
1 parent 2520bda commit 1c9b12f

2 files changed

Lines changed: 26 additions & 30 deletions

File tree

src/commands/cmd_bit.cc

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -156,39 +156,37 @@ class CommandBitPos : public Commander {
156156
using Commander::Parse;
157157

158158
Status Parse(const std::vector<std::string> &args) override {
159-
if (args.size() >= 4) {
160-
auto parse_start = ParseInt<int64_t>(args[3], 10);
161-
if (!parse_start) {
162-
return {Status::RedisParseErr, errValueNotInteger};
163-
}
159+
auto parse_bit = ParseInt<int>(args[2], 10);
160+
if (!parse_bit || (*parse_bit != 0 && *parse_bit != 1)) {
161+
return {Status::RedisParseErr, "The bit argument must be 1 or 0."};
162+
}
163+
bit_ = (*parse_bit == 1);
164164

165-
start_ = *parse_start;
165+
if (args.size() >= 4) {
166+
start_ = GET_OR_RET(ParseInt<int64_t>(args[3], 10));
166167
}
167168

168-
if (args.size() >= 5) {
169-
auto parse_stop = ParseInt<int64_t>(args[4], 10);
170-
if (!parse_stop) {
171-
return {Status::RedisParseErr, errValueNotInteger};
169+
if (args.size() == 5) {
170+
if (util::EqualICase(args[4], "BIT")) {
171+
is_bit_index_ = true;
172+
} else if (util::EqualICase(args[4], "BYTE")) {
173+
is_bit_index_ = false;
174+
} else {
175+
stop_ = GET_OR_RET(ParseInt<int64_t>(args[4], 10));
176+
stop_given_ = true;
172177
}
173-
178+
} else if (args.size() == 6) {
179+
stop_ = GET_OR_RET(ParseInt<int64_t>(args[4], 10));
174180
stop_given_ = true;
175-
stop_ = *parse_stop;
176-
}
177-
178-
if (args.size() >= 6 && util::EqualICase(args[5], "BIT")) {
179-
is_bit_index_ = true;
180-
}
181-
182-
auto parse_arg = ParseInt<int64_t>(args[2], 10);
183-
if (!parse_arg) {
184-
return {Status::RedisParseErr, errValueNotInteger};
185-
}
186-
if (*parse_arg == 0) {
187-
bit_ = false;
188-
} else if (*parse_arg == 1) {
189-
bit_ = true;
190-
} else {
191-
return {Status::RedisParseErr, "The bit argument must be 1 or 0."};
181+
if (util::EqualICase(args[5], "BIT")) {
182+
is_bit_index_ = true;
183+
} else if (util::EqualICase(args[5], "BYTE")) {
184+
is_bit_index_ = false;
185+
} else {
186+
return {Status::RedisParseErr, errInvalidSyntax};
187+
}
188+
} else if (args.size() > 6) {
189+
return {Status::RedisParseErr, errInvalidSyntax};
192190
}
193191

194192
return Commander::Parse(args);

src/types/redis_bitmap.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ rocksdb::Status Bitmap::BitCount(engine::Context &ctx, const Slice &user_key, in
308308

309309
rocksdb::Status Bitmap::BitPos(engine::Context &ctx, const Slice &user_key, bool bit, int64_t start, int64_t stop,
310310
bool stop_given, int64_t *pos, bool is_bit_index) {
311-
if (is_bit_index) CHECK(stop_given);
312-
313311
std::string raw_value;
314312
std::string ns_key = AppendNamespacePrefix(user_key);
315313

0 commit comments

Comments
 (0)