From a01c8f57dccdbb39bb69b09a6accbdc064935d24 Mon Sep 17 00:00:00 2001 From: LykxSassinator Date: Tue, 20 Jul 2021 11:37:36 +0800 Subject: [PATCH] Supplements of guideline of compilation on macOS with make and clean up some code (#334) --- README.md | 2 +- src/redis_cmd.cc | 2 +- src/redis_db.cc | 11 ++++++----- src/redis_hash.cc | 5 +++-- src/util.cc | 1 - 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2d745b46fc1..37a2e97e967 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ sudo yum install -y epel-release && sudo yum install -y git gcc gcc-c++ make sna sudo apt-get install gcc g++ make libsnappy-dev autoconf automake libtool which libgtest-dev # MACOSX -brew install snappy googletest +brew install autoconf automake libtool snappy googletest ``` It is as simple as: diff --git a/src/redis_cmd.cc b/src/redis_cmd.cc index e8e1a103cee..ff4b52f5c14 100644 --- a/src/redis_cmd.cc +++ b/src/redis_cmd.cc @@ -1177,7 +1177,7 @@ class CommandHMSet : public Commander { Redis::Hash hash_db(svr->storage_, conn->GetNamespace()); std::vector field_values; for (unsigned int i = 2; i < args_.size(); i += 2) { - field_values.push_back(FieldValue{args_[i], args_[i + 1]}); + field_values.emplace_back(FieldValue{args_[i], args_[i + 1]}); } rocksdb::Status s = hash_db.MSet(args_[1], field_values, false, &ret); if (!s.ok()) { diff --git a/src/redis_db.cc b/src/redis_db.cc index 2c87a7f4904..718cec0c5fb 100644 --- a/src/redis_db.cc +++ b/src/redis_db.cc @@ -443,6 +443,9 @@ rocksdb::Status Database::FindKeyRangeWithPrefix(const std::string &prefix, if (cf_handle == nullptr) { cf_handle = metadata_cf_handle_; } + if (prefix.empty()) { + return rocksdb::Status::NotFound(); + } begin->clear(); end->clear(); @@ -461,10 +464,8 @@ rocksdb::Status Database::FindKeyRangeWithPrefix(const std::string &prefix, // it's ok to increase the last char in prefix as the boundary of the prefix // while we limit the namespace last char shouldn't be larger than 128. std::string next_prefix = prefix; - char last_char = next_prefix.back(); - last_char++; - next_prefix.pop_back(); - next_prefix.push_back(last_char); + auto prefix_size = prefix.size(); + next_prefix[prefix_size - 1]++; iter->SeekForPrev(next_prefix); int max_prev_limit = 128; // prevent unpredicted long while loop int i = 0; @@ -553,7 +554,7 @@ std::string WriteBatchLogData::Encode() { } Status WriteBatchLogData::Decode(const rocksdb::Slice &blob) { - std::string log_data = blob.ToString(); + const std::string& log_data = blob.ToString(); std::vector args; Util::Split(log_data, " ", &args); type_ = static_cast(std::stoi(args[0])); diff --git a/src/redis_hash.cc b/src/redis_hash.cc index 004d860a990..0420824598a 100644 --- a/src/redis_hash.cc +++ b/src/redis_hash.cc @@ -1,4 +1,5 @@ #include "redis_hash.h" +#include #include #include #include @@ -168,14 +169,14 @@ rocksdb::Status Hash::MGet(const Slice &user_key, rocksdb::Status Hash::Set(const Slice &user_key, const Slice &field, const Slice &value, int *ret) { FieldValue fv = {field.ToString(), value.ToString()}; std::vector fvs; - fvs.push_back(fv); + fvs.emplace_back(std::move(fv)); return MSet(user_key, fvs, false, ret); } rocksdb::Status Hash::SetNX(const Slice &user_key, const Slice &field, Slice value, int *ret) { FieldValue fv = {field.ToString(), value.ToString()}; std::vector fvs; - fvs.push_back(fv); + fvs.emplace_back(std::move(fv)); return MSet(user_key, fvs, true, ret); } diff --git a/src/util.cc b/src/util.cc index fa9eec63aff..387f3222927 100644 --- a/src/util.cc +++ b/src/util.cc @@ -172,7 +172,6 @@ Status SockConnect(std::string host, uint32_t port, int *fd, uint64_t conn_timeo return Status(Status::NotOK, strerror(errno)); } SockSetTcpNoDelay(*fd, 1); - SockSetTcpNoDelay(*fd, 1); } if (timeout > 0) { struct timeval tv;