From 97c2754734b34b1f9aca1657a6a3aaed7dbebf19 Mon Sep 17 00:00:00 2001 From: YuCai18 <1512875381@qq.com> Date: Tue, 22 Jul 2025 09:46:56 +0800 Subject: [PATCH] fix SETEX replication does not work --- src/pika_kv.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pika_kv.cc b/src/pika_kv.cc index 4c9c459184..35f4d49ffc 100644 --- a/src/pika_kv.cc +++ b/src/pika_kv.cc @@ -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(::time(nullptr)) + ttl_sec_; pstd::ll2string(buf, 100, time_stamp); std::string at(buf); RedisAppendLenUint64(content, at.size(), "$"); @@ -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(), "$"); @@ -1770,7 +1771,9 @@ void PKSetexAtCmd::DoInitial() { } void PKSetexAtCmd::Do() { - s_ = db_->storage()->PKSetexAt(key_, value_, static_cast(time_stamp_sec_ * 1000)); + // Use int64_t to avoid overflow + int64_t time_stamp_ms = static_cast(time_stamp_sec_) * 1000; + s_ = db_->storage()->PKSetexAt(key_, value_, time_stamp_ms); if (s_.ok()) { res_.SetRes(CmdRes::kOk); } else if (s_.IsInvalidArgument()) {