Skip to content

Commit

Permalink
Don't call GetCurrentTime in expired and type when possible (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU authored Jul 5, 2022
1 parent e86411a commit ddcd7ea
Showing 1 changed file with 13 additions and 7 deletions.
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;
}
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();
}

0 comments on commit ddcd7ea

Please sign in to comment.