Skip to content

Commit 701c404

Browse files
committed
Remove unnecessary diffs
Signed-off-by: dashjay <dashjwz@gmail.com>
1 parent b440283 commit 701c404

3 files changed

Lines changed: 12 additions & 21 deletions

File tree

src/commands/cmd_hash.cc

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,6 @@ class CommandHPersist : public Commander {
588588
public:
589589
Status Parse(const std::vector<std::string> &args) override {
590590
// HPERSIST key FIELDS numfields field [field ...]
591-
// Minimum: HPERSIST key FIELDS 1 field = 5 args
592591
if (args.size() < 5) {
593592
return {Status::RedisParseErr, errWrongNumOfArguments};
594593
}
@@ -606,7 +605,6 @@ class CommandHPersist : public Commander {
606605
return {Status::RedisExecErr, s.ToString()};
607606
}
608607

609-
// Return array of results
610608
std::vector<std::string> result_strings;
611609
result_strings.reserve(results.size());
612610
for (const auto &r : results) {
@@ -624,7 +622,6 @@ class CommandHTTL : public Commander {
624622
public:
625623
Status Parse(const std::vector<std::string> &args) override {
626624
// HTTL key FIELDS numfields field [field ...]
627-
// Minimum: HTTL key FIELDS 1 field = 5 args
628625
if (args.size() < 5) {
629626
return {Status::RedisParseErr, errWrongNumOfArguments};
630627
}
@@ -644,9 +641,6 @@ class CommandHTTL : public Commander {
644641

645642
auto current_time_ms = static_cast<int64_t>(util::GetTimeStampMS());
646643

647-
// httl returns time in seconds, hpttl returns time in milliseconds as TTLFields
648-
// hexpiretime returns expire_time in seconds, hpexpiretime returns expire_time in milliseconds as TTLFields already
649-
// does
650644
for (auto &r : results) {
651645
if (r > 0) {
652646
if (util::EqualICase(args_[0], "httl")) {
@@ -656,7 +650,6 @@ class CommandHTTL : public Commander {
656650
} else if (util::EqualICase(args_[0], "hexpiretime")) {
657651
r = r / 1000;
658652
} else if (util::EqualICase(args_[0], "hpexpiretime")) {
659-
// do nothing as TTLFields already returns expire_time in milliseconds
660653
}
661654
}
662655
}
@@ -676,13 +669,13 @@ class CommandHTTL : public Commander {
676669
class CommandHMSetEX : public Commander {
677670
public:
678671
Status Parse(const std::vector<std::string> &args) override {
672+
// HSETEX key [FNX | FXX] [EX seconds | PX milliseconds |
673+
// EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL]
674+
// FIELDS numfields field value [field value ...]
679675
if (args.size() < 7) {
680676
return {Status::RedisParseErr, errWrongNumOfArguments};
681677
}
682678

683-
size_t pos = 2;
684-
685-
// Lambda to parse expiration value with validation
686679
auto parse_expire_value = [](const std::string &value_str) -> uint64_t {
687680
auto result = ParseInt<uint64_t>(value_str, 10);
688681
if (!result || *result <= 0) {
@@ -691,11 +684,11 @@ class CommandHMSetEX : public Commander {
691684
return result.GetValue();
692685
};
693686

687+
size_t pos = 2;
694688
if (pos < args.size() && util::EqualICase(args[pos], std::string_view("FIELDS"))) {
695689
return {Status::RedisParseErr, "ERR Missing expiration option"};
696690
}
697691

698-
// Parse expiration option - optional
699692
params_.expire_params.option = SetEXExpireOption::kNoExpire;
700693
while (pos < args.size()) {
701694
const auto &opt = args[pos];
@@ -712,11 +705,9 @@ class CommandHMSetEX : public Commander {
712705
if (params_.expire_params.option == SetEXExpireOption::kNoExpire) {
713706
return {Status::RedisParseErr, "Invalid syntax: at least one expiration option is required before FIELDS"};
714707
} else {
715-
// FIELDS is a special case and should not be treated as an expiration option
716708
break;
717709
}
718710
} else {
719-
// got next must be a integer
720711
auto value = parse_expire_value(args[pos + 1]);
721712
params_.expire_params.value = value;
722713
if (value == 0) {
@@ -736,7 +727,6 @@ class CommandHMSetEX : public Commander {
736727
pos += 2;
737728
}
738729
}
739-
// Parse FIELDS and field-value pairs
740730
if (pos >= args.size() || !util::EqualICase(args[pos], "FIELDS")) {
741731
return {Status::RedisParseErr, "mandatory argument FIELDS is missing"};
742732
}
@@ -755,7 +745,6 @@ class CommandHMSetEX : public Commander {
755745
auto num_fields = *num_fields_result;
756746
pos++;
757747

758-
// Parse field-value pairs
759748
if (args.size() != pos + 2 * num_fields) {
760749
return {Status::RedisParseErr, "number of field-value pairs does not match numfields"};
761750
}

src/types/redis_hash.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <algorithm>
2626
#include <cctype>
2727
#include <cmath>
28-
#include <cstdint>
2928
#include <random>
3029
#include <utility>
3130

@@ -78,6 +77,7 @@ rocksdb::Status Hash::IncrBy(engine::Context &ctx, const Slice &user_key, const
7877
bool exists = false;
7978
int64_t old_value = 0;
8079
bool expired = false;
80+
8181
std::string ns_key = AppendNamespacePrefix(user_key);
8282

8383
HashMetadata metadata;
@@ -91,8 +91,8 @@ rocksdb::Status Hash::IncrBy(engine::Context &ctx, const Slice &user_key, const
9191
if (!s.ok() && !s.IsNotFound()) return s;
9292
if (s.ok()) {
9393
uint64_t expire_at = NoExpireTime;
94-
s = GetSubKeyExpireTimestampMS(ctx, user_key, field, metadata.version, &expire_at);
95-
if (!s.ok() && !s.IsNotFound()) return s;
94+
rocksdb::Status expire_s = GetSubKeyExpireTimestampMS(ctx, user_key, field, metadata.version, &expire_at);
95+
if (!expire_s.ok() && !expire_s.IsNotFound()) return expire_s;
9696
if (expire_at != NoExpireTime && expire_at < util::GetTimeStampMS()) {
9797
expired = true;
9898
old_value = 0;
@@ -137,6 +137,7 @@ rocksdb::Status Hash::IncrByFloat(engine::Context &ctx, const Slice &user_key, c
137137
bool exists = false;
138138
double old_value = 0;
139139
bool expired = false;
140+
140141
std::string ns_key = AppendNamespacePrefix(user_key);
141142

142143
HashMetadata metadata;
@@ -150,8 +151,8 @@ rocksdb::Status Hash::IncrByFloat(engine::Context &ctx, const Slice &user_key, c
150151
if (!s.ok() && !s.IsNotFound()) return s;
151152
if (s.ok()) {
152153
uint64_t expire_at = NoExpireTime;
153-
s = GetSubKeyExpireTimestampMS(ctx, user_key, field, metadata.version, &expire_at);
154-
if (!s.ok() && !s.IsNotFound()) return s;
154+
rocksdb::Status expire_s = GetSubKeyExpireTimestampMS(ctx, user_key, field, metadata.version, &expire_at);
155+
if (!expire_s.ok() && !expire_s.IsNotFound()) return expire_s;
155156
if (expire_at != NoExpireTime && expire_at < util::GetTimeStampMS()) {
156157
expired = true;
157158
old_value = 0;
@@ -308,6 +309,7 @@ rocksdb::Status Hash::MSet(engine::Context &ctx, const Slice &user_key, const st
308309
s = batch->PutLogData(log_data.Encode());
309310
if (!s.ok()) return s;
310311
std::unordered_set<std::string_view> field_set;
312+
311313
std::vector<rocksdb::Slice> keys;
312314
std::vector<rocksdb::Slice> origin_keys;
313315
std::vector<std::string> keys_encoded;
@@ -319,6 +321,7 @@ rocksdb::Status Hash::MSet(engine::Context &ctx, const Slice &user_key, const st
319321
if (!field_set.insert(it->field).second) {
320322
continue;
321323
}
324+
322325
origin_keys.emplace_back(it->field);
323326
keys_encoded.push_back(InternalKey(ns_key, it->field, metadata.version, storage_->IsSlotIdEncoded()).Encode());
324327
keys.emplace_back(keys_encoded.back());

src/types/redis_hash.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include <rocksdb/status.h>
2424

25-
#include <cstdint>
2625
#include <string>
2726
#include <vector>
2827

0 commit comments

Comments
 (0)