Skip to content

Commit 4d63b1b

Browse files
authored
Signed-off-by: Hao Lee <1838249551@qq.com>
1 parent f0d1760 commit 4d63b1b

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/storage/src/base_value_format.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "rocksdb/env.h"
1212
#include "rocksdb/slice.h"
1313
#include "src/coding.h"
14+
#include "src/redis.h"
1415

1516
namespace storage {
1617

@@ -24,10 +25,14 @@ class InternalValue {
2425
}
2526
}
2627
void set_timestamp(int32_t timestamp = 0) { timestamp_ = timestamp; }
27-
void SetRelativeTimestamp(int32_t ttl) {
28+
Status SetRelativeTimestamp(int32_t ttl) {
2829
int64_t unix_time;
2930
rocksdb::Env::Default()->GetCurrentTime(&unix_time);
3031
timestamp_ = static_cast<int32_t>(unix_time) + ttl;
32+
if (timestamp_ != unix_time + static_cast<int64_t>(ttl)) {
33+
return Status::InvalidArgument("invalid expire time");
34+
}
35+
return Status::OK();
3136
}
3237
void set_version(int32_t version = 0) { version_ = version; }
3338
static const size_t kDefaultValueSuffixLength = sizeof(int32_t) * 2;

src/storage/src/redis_strings.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,10 @@ Status RedisStrings::Setex(const Slice& key, const Slice& value, int32_t ttl) {
690690
return Status::InvalidArgument("invalid expire time");
691691
}
692692
StringsValue strings_value(value);
693-
strings_value.SetRelativeTimestamp(ttl);
693+
auto s = strings_value.SetRelativeTimestamp(ttl);
694+
if (s != Status::OK()) {
695+
return s;
696+
}
694697
ScopeRecordLock l(lock_mgr_, key);
695698
return db_->Put(default_write_options_, key, strings_value.Encode());
696699
}

0 commit comments

Comments
 (0)