Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 8 additions & 1 deletion src/storage/src/redis_strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,14 @@ rocksdb::Status Redis::GetType(const storage::Slice& key, enum DataType& type) {
BaseMetaKey base_meta_key(key);
rocksdb::Status s = db_->Get(default_read_options_, handles_[kMetaCF], base_meta_key.Encode(), &meta_value);
if (s.ok()) {
type = static_cast<enum DataType>(static_cast<uint8_t>(meta_value[0]));
// 检查键是否已过期
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.

注释修改成英文

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.

done

if (ExpectedStale(meta_value)) {
type = DataType::kNones; // 如果键已过期,返回"none"类型
} else {
type = static_cast<enum DataType>(static_cast<uint8_t>(meta_value[0]));
}
} else {
type = DataType::kNones; // 如果键不存在,返回"none"类型
}
return Status::OK();
}
Expand Down
10 changes: 10 additions & 0 deletions src/storage/src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,16 @@ Status Storage::GetType(const std::string& key, enum DataType& type) {
return Status::OK();
}

Status Storage::Type(const std::string& key, std::vector<std::string>& types) {
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.

这里为什么要新增加一个Type,不可以直接用之前的GetType接口吗

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.

因为 rocksdb::Status Type() 这个接口在头文件里一直存在,并且已经被大量外部模块(如 pika_migrate、pika_cache、rsync_client 等)调用,它返回的是 Redis 协议要求的字符串类型(如 “string” / “hash”),而旧的 GetType()函数 只返回内部枚举 DataType。

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.

防御性编程,先删去了。

types.clear();
DataType type;
Status s = GetType(key, type);
if (s.ok()) {
types.push_back(DataTypeToString(type));
}
return s;
}

Status Storage::Keys(const DataType& data_type, const std::string& pattern, std::vector<std::string>* keys) {
keys->clear();
std::vector<DataType> types;
Expand Down
Loading