@@ -897,7 +897,7 @@ std::string SetexCmd::ToRedisProtocol() {
897897 RedisAppendContent (content, key_);
898898 // time_stamp
899899 char buf[100 ];
900- auto time_stamp = time (nullptr ) + ttl_sec_;
900+ int64_t time_stamp = static_cast < int64_t >(:: time (nullptr ) ) + ttl_sec_;
901901 pstd::ll2string (buf, 100 , time_stamp);
902902 std::string at (buf);
903903 RedisAppendLenUint64 (content, at.size (), " $" );
@@ -955,8 +955,9 @@ std::string PsetexCmd::ToRedisProtocol() {
955955 RedisAppendLenUint64 (content, key_.size (), " $" );
956956 RedisAppendContent (content, key_);
957957 // time_stamp
958+ int64_t expire_at_ms = pstd::NowMillis () + ttl_millsec;
959+ int64_t time_stamp = expire_at_ms / 1000 ;
958960 char buf[100 ];
959- auto time_stamp = pstd::NowMillis () + ttl_millsec;
960961 pstd::ll2string (buf, 100 , time_stamp);
961962 std::string at (buf);
962963 RedisAppendLenUint64 (content, at.size (), " $" );
@@ -1805,7 +1806,9 @@ void PKSetexAtCmd::DoInitial() {
18051806}
18061807
18071808void PKSetexAtCmd::Do () {
1808- s_ = db_->storage ()->PKSetexAt (key_, value_, static_cast <int32_t >(time_stamp_sec_ * 1000 ));
1809+ // Use int64_t to avoid overflow
1810+ int64_t time_stamp_ms = static_cast <int64_t >(time_stamp_sec_) * 1000 ;
1811+ s_ = db_->storage ()->PKSetexAt (key_, value_, time_stamp_ms);
18091812 if (s_.ok ()) {
18101813 res_.SetRes (CmdRes::kOk );
18111814 } else if (s_.IsInvalidArgument ()) {
0 commit comments