diff --git a/.clang-tidy b/.clang-tidy index 3064647a842..e1bb8f055d9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,7 +1,7 @@ # refer to https://clang.llvm.org/extra/clang-tidy/checks/list.html Checks: -*, clang-analyzer-core.*, clang-analyzer-cplusplus.*, clang-analyzer-deadcode.*, clang-analyzer-nullability.*, clang-analyzer-security.*, clang-analyzer-unix.*, clang-analyzer-valist.*, cppcoreguidelines-init-variables, cppcoreguidelines-macro-usage, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-special-member-functions, cppcoreguidelines-slicing, google-build-explicit-make-pair, google-default-arguments, google-explicit-constructor, modernize-avoid-bind, modernize-loop-convert, modernize-macro-to-enum, modernize-make-shared, modernize-make-unique, modernize-pass-by-value, modernize-redundant-void-arg, modernize-return-braced-init-list, modernize-use-auto, modernize-use-bool-literals, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, modernize-use-override, modernize-use-using, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-inefficient-vector-operation, performance-move-const-arg, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, performance-unnecessary-value-param -WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, cppcoreguidelines-slicing, google-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, modernize-use-bool-literals, performance-unnecessary-value-param, modernize-make-unique, performance-for-range-copy, performance-faster-string-find, modernize-redundant-void-arg, modernize-avoid-bind, modernize-use-auto, modernize-use-using, performance-inefficient-vector-operation, cppcoreguidelines-special-member-functions, modernize-loop-convert, cppcoreguidelines-init-variables, modernize-use-nullptr, cppcoreguidelines-macro-usage +WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, cppcoreguidelines-slicing, google-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, modernize-use-bool-literals, performance-unnecessary-value-param, modernize-make-unique, performance-for-range-copy, performance-faster-string-find, modernize-redundant-void-arg, modernize-avoid-bind, modernize-use-auto, modernize-use-using, performance-inefficient-vector-operation, cppcoreguidelines-special-member-functions, modernize-loop-convert, cppcoreguidelines-init-variables, modernize-use-nullptr, cppcoreguidelines-macro-usage, cppcoreguidelines-narrowing-conversions CheckOptions: - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor diff --git a/src/commands/redis_cmd.cc b/src/commands/redis_cmd.cc index 8edcef619d8..87ffae04991 100644 --- a/src/commands/redis_cmd.cc +++ b/src/commands/redis_cmd.cc @@ -670,7 +670,7 @@ class CommandPSetEX : public Commander { if (*ttl_ms < 1000) { ttl_ = 1; } else { - ttl_ = *ttl_ms / 1000; + ttl_ = static_cast(*ttl_ms / 1000); } return Commander::Parse(args); @@ -1270,7 +1270,7 @@ class CommandExpireAt : public Commander { return {Status::RedisParseErr, "the expire time was overflow"}; } - timestamp_ = *parse_result; + timestamp_ = static_cast(*parse_result); return Commander::Parse(args); } @@ -3470,7 +3470,7 @@ class CommandGeoRadius : public CommandGeoBase { } std::string GenerateOutput(const std::vector &geo_points) { - int result_length = geo_points.size(); + int result_length = static_cast(geo_points.size()); int returned_items_count = (count_ == 0 || result_length < count_) ? result_length : count_; std::vector list; for (int i = 0; i < returned_items_count; i++) { @@ -4581,7 +4581,7 @@ class CommandCommand : public Commander { GetCommandsInfo(output, std::vector(args_.begin() + 2, args_.end())); } else if (sub_command == "getkeys") { std::vector keys_indexes; - auto s = GetKeysFromCommand(args_[2], args_.size() - 2, &keys_indexes); + auto s = GetKeysFromCommand(args_[2], static_cast(args_.size()) - 2, &keys_indexes); if (!s.IsOK()) return s; if (keys_indexes.size() == 0) { @@ -5043,7 +5043,8 @@ class CommandFetchFile : public Commander { // Sleep if the speed of sending file is more than replication speed limit auto end = std::chrono::high_resolution_clock::now(); uint64_t duration = std::chrono::duration_cast(end - start).count(); - auto shortest = static_cast(static_cast(file_size) / max_replication_bytes * (1000 * 1000)); + auto shortest = static_cast(static_cast(file_size) / + static_cast(max_replication_bytes) * (1000 * 1000)); if (max_replication_bytes > 0 && duration < shortest) { LOG(INFO) << "[replication] Need to sleep " << (shortest - duration) / 1000 << " ms since of sending files too quickly"; diff --git a/src/common/io_util.cc b/src/common/io_util.cc index 99e16f32e15..4c3e40baf70 100644 --- a/src/common/io_util.cc +++ b/src/common/io_util.cc @@ -130,7 +130,7 @@ Status SockSetTcpKeepalive(int fd, int interval) { return Status::OK(); } -Status SockConnect(const std::string &host, uint32_t port, int *fd, uint64_t conn_timeout, uint64_t timeout) { +Status SockConnect(const std::string &host, uint32_t port, int *fd, int conn_timeout, int timeout) { if (conn_timeout == 0) { auto s = SockConnect(host, port, fd); if (!s) return s; @@ -307,16 +307,16 @@ int GetLocalPort(int fd) { return 0; } -bool IsPortInUse(int port) { +bool IsPortInUse(uint32_t port) { int fd = NullFD; - Status s = SockConnect("0.0.0.0", static_cast(port), &fd); + Status s = SockConnect("0.0.0.0", port, &fd); if (fd != NullFD) close(fd); return s.IsOK(); } /* Wait for milliseconds until the given file descriptor becomes * writable/readable/exception */ -int aeWait(int fd, int mask, uint64_t timeout) { +int aeWait(int fd, int mask, int timeout) { pollfd pfd; int retmask = 0, retval = 0; diff --git a/src/common/io_util.h b/src/common/io_util.h index 23f431b4de0..87fdc3d6560 100644 --- a/src/common/io_util.h +++ b/src/common/io_util.h @@ -28,7 +28,7 @@ namespace Util { sockaddr_in NewSockaddrInet(const std::string &host, uint32_t port); Status SockConnect(const std::string &host, uint32_t port, int *fd); -Status SockConnect(const std::string &host, uint32_t port, int *fd, uint64_t conn_timeout, uint64_t timeout = 0); +Status SockConnect(const std::string &host, uint32_t port, int *fd, int conn_timeout, int timeout = 0); Status SockSetTcpNoDelay(int fd, int val); Status SockSetTcpKeepalive(int fd, int interval); Status SockSend(int fd, const std::string &data); @@ -37,9 +37,9 @@ Status SockSendFile(int out_fd, int in_fd, size_t size); Status SockSetBlocking(int fd, int blocking); int GetPeerAddr(int fd, std::string *addr, uint32_t *port); int GetLocalPort(int fd); -bool IsPortInUse(int port); +bool IsPortInUse(uint32_t port); -int aeWait(int fd, int mask, uint64_t milliseconds); +int aeWait(int fd, int mask, int milliseconds); Status Write(int fd, const std::string &data); Status Pwrite(int fd, const std::string &data, off_t offset); diff --git a/src/common/string_util.cc b/src/common/string_util.cc index f4a48736ad8..03cfe67ecf7 100644 --- a/src/common/string_util.cc +++ b/src/common/string_util.cc @@ -121,50 +121,50 @@ int StringMatch(const std::string &pattern, const std::string &in, int nocase) { } // Glob-style pattern matching. -int StringMatchLen(const char *pattern, int patternLen, const char *string, int stringLen, int nocase) { - while (patternLen && stringLen) { +int StringMatchLen(const char *pattern, size_t pattern_len, const char *string, size_t string_len, int nocase) { + while (pattern_len && string_len) { switch (pattern[0]) { case '*': while (pattern[1] == '*') { pattern++; - patternLen--; + pattern_len--; } - if (patternLen == 1) return 1; /* match */ - while (stringLen) { - if (StringMatchLen(pattern + 1, patternLen - 1, string, stringLen, nocase)) return 1; /* match */ + if (pattern_len == 1) return 1; /* match */ + while (string_len) { + if (StringMatchLen(pattern + 1, pattern_len - 1, string, string_len, nocase)) return 1; /* match */ string++; - stringLen--; + string_len--; } return 0; /* no match */ break; case '?': - if (stringLen == 0) return 0; /* no match */ + if (string_len == 0) return 0; /* no match */ string++; - stringLen--; + string_len--; break; case '[': { int not_symbol = 0, match = 0; pattern++; - patternLen--; + pattern_len--; not_symbol = pattern[0] == '^'; if (not_symbol) { pattern++; - patternLen--; + pattern_len--; } match = 0; while (true) { - if (pattern[0] == '\\' && patternLen >= 2) { + if (pattern[0] == '\\' && pattern_len >= 2) { pattern++; - patternLen--; + pattern_len--; if (pattern[0] == string[0]) match = 1; } else if (pattern[0] == ']') { break; - } else if (patternLen == 0) { + } else if (pattern_len == 0) { pattern--; - patternLen++; + pattern_len++; break; - } else if (pattern[1] == '-' && patternLen >= 3) { + } else if (pattern[1] == '-' && pattern_len >= 3) { int start = pattern[0]; int end = pattern[2]; int c = string[0]; @@ -179,7 +179,7 @@ int StringMatchLen(const char *pattern, int patternLen, const char *string, int c = tolower(c); } pattern += 2; - patternLen -= 2; + pattern_len -= 2; if (c >= start && c <= end) match = 1; } else { if (!nocase) { @@ -189,18 +189,18 @@ int StringMatchLen(const char *pattern, int patternLen, const char *string, int } } pattern++; - patternLen--; + pattern_len--; } if (not_symbol) match = !match; if (!match) return 0; /* no match */ string++; - stringLen--; + string_len--; break; } case '\\': - if (patternLen >= 2) { + if (pattern_len >= 2) { pattern++; - patternLen--; + pattern_len--; } /* fall through */ default: @@ -210,20 +210,20 @@ int StringMatchLen(const char *pattern, int patternLen, const char *string, int if (tolower(static_cast(pattern[0])) != tolower(static_cast(string[0]))) return 0; /* no match */ } string++; - stringLen--; + string_len--; break; } pattern++; - patternLen--; - if (stringLen == 0) { + pattern_len--; + if (string_len == 0) { while (*pattern == '*') { pattern++; - patternLen--; + pattern_len--; } break; } } - if (patternLen == 0 && stringLen == 0) return 1; + if (pattern_len == 0 && string_len == 0) return 1; return 0; } diff --git a/src/common/string_util.h b/src/common/string_util.h index 9ed3a1450ef..e67893c7308 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -35,7 +35,7 @@ std::vector Split(const std::string &in, const std::string &delim); std::vector Split2KV(const std::string &in, const std::string &delim); bool HasPrefix(const std::string &str, const std::string &prefix); int StringMatch(const std::string &pattern, const std::string &in, int nocase); -int StringMatchLen(const char *p, int plen, const char *s, int slen, int nocase); +int StringMatchLen(const char *p, size_t plen, const char *s, size_t slen, int nocase); std::string StringToHex(const std::string &input); std::vector TokenizeRedisProtocol(const std::string &value); diff --git a/src/config/config.cc b/src/config/config.cc index 8982a7a98c5..5fecfe7ecd7 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -97,9 +97,9 @@ Config::Config() { FieldWrapper fields[] = { {"daemonize", true, new YesNoField(&daemonize, false)}, {"bind", true, new StringField(&binds_, "")}, - {"port", true, new IntField(&port, kDefaultPort, 1, PORT_LIMIT)}, + {"port", true, new UInt32Field(&port, kDefaultPort, 1, PORT_LIMIT)}, #ifdef ENABLE_OPENSSL - {"tls-port", true, new IntField(&tls_port, 0, 0, PORT_LIMIT)}, + {"tls-port", true, new UInt32Field(&tls_port, 0, 0, PORT_LIMIT)}, {"tls-cert-file", false, new StringField(&tls_cert_file, "")}, {"tls-key-file", false, new StringField(&tls_key_file, "")}, {"tls-key-file-pass", false, new StringField(&tls_key_file_pass, "")}, @@ -268,8 +268,8 @@ void Config::initFieldValidator() { s = Util::DecimalStringToNum(args[1], &stop, 0, 24); if (!s.IsOK()) return s; if (start > stop) return Status(Status::NotOK, "invalid range format, start should be smaller than stop"); - compaction_checker_range.Start = start; - compaction_checker_range.Stop = stop; + compaction_checker_range.Start = static_cast(start); + compaction_checker_range.Stop = static_cast(stop); return Status::OK(); }}, {"rename-command", @@ -430,7 +430,7 @@ void Config::initFieldCallback() { {"max-io-mb", [this](Server *srv, const std::string &k, const std::string &v) -> Status { if (!srv) return Status::OK(); - srv->storage_->SetIORateLimit(static_cast(max_io_mb)); + srv->storage_->SetIORateLimit(max_io_mb); return Status::OK(); }}, {"profiling-sample-record-max-len", @@ -588,7 +588,7 @@ void Config::initFieldCallback() { } } -void Config::SetMaster(const std::string &host, int port) { +void Config::SetMaster(const std::string &host, uint32_t port) { master_host = host; master_port = port; auto iter = fields_.find("slaveof"); diff --git a/src/config/config.h b/src/config/config.h index e57145260b0..144ae192deb 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -39,7 +39,7 @@ namespace Engine { class Storage; } -constexpr const uint16_t PORT_LIMIT = 65535; +constexpr const uint32_t PORT_LIMIT = 65535; enum SupervisedMode { kSupervisedNone = 0, kSupervisedAutoDetect, kSupervisedSystemd, kSupervisedUpStart }; @@ -49,7 +49,7 @@ constexpr const char *TLS_AUTH_CLIENTS_OPTIONAL = "optional"; constexpr const size_t KiB = 1024L; constexpr const size_t MiB = 1024L * KiB; constexpr const size_t GiB = 1024L * MiB; -constexpr const int kDefaultPort = 6666; +constexpr const uint32_t kDefaultPort = 6666; extern const char *kDefaultNamespace; @@ -73,8 +73,8 @@ struct Config { public: Config(); ~Config() = default; - int port = 0; - int tls_port = 0; + uint32_t port = 0; + uint32_t tls_port = 0; std::string tls_cert_file; std::string tls_key_file; std::string tls_key_file_pass; @@ -127,7 +127,7 @@ struct Config { std::string master_host; std::string unixsocket; int unixsocketperm = 0777; - int master_port = 0; + uint32_t master_port = 0; Cron compact_cron; Cron bgsave_cron; CompactionCheckerRange compaction_checker_range{-1, -1}; @@ -197,7 +197,7 @@ struct Config { Status Load(const CLIOptions &path); void Get(const std::string &key, std::vector *values); Status Set(Server *svr, std::string key, const std::string &value); - void SetMaster(const std::string &host, int port); + void SetMaster(const std::string &host, uint32_t port); void ClearMaster(); Status GetNamespace(const std::string &ns, std::string *token); Status AddNamespace(const std::string &ns, const std::string &token); diff --git a/src/config/config_type.h b/src/config/config_type.h index ad776f926f8..65e774d9eb1 100644 --- a/src/config/config_type.h +++ b/src/config/config_type.h @@ -22,9 +22,11 @@ #include +#include #include #include +#include "parse_util.h" #include "status.h" #include "string_util.h" @@ -34,6 +36,14 @@ class Server; using validate_fn = std::function; using callback_fn = std::function; +// forward declaration +template +class IntegerField; + +using IntField = IntegerField; +using UInt32Field = IntegerField; +using Int64Field = IntegerField; + struct configEnum { const char *name; const int val; @@ -101,27 +111,30 @@ class MultiStringField : public ConfigField { std::vector *receiver_; }; -class IntField : public ConfigField { +template +class IntegerField : public ConfigField { public: - IntField(int *receiver, int n, int min, int max) : receiver_(receiver), min_(min), max_(max) { *receiver_ = n; } - ~IntField() override = default; + IntegerField(IntegerType *receiver, IntegerType n, IntegerType min, IntegerType max) + : receiver_(receiver), min_(min), max_(max) { + *receiver_ = n; + } + ~IntegerField() override = default; std::string ToString() override { return std::to_string(*receiver_); } Status ToNumber(int64_t *n) override { *n = *receiver_; return Status::OK(); } Status Set(const std::string &v) override { - int64_t n; - auto s = Util::DecimalStringToNum(v, &n, min_, max_); + auto s = ParseInt(v, {min_, max_}); if (!s.IsOK()) return s; - *receiver_ = static_cast(n); + *receiver_ = s.GetValue(); return Status::OK(); } private: - int *receiver_; - int min_ = INT_MIN; - int max_ = INT_MAX; + IntegerType *receiver_; + IntegerType min_ = std::numeric_limits::min(); + IntegerType max_ = std::numeric_limits::max(); }; class OctalField : public ConfigField { @@ -147,31 +160,6 @@ class OctalField : public ConfigField { int max_ = INT_MAX; }; -class Int64Field : public ConfigField { - public: - Int64Field(int64_t *receiver, int64_t n, int64_t min, int64_t max) : receiver_(receiver), min_(min), max_(max) { - *receiver_ = n; - } - ~Int64Field() override = default; - std::string ToString() override { return std::to_string(*receiver_); } - Status ToNumber(int64_t *n) override { - *n = *receiver_; - return Status::OK(); - } - Status Set(const std::string &v) override { - int64_t n; - auto s = Util::DecimalStringToNum(v, &n, min_, max_); - if (!s.IsOK()) return s; - *receiver_ = n; - return Status::OK(); - } - - private: - int64_t *receiver_; - int64_t min_ = INT64_MIN; - int64_t max_ = INT64_MAX; -}; - class YesNoField : public ConfigField { public: YesNoField(bool *receiver, bool b) : receiver_(receiver) { *receiver_ = b; } diff --git a/src/main.cc b/src/main.cc index e8d1bb44319..356b49c9c6f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -81,7 +81,7 @@ extern "C" void segvHandler(int sig, siginfo_t *info, void *secret) { for (int i = 1; i < trace_size; ++i) { char func_info[1024] = {}; if (google::Symbolize(trace[i], func_info, sizeof(func_info) - 1)) { - LOG(ERROR) << std::left << std::setw(max_msg_len) << messages[i] << " " << func_info; + LOG(ERROR) << std::left << std::setw(static_cast(max_msg_len)) << messages[i] << " " << func_info; } else { LOG(ERROR) << messages[i]; } @@ -309,8 +309,8 @@ int main(int argc, char *argv[]) { // but the server use REUSE_PORT to support the multi listeners. So we connect // the listen port to check if the port has already listened or not. if (!config.binds.empty()) { - int ports[] = {config.port, config.tls_port, 0}; - for (int *port = ports; *port; ++port) { + uint32_t ports[] = {config.port, config.tls_port, 0}; + for (uint32_t *port = ports; *port; ++port) { if (Util::IsPortInUse(*port)) { LOG(ERROR) << "Could not create server TCP since the specified port[" << *port << "] is already in use" << std::endl; diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc index 2f5b7770d6c..8f41750ee17 100644 --- a/src/server/redis_connection.cc +++ b/src/server/redis_connection.cc @@ -126,7 +126,7 @@ void Connection::SendFile(int fd) { evbuffer_add_file(output, fd, 0, -1); } -void Connection::SetAddr(std::string ip, int port) { +void Connection::SetAddr(std::string ip, uint32_t port) { ip_ = std::move(ip); port_ = port; addr_ = ip_ + ":" + std::to_string(port_); @@ -196,7 +196,7 @@ void Connection::UnSubscribeChannel(const std::string &channel) { void Connection::UnSubscribeAll(const unsubscribe_callback &reply) { if (subscribe_channels_.empty()) { - if (reply != nullptr) reply("", subcribe_patterns_.size()); + if (reply != nullptr) reply("", static_cast(subcribe_patterns_.size())); return; } int removed = 0; @@ -233,7 +233,7 @@ void Connection::PUnSubscribeChannel(const std::string &pattern) { void Connection::PUnSubscribeAll(const unsubscribe_callback &reply) { if (subcribe_patterns_.empty()) { - if (reply != nullptr) reply("", subscribe_channels_.size()); + if (reply != nullptr) reply("", static_cast(subscribe_channels_.size())); return; } diff --git a/src/server/redis_connection.h b/src/server/redis_connection.h index b9522532b9c..54e86f0cf29 100644 --- a/src/server/redis_connection.h +++ b/src/server/redis_connection.h @@ -79,7 +79,7 @@ class Connection { std::string GetName() { return name_; } void SetName(std::string name) { name_ = std::move(name); } std::string GetAddr() { return addr_; } - void SetAddr(std::string ip, int port); + void SetAddr(std::string ip, uint32_t port); void SetLastCmd(std::string cmd) { last_cmd_ = std::move(cmd); } std::string GetIP() { return ip_; } int GetPort() { return port_; } @@ -125,7 +125,7 @@ class Connection { std::string ns_; std::string name_; std::string ip_; - int port_ = 0; + uint32_t port_ = 0; std::string addr_; int listening_port_ = 0; bool is_admin_ = false; diff --git a/src/server/redis_reply.cc b/src/server/redis_reply.cc index 741b9e755cf..86ccf030e54 100644 --- a/src/server/redis_reply.cc +++ b/src/server/redis_reply.cc @@ -30,14 +30,10 @@ std::string SimpleString(const std::string &data) { return "+" + data + CRLF; } std::string Error(const std::string &err) { return "-" + err + CRLF; } -std::string Integer(int64_t data) { return ":" + std::to_string(data) + CRLF; } - std::string BulkString(const std::string &data) { return "$" + std::to_string(data.length()) + CRLF + data + CRLF; } std::string NilString() { return "$-1" CRLF; } -std::string MultiLen(int64_t len) { return "*" + std::to_string(len) + CRLF; } - std::string MultiBulkString(const std::vector &values, bool output_nil_for_empty_string) { std::string result = "*" + std::to_string(values.size()) + CRLF; for (const auto &value : values) { diff --git a/src/server/redis_reply.h b/src/server/redis_reply.h index ebf4fe449bc..436b9f12d77 100644 --- a/src/server/redis_reply.h +++ b/src/server/redis_reply.h @@ -32,10 +32,20 @@ namespace Redis { void Reply(evbuffer *output, const std::string &data); std::string SimpleString(const std::string &data); std::string Error(const std::string &err); -std::string Integer(int64_t data); + +template +std::string Integer(IntegerType data) { + return ":" + std::to_string(data) + CRLF; +} + std::string BulkString(const std::string &data); std::string NilString(); -std::string MultiLen(int64_t len); + +template +std::string MultiLen(IntegerType len) { + return "*" + std::to_string(len) + CRLF; +} + std::string Array(const std::vector &list); std::string MultiBulkString(const std::vector &values, bool output_nil_for_empty_string = true); std::string MultiBulkString(const std::vector &values, const std::vector &statuses); diff --git a/src/server/redis_request.cc b/src/server/redis_request.cc index 220663310f2..c5c43381c8f 100644 --- a/src/server/redis_request.cc +++ b/src/server/redis_request.cc @@ -110,7 +110,7 @@ Status Request::Tokenize(evbuffer *input) { } case BulkData: if (evbuffer_get_length(input) < bulk_len_ + 2) return Status::OK(); - char *data = reinterpret_cast(evbuffer_pullup(input, bulk_len_ + 2)); + char *data = reinterpret_cast(evbuffer_pullup(input, static_cast(bulk_len_ + 2))); tokens_.emplace_back(data, bulk_len_); evbuffer_drain(input, bulk_len_ + 2); svr_->stats_.IncrInbondBytes(bulk_len_ + 2); diff --git a/src/server/server.cc b/src/server/server.cc index daccf0a2b61..fd7bfe07fb7 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -157,7 +157,7 @@ Status Server::Start() { compaction_checker_thread_ = std::thread([this]() { uint64_t counter = 0; - int32_t last_compact_date = 0; + time_t last_compact_date = 0; Util::ThreadSetName("compact-check"); CompactionChecker compaction_checker(this->storage_); while (!stop_) { @@ -1037,7 +1037,9 @@ void Server::GetInfo(const std::string &ns, const std::string §ion, std::str string_stream << "sequence:" << storage_->GetDB()->GetLatestSequenceNumber() << "\r\n"; string_stream << "used_db_size:" << storage_->GetTotalSize(ns) << "\r\n"; string_stream << "max_db_size:" << config_->max_db_size * GiB << "\r\n"; - double used_percent = config_->max_db_size ? storage_->GetTotalSize() * 100 / (config_->max_db_size * GiB) : 0; + double used_percent = config_->max_db_size ? static_cast(storage_->GetTotalSize() * 100) / + static_cast(config_->max_db_size * GiB) + : 0; string_stream << "used_percent: " << used_percent << "%\r\n"; struct statvfs stat; if (statvfs(config_->db_dir.c_str(), &stat) == 0) { @@ -1045,7 +1047,7 @@ void Server::GetInfo(const std::string &ns, const std::string §ion, std::str auto used_disk_size = (stat.f_blocks - stat.f_bavail) * stat.f_frsize; string_stream << "disk_capacity:" << disk_capacity << "\r\n"; string_stream << "used_disk_size:" << used_disk_size << "\r\n"; - double used_disk_percent = used_disk_size * 100 / disk_capacity; + double used_disk_percent = static_cast(used_disk_size * 100) / static_cast(disk_capacity); string_stream << "used_disk_percent: " << used_disk_percent << "%\r\n"; } } diff --git a/src/server/worker.cc b/src/server/worker.cc index 80a9a9211cd..c7f82ebc88f 100644 --- a/src/server/worker.cc +++ b/src/server/worker.cc @@ -59,10 +59,10 @@ Worker::Worker(Server *svr, Config *config, bool repl) : svr_(svr) { timeval tm = {10, 0}; evtimer_add(timer_, &tm); - int ports[3] = {config->port, config->tls_port, 0}; + uint32_t ports[3] = {config->port, config->tls_port, 0}; auto binds = config->binds; - for (int *port = ports; *port; ++port) { + for (uint32_t *port = ports; *port; ++port) { for (const auto &bind : binds) { Status s = listenTCP(bind, *port, config->backlog); if (!s.IsOK()) { @@ -200,7 +200,7 @@ void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t f } } -Status Worker::listenTCP(const std::string &host, int port, int backlog) { +Status Worker::listenTCP(const std::string &host, uint32_t port, int backlog) { int af = 0, rv = 0, fd = 0, sock_opt = 1; if (strchr(host.data(), ':')) { diff --git a/src/server/worker.h b/src/server/worker.h index f2f53e2254d..365a1244408 100644 --- a/src/server/worker.h +++ b/src/server/worker.h @@ -70,7 +70,7 @@ class Worker { Server *svr_; private: - Status listenTCP(const std::string &host, int port, int backlog); + Status listenTCP(const std::string &host, uint32_t port, int backlog); static void newTCPConnection(evconnlistener *listener, evutil_socket_t fd, sockaddr *address, int socklen, void *ctx); static void newUnixSocketConnection(evconnlistener *listener, evutil_socket_t fd, sockaddr *address, int socklen, void *ctx); diff --git a/src/stats/log_collector.cc b/src/stats/log_collector.cc index 629b0b81a0b..08211dbbc81 100644 --- a/src/stats/log_collector.cc +++ b/src/stats/log_collector.cc @@ -53,7 +53,7 @@ LogCollector::~LogCollector() { template ssize_t LogCollector::Size() { - size_t n = 0; + ssize_t n = 0; std::lock_guard guard(mu_); n = entries_.size(); return n; diff --git a/src/storage/lock_manager.cc b/src/storage/lock_manager.cc index 49fc52e3432..f4668526c93 100644 --- a/src/storage/lock_manager.cc +++ b/src/storage/lock_manager.cc @@ -37,9 +37,7 @@ LockManager::~LockManager() { } } -unsigned LockManager::hash(const rocksdb::Slice &key) { - return static_cast(std::hash{}(key.ToString()) & hash_mask_); -} +unsigned LockManager::hash(const rocksdb::Slice &key) { return std::hash{}(key.ToString()) & hash_mask_; } unsigned LockManager::Size() { return (1U << hash_power_); } diff --git a/src/storage/lock_manager.h b/src/storage/lock_manager.h index 9520649b3e5..e6ff30a02b3 100644 --- a/src/storage/lock_manager.h +++ b/src/storage/lock_manager.h @@ -39,7 +39,7 @@ class LockManager { private: int hash_power_; - int hash_mask_; + unsigned hash_mask_; std::vector mutex_pool_; unsigned hash(const rocksdb::Slice &key); }; diff --git a/src/storage/scripting.cc b/src/storage/scripting.cc index 57ffcca6951..7d165715336 100644 --- a/src/storage/scripting.cc +++ b/src/storage/scripting.cc @@ -203,7 +203,7 @@ int redisLogCommand(lua_State *lua) { lua_pushstring(lua, "First argument must be a number (log level)."); return lua_error(lua); } - level = lua_tonumber(lua, -argc); + level = static_cast(lua_tonumber(lua, -argc)); if (level < LL_DEBUG || level > LL_WARNING) { lua_pushstring(lua, "Invalid debug level."); return lua_error(lua); @@ -269,7 +269,7 @@ Status evalGenericCommand(Redis::Connection *conn, const std::vector= 'A' && sha[j] <= 'Z') ? sha[j] + ('a' - 'A') : sha[j]; + funcname[j + 2] = (sha[j] >= 'A' && sha[j] <= 'Z') ? static_cast(sha[j] + 'a' - 'A') : sha[j]; } funcname[42] = '\0'; } @@ -835,7 +835,7 @@ void sortArray(lua_State *lua) { void setGlobalArray(lua_State *lua, const std::string &var, const std::vector &elems) { lua_newtable(lua); - for (size_t i = 0; i < elems.size(); i++) { + for (int i = 0; i < elems.size(); i++) { lua_pushlstring(lua, elems[i].c_str(), elems[i].size()); lua_rawseti(lua, -2, i + 1); } diff --git a/src/storage/storage.cc b/src/storage/storage.cc index b5f38a6774c..efb7e46942a 100644 --- a/src/storage/storage.cc +++ b/src/storage/storage.cc @@ -64,7 +64,7 @@ const char *kLuaFunctionPrefix = "lua_f_"; const char *kReplicationIdKey = "replication_id_"; -const uint64_t kIORateLimitMaxMb = 1024000; +const int64_t kIORateLimitMaxMb = 1024000; using rocksdb::Slice; @@ -169,9 +169,10 @@ rocksdb::Options Storage::InitOptions() { options.dump_malloc_stats = true; sst_file_manager_ = std::shared_ptr(rocksdb::NewSstFileManager(rocksdb::Env::Default())); options.sst_file_manager = sst_file_manager_; - uint64_t max_io_mb = kIORateLimitMaxMb; - if (config_->max_io_mb > 0) max_io_mb = static_cast(config_->max_io_mb); - rate_limiter_ = std::shared_ptr(rocksdb::NewGenericRateLimiter(max_io_mb * MiB)); + int64_t max_io_mb = kIORateLimitMaxMb; + if (config_->max_io_mb > 0) max_io_mb = config_->max_io_mb; + rate_limiter_ = + std::shared_ptr(rocksdb::NewGenericRateLimiter(max_io_mb * static_cast(MiB))); options.rate_limiter = rate_limiter_; options.delayed_write_rate = static_cast(config_->RocksDB.delayed_write_rate); options.compaction_readahead_size = static_cast(config_->RocksDB.compaction_readahead_size); @@ -623,11 +624,11 @@ Status Storage::CheckDBSizeLimit() { return Status::OK(); } -void Storage::SetIORateLimit(uint64_t max_io_mb) { +void Storage::SetIORateLimit(int64_t max_io_mb) { if (max_io_mb == 0) { max_io_mb = kIORateLimitMaxMb; } - rate_limiter_->SetBytesPerSecond(max_io_mb * MiB); + rate_limiter_->SetBytesPerSecond(max_io_mb * static_cast(MiB)); } rocksdb::DB *Storage::GetDB() { return db_; } @@ -646,7 +647,7 @@ Status Storage::WriteToPropagateCF(const std::string &key, const std::string &va bool Storage::ShiftReplId() { const char *charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - const int charset_len = strlen(charset); + const int charset_len = static_cast(strlen(charset)); // Do nothing if don't enable rsid psync if (!config_->use_rsid_psync) return true; diff --git a/src/storage/storage.h b/src/storage/storage.h index 689eb2d0756..01dd61303b8 100644 --- a/src/storage/storage.h +++ b/src/storage/storage.h @@ -103,7 +103,7 @@ class Storage { void PurgeOldBackups(uint32_t num_backups_to_keep, uint32_t backup_max_keep_hours); uint64_t GetTotalSize(const std::string &ns = kDefaultNamespace); Status CheckDBSizeLimit(); - void SetIORateLimit(uint64_t max_io_mb); + void SetIORateLimit(int64_t max_io_mb); std::unique_ptr ReadLockGuard(); std::unique_ptr WriteLockGuard(); diff --git a/src/types/geohash.cc b/src/types/geohash.cc index 438731f3bff..c613abd43ff 100644 --- a/src/types/geohash.cc +++ b/src/types/geohash.cc @@ -180,9 +180,9 @@ int geohashEncode(const GeoHashRange *long_range, const GeoHashRange *lat_range, double long_offset = (longitude - long_range->min) / (long_range->max - long_range->min); /* convert to fixed point based on the step size */ - lat_offset *= (1ULL << step); - long_offset *= (1ULL << step); - hash->bits = interleave64(lat_offset, long_offset); + lat_offset *= static_cast(1ULL << step); + long_offset *= static_cast(1ULL << step); + hash->bits = interleave64(static_cast(lat_offset), static_cast(long_offset)); return 1; } @@ -215,10 +215,10 @@ int geohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range, /* divide by 2**step. * Then, for 0-1 coordinate, multiply times scale and add to the min to get the absolute coordinate. */ - area->latitude.min = lat_range.min + (ilato * 1.0 / (1ull << step)) * lat_scale; - area->latitude.max = lat_range.min + ((ilato + 1) * 1.0 / (1ull << step)) * lat_scale; - area->longitude.min = long_range.min + (ilono * 1.0 / (1ull << step)) * long_scale; - area->longitude.max = long_range.min + ((ilono + 1) * 1.0 / (1ull << step)) * long_scale; + area->latitude.min = lat_range.min + (ilato * 1.0 / static_cast(1ull << step)) * lat_scale; + area->latitude.max = lat_range.min + ((ilato + 1) * 1.0 / static_cast(1ull << step)) * lat_scale; + area->longitude.min = long_range.min + (ilono * 1.0 / static_cast(1ull << step)) * long_scale; + area->longitude.max = long_range.min + ((ilono + 1) * 1.0 / static_cast(1ull << step)) * long_scale; return 1; } diff --git a/src/types/redis_bitmap.cc b/src/types/redis_bitmap.cc index bb151cd7c6e..c81d5414afb 100644 --- a/src/types/redis_bitmap.cc +++ b/src/types/redis_bitmap.cc @@ -165,7 +165,7 @@ rocksdb::Status Bitmap::GetString(const Slice &user_key, const uint32_t max_btos 0x3F, 0xBF, 0x7F, 0xFF}; for (uint32_t i = 0; i < valid_size; i++) { if (!fragment[i]) continue; - fragment[i] = swap_table[static_cast(fragment[i])]; + fragment[i] = static_cast(swap_table[static_cast(fragment[i])]); ; } value->replace(frag_index, valid_size, fragment.data(), valid_size); @@ -211,9 +211,9 @@ rocksdb::Status Bitmap::SetBit(const Slice &user_key, uint32_t offset, bool new_ uint32_t bit_offset = offset % 8; *old_bit = (value[byte_index] & (1 << bit_offset)) != 0; if (new_bit) { - value[byte_index] |= 1 << bit_offset; + value[byte_index] = static_cast(value[byte_index] | (1 << bit_offset)); } else { - value[byte_index] &= ~(1 << bit_offset); + value[byte_index] = static_cast(value[byte_index] & (~(1 << bit_offset))); } rocksdb::WriteBatch batch; WriteBatchLogData log_data(kRedisBitmap, {std::to_string(kRedisCmdSetBit), std::to_string(offset)}); @@ -536,7 +536,7 @@ rocksdb::Status Bitmap::BitOp(BitOpFlags op_flag, const std::string &op_name, co res_metadata.size = max_size; res_metadata.Encode(&bytes); batch.Put(metadata_cf_handle_, ns_key, bytes); - *len = max_size; + *len = static_cast(max_size); return storage_->Write(storage_->DefaultWriteOptions(), &batch); } diff --git a/src/types/redis_bitmap_string.cc b/src/types/redis_bitmap_string.cc index 4aa0b1b9adb..f78592952d7 100644 --- a/src/types/redis_bitmap_string.cc +++ b/src/types/redis_bitmap_string.cc @@ -51,8 +51,8 @@ rocksdb::Status BitmapString::SetBit(const Slice &ns_key, std::string *raw_value auto byteval = string_value[byte_index]; *old_bit = (byteval & (1 << bit_offset)) != 0; - byteval &= ~(1 << bit_offset); - byteval |= ((new_bit & 0x1) << bit_offset); + byteval = static_cast(byteval & (~(1 << bit_offset))); + byteval = static_cast(byteval | ((new_bit & 0x1) << bit_offset)); string_value[byte_index] = byteval; *raw_value = raw_value->substr(0, STRING_HDR_SIZE); @@ -71,12 +71,12 @@ rocksdb::Status BitmapString::BitCount(const std::string &raw_value, int64_t sta if (start < 0 && stop < 0 && start > stop) { return rocksdb::Status::OK(); } - auto strlen = string_value.size(); + auto strlen = static_cast(string_value.size()); if (start < 0) start = strlen + start; if (stop < 0) stop = strlen + stop; if (start < 0) start = 0; if (stop < 0) stop = 0; - if (stop >= static_cast(strlen)) stop = strlen - 1; + if (stop >= strlen) stop = strlen - 1; /* Precondition: end >= 0 && end < strlen, so the only condition where * zero can be returned is: start > stop. */ @@ -90,13 +90,13 @@ rocksdb::Status BitmapString::BitCount(const std::string &raw_value, int64_t sta rocksdb::Status BitmapString::BitPos(const std::string &raw_value, bool bit, int64_t start, int64_t stop, bool stop_given, int64_t *pos) { auto string_value = raw_value.substr(STRING_HDR_SIZE, raw_value.size() - STRING_HDR_SIZE); - auto strlen = string_value.size(); + auto strlen = static_cast(string_value.size()); /* Convert negative indexes */ if (start < 0) start = strlen + start; if (stop < 0) stop = strlen + stop; if (start < 0) start = 0; if (stop < 0) stop = 0; - if (stop >= static_cast(strlen)) stop = strlen - 1; + if (stop >= strlen) stop = strlen - 1; if (start > stop) { *pos = -1; diff --git a/src/types/redis_geo.cc b/src/types/redis_geo.cc index 348178b0e99..d4c2740923e 100644 --- a/src/types/redis_geo.cc +++ b/src/types/redis_geo.cc @@ -104,7 +104,7 @@ rocksdb::Status Geo::Radius(const Slice &user_key, double longitude, double lati } if (!store_key.empty()) { - int64_t result_length = geo_points->size(); + auto result_length = static_cast(geo_points->size()); int64_t returned_items_count = (count == 0 || result_length < count) ? result_length : count; if (returned_items_count == 0) { ZSet::Del(user_key); @@ -195,7 +195,7 @@ std::string Geo::EncodeGeoHash(double longitude, double latitude) { * zero. */ idx = 0; } else { - idx = (hash.bits >> (52 - ((i + 1) * 5))) & 0x1f; + idx = static_cast((hash.bits >> (52 - ((i + 1) * 5))) & 0x1f); } geoHash += geoalphabet[idx]; } @@ -211,7 +211,8 @@ int Geo::decodeGeoHash(double bits, double *xy) { int Geo::membersOfAllNeighbors(const Slice &user_key, GeoHashRadius n, double lon, double lat, double radius, std::vector *geo_points) { GeoHashBits neighbors[9]; - unsigned int i = 0, count = 0, last_processed = 0; + unsigned int i = 0, last_processed = 0; + int count = 0; neighbors[0] = n.hash; neighbors[1] = n.neighbors.north; @@ -252,7 +253,7 @@ int Geo::membersOfGeoHashBox(const Slice &user_key, GeoHashBits hash, std::vecto GeoHashFix52Bits min = 0, max = 0; scoresOfGeoHashBox(hash, &min, &max); - return getPointsInRange(user_key, min, max, lon, lat, radius, geo_points); + return getPointsInRange(user_key, static_cast(min), static_cast(max), lon, lat, radius, geo_points); } /* Compute the sorted set scores min (inclusive), max (exclusive) we should diff --git a/src/types/redis_hash.cc b/src/types/redis_hash.cc index 86444a0bc7a..d7001b67cb5 100644 --- a/src/types/redis_hash.cc +++ b/src/types/redis_hash.cc @@ -113,7 +113,7 @@ rocksdb::Status Hash::IncrBy(const Slice &user_key, const Slice &field, int64_t rocksdb::Status Hash::IncrByFloat(const Slice &user_key, const Slice &field, double increment, double *ret) { bool exists = false; - float old_value = 0; + double old_value = 0; std::string ns_key; AppendNamespacePrefix(user_key, &ns_key); diff --git a/src/types/redis_list.cc b/src/types/redis_list.cc index 3d45419e69a..d049bfdab44 100644 --- a/src/types/redis_list.cc +++ b/src/types/redis_list.cc @@ -84,7 +84,7 @@ rocksdb::Status List::push(const Slice &user_key, const std::vector &elem metadata.size += elems.size(); metadata.Encode(&bytes); batch.Put(metadata_cf_handle_, ns_key, bytes); - *ret = metadata.size; + *ret = static_cast(metadata.size); return storage_->Write(storage_->DefaultWriteOptions(), &batch); } @@ -334,7 +334,7 @@ rocksdb::Status List::Insert(const Slice &user_key, const Slice &pivot, const Sl metadata.Encode(&bytes); batch.Put(metadata_cf_handle_, ns_key, bytes); - *ret = metadata.size; + *ret = static_cast(metadata.size); return storage_->Write(storage_->DefaultWriteOptions(), &batch); } @@ -347,7 +347,7 @@ rocksdb::Status List::Index(const Slice &user_key, int index, std::string *elem) rocksdb::Status s = GetMetadata(ns_key, &metadata); if (!s.ok()) return s; - if (index < 0) index += metadata.size; + if (index < 0) index += static_cast(metadata.size); if (index < 0 || index >= static_cast(metadata.size)) return rocksdb::Status::NotFound(); rocksdb::ReadOptions read_options; @@ -414,7 +414,7 @@ rocksdb::Status List::Set(const Slice &user_key, int index, Slice elem) { ListMetadata metadata(false); rocksdb::Status s = GetMetadata(ns_key, &metadata); if (!s.ok()) return s; - if (index < 0) index = metadata.size + index; + if (index < 0) index += static_cast(metadata.size); if (index < 0 || index >= static_cast(metadata.size)) { return rocksdb::Status::InvalidArgument("index out of range"); } @@ -597,8 +597,8 @@ rocksdb::Status List::Trim(const Slice &user_key, int start, int stop) { rocksdb::Status s = GetMetadata(ns_key, &metadata); if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s; - if (start < 0) start = metadata.size + start; - if (stop < 0) stop = static_cast(metadata.size) >= -1 * stop ? metadata.size + stop : -1; + if (start < 0) start += static_cast(metadata.size); + if (stop < 0) stop = static_cast(metadata.size) >= -1 * stop ? static_cast(metadata.size) + stop : -1; // the result will be empty list when start > stop, // or start is larger than the end of list if (start > stop) { diff --git a/src/types/redis_set.cc b/src/types/redis_set.cc index 363e380d79f..ffcb182c56a 100644 --- a/src/types/redis_set.cc +++ b/src/types/redis_set.cc @@ -129,7 +129,7 @@ rocksdb::Status Set::Card(const Slice &user_key, int *ret) { SetMetadata metadata(false); rocksdb::Status s = GetMetadata(ns_key, &metadata); if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s; - *ret = metadata.size; + *ret = static_cast(metadata.size); return rocksdb::Status::OK(); } diff --git a/src/types/redis_sortedint.cc b/src/types/redis_sortedint.cc index bd4d1031922..a79a1ac69ac 100644 --- a/src/types/redis_sortedint.cc +++ b/src/types/redis_sortedint.cc @@ -107,7 +107,7 @@ rocksdb::Status Sortedint::Card(const Slice &user_key, int *ret) { SortedintMetadata metadata(false); rocksdb::Status s = GetMetadata(ns_key, &metadata); if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s; - *ret = metadata.size; + *ret = static_cast(metadata.size); return rocksdb::Status::OK(); } diff --git a/src/types/redis_string.cc b/src/types/redis_string.cc index df665223c02..faa96fbb7b9 100644 --- a/src/types/redis_string.cc +++ b/src/types/redis_string.cc @@ -148,10 +148,10 @@ rocksdb::Status String::Get(const std::string &user_key, std::string *value) { } rocksdb::Status String::GetEx(const std::string &user_key, std::string *value, int ttl) { - uint32_t expire = 0; + int expire = 0; if (ttl > 0) { int64_t now = Util::GetTimeStamp(); - expire = uint32_t(now) + ttl; + expire = int(now) + ttl; } std::string ns_key; AppendNamespacePrefix(user_key, &ns_key); @@ -219,10 +219,10 @@ rocksdb::Status String::SetNX(const std::string &user_key, const std::string &va rocksdb::Status String::SetXX(const std::string &user_key, const std::string &value, int ttl, int *ret) { *ret = 0; int exists = 0; - uint32_t expire = 0; + int expire = 0; if (ttl > 0) { int64_t now = Util::GetTimeStamp(); - expire = uint32_t(now) + ttl; + expire = int(now) + ttl; } std::string ns_key; @@ -358,10 +358,10 @@ rocksdb::Status String::IncrByFloat(const std::string &user_key, double incremen } rocksdb::Status String::MSet(const std::vector &pairs, int ttl) { - uint32_t expire = 0; + int expire = 0; if (ttl > 0) { int64_t now = Util::GetTimeStamp(); - expire = uint32_t(now) + ttl; + expire = int(now) + ttl; } // Data race, key string maybe overwrite by other key while didn't lock the key here, @@ -388,10 +388,10 @@ rocksdb::Status String::MSet(const std::vector &pairs, int ttl) { rocksdb::Status String::MSetNX(const std::vector &pairs, int ttl, int *ret) { *ret = 0; - uint32_t expire = 0; + int expire = 0; if (ttl > 0) { int64_t now = Util::GetTimeStamp(); - expire = uint32_t(now) + ttl; + expire = int(now) + ttl; } int exists = 0; @@ -453,11 +453,11 @@ rocksdb::Status String::CAS(const std::string &user_key, const std::string &old_ if (old_value == current_value) { std::string raw_value; - uint32_t expire = 0; + int expire = 0; Metadata metadata(kRedisString, false); if (ttl > 0) { int64_t now = Util::GetTimeStamp(); - expire = uint32_t(now) + ttl; + expire = int(now) + ttl; } metadata.expire = expire; metadata.Encode(&raw_value); diff --git a/src/types/redis_zset.cc b/src/types/redis_zset.cc index cdaa72d6886..57aecd71ac0 100644 --- a/src/types/redis_zset.cc +++ b/src/types/redis_zset.cc @@ -142,7 +142,7 @@ rocksdb::Status ZSet::Card(const Slice &user_key, int *ret) { ZSetMetadata metadata(false); rocksdb::Status s = GetMetadata(ns_key, &metadata); if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s; - *ret = metadata.size; + *ret = static_cast(metadata.size); return rocksdb::Status::OK(); } @@ -172,7 +172,7 @@ rocksdb::Status ZSet::Pop(const Slice &user_key, int count, bool min, std::vecto rocksdb::Status s = GetMetadata(ns_key, &metadata); if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s; if (count <= 0) return rocksdb::Status::OK(); - if (count > static_cast(metadata.size)) count = metadata.size; + if (count > static_cast(metadata.size)) count = static_cast(metadata.size); std::string score_bytes; double score = min ? kMinScore : kMaxScore; @@ -237,8 +237,8 @@ rocksdb::Status ZSet::Range(const Slice &user_key, int start, int stop, uint8_t ZSetMetadata metadata(false); rocksdb::Status s = GetMetadata(ns_key, &metadata); if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s; - if (start < 0) start += metadata.size; - if (stop < 0) stop += metadata.size; + if (start < 0) start += static_cast(metadata.size); + if (stop < 0) stop += static_cast(metadata.size); if (start < 0) start = 0; if (stop < 0 || start > stop) { return rocksdb::Status::OK(); @@ -704,7 +704,7 @@ rocksdb::Status ZSet::InterStore(const Slice &dst, const std::vector if (member_counters[iter.first] != keys_weights.size()) continue; mscores.emplace_back(MemberScore{iter.first, iter.second}); } - if (size) *size = mscores.size(); + if (size) *size = static_cast(mscores.size()); Overwrite(dst, mscores); } @@ -754,7 +754,7 @@ rocksdb::Status ZSet::UnionStore(const Slice &dst, const std::vector for (const auto &iter : dst_zset) { mscores.emplace_back(MemberScore{iter.first, iter.second}); } - if (size) *size = mscores.size(); + if (size) *size = static_cast(mscores.size()); Overwrite(dst, mscores); }