Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: not call GetCurrentTime when possible #709

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/redis_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,14 @@ RedisType Metadata::Type() const {

int32_t Metadata::TTL() const {
int64_t now;
if (expire <= 0) {
return -1;
}
PragmaTwice marked this conversation as resolved.
Show resolved Hide resolved
rocksdb::Env::Default()->GetCurrentTime(&now);
if (expire != 0 && expire < now) {
if (expire < now) {
return -2;
}
return expire <= 0 ? -1 : int32_t (expire - now);
return int32_t (expire - now);
}

timeval Metadata::Time() const {
Expand All @@ -246,12 +249,15 @@ timeval Metadata::Time() const {
}

bool Metadata::Expired() const {
int64_t now;
rocksdb::Env::Default()->GetCurrentTime(&now);
if (expire > 0 && expire < now) {
if (Type() != kRedisString && size == 0) {
return true;
}
return Type() != kRedisString && size == 0;
if (expire <= 0) {
return false;
}
int64_t now;
rocksdb::Env::Default()->GetCurrentTime(&now);
return expire < now;
}

ListMetadata::ListMetadata(bool generate_version) : Metadata(kRedisList, generate_version) {
Expand Down Expand Up @@ -279,5 +285,5 @@ rocksdb::Status ListMetadata::Decode(const std::string &bytes) {
GetFixed64(&input, &head);
GetFixed64(&input, &tail);
}
return rocksdb::Status();
return rocksdb::Status::OK();
}