Skip to content

Commit 0cdad27

Browse files
committed
Fix Type Command Expired Key Consistency
1 parent 1b0990e commit 0cdad27

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/storage/src/redis_strings.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,14 @@ rocksdb::Status Redis::GetType(const storage::Slice& key, enum DataType& type) {
16711671
BaseMetaKey base_meta_key(key);
16721672
rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value);
16731673
if (s.ok()) {
1674-
type = static_cast<enum DataType>(static_cast<uint8_t>(meta_value[0]));
1674+
// 检查键是否已过期
1675+
if (ExpectedStale(meta_value)) {
1676+
type = DataType::kNones; // 如果键已过期,返回"none"类型
1677+
} else {
1678+
type = static_cast<enum DataType>(static_cast<uint8_t>(meta_value[0]));
1679+
}
1680+
} else {
1681+
type = DataType::kNones; // 如果键不存在,返回"none"类型
16751682
}
16761683
return Status::OK();
16771684
}

src/storage/src/storage.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,16 @@ Status Storage::GetType(const std::string& key, enum DataType& type) {
15141514
return Status::OK();
15151515
}
15161516

1517+
Status Storage::Type(const std::string& key, std::vector<std::string>& types) {
1518+
types.clear();
1519+
DataType type;
1520+
Status s = GetType(key, type);
1521+
if (s.ok()) {
1522+
types.push_back(DataTypeToString(type));
1523+
}
1524+
return s;
1525+
}
1526+
15171527
Status Storage::Keys(const DataType& data_type, const std::string& pattern, std::vector<std::string>* keys) {
15181528
keys->clear();
15191529
std::vector<DataType> types;

0 commit comments

Comments
 (0)