Skip to content
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
9 changes: 6 additions & 3 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ std::string SetexCmd::ToRedisProtocol() {
RedisAppendContent(content, key_);
// time_stamp
char buf[100];
auto time_stamp = time(nullptr) + ttl_sec_;
int64_t time_stamp = static_cast<int64_t>(::time(nullptr)) + ttl_sec_;
pstd::ll2string(buf, 100, time_stamp);
std::string at(buf);
RedisAppendLenUint64(content, at.size(), "$");
Expand Down Expand Up @@ -945,8 +945,9 @@ std::string PsetexCmd::ToRedisProtocol() {
RedisAppendLenUint64(content, key_.size(), "$");
RedisAppendContent(content, key_);
// time_stamp
int64_t expire_at_ms = pstd::NowMillis() + ttl_millsec;
int64_t time_stamp = expire_at_ms / 1000;
char buf[100];
auto time_stamp = pstd::NowMillis() + ttl_millsec;
pstd::ll2string(buf, 100, time_stamp);
std::string at(buf);
RedisAppendLenUint64(content, at.size(), "$");
Expand Down Expand Up @@ -1770,7 +1771,9 @@ void PKSetexAtCmd::DoInitial() {
}

void PKSetexAtCmd::Do() {
s_ = db_->storage()->PKSetexAt(key_, value_, static_cast<int32_t>(time_stamp_sec_ * 1000));
// Use int64_t to avoid overflow
int64_t time_stamp_ms = static_cast<int64_t>(time_stamp_sec_) * 1000;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 time_stamp_sec 已经是 int64_t 了,为啥还需要转一下

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的已经是int64_t了,保留static_cast<int64_t>是为了和源代码对齐

s_ = db_->storage()->PKSetexAt(key_, value_, time_stamp_ms);
if (s_.ok()) {
res_.SetRes(CmdRes::kOk);
} else if (s_.IsInvalidArgument()) {
Expand Down
Loading