Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 2096: The setrange and setbit commands do not retain the expiration time of the original key #2095

Merged
merged 2 commits into from
Nov 4, 2023
Merged
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
6 changes: 6 additions & 0 deletions src/storage/src/redis_strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,12 @@ Status RedisStrings::SetBit(const Slice& key, int64_t offset, int32_t on, int32_
Status s = db_->Get(default_read_options_, key, &meta_value);
if (s.ok() || s.IsNotFound()) {
std::string data_value;
int32_t timestamp = 0;
dingxiaoshuai123 marked this conversation as resolved.
Show resolved Hide resolved
if (s.ok()) {
ParsedStringsValue parsed_strings_value(&meta_value);
if (!parsed_strings_value.IsStale()) {
data_value = parsed_strings_value.value().ToString();
timestamp = parsed_strings_value.timestamp();
}
}
size_t byte = offset >> 3;
Expand All @@ -686,6 +688,7 @@ Status RedisStrings::SetBit(const Slice& key, int64_t offset, int32_t on, int32_
data_value.append(1, byte_val);
}
StringsValue strings_value(data_value);
strings_value.set_timestamp(timestamp);
return db_->Put(rocksdb::WriteOptions(), key, strings_value.Encode());
} else {
return s;
Expand Down Expand Up @@ -802,13 +805,15 @@ Status RedisStrings::Setrange(const Slice& key, int64_t start_offset, const Slic
ScopeRecordLock l(lock_mgr_, key);
Status s = db_->Get(default_read_options_, key, &old_value);
if (s.ok()) {
int32_t timestamp = 0;
ParsedStringsValue parsed_strings_value(&old_value);
parsed_strings_value.StripSuffix();
if (parsed_strings_value.IsStale()) {
std::string tmp(start_offset, '\0');
new_value = tmp.append(value.data());
*ret = static_cast<int32_t>(new_value.length());
} else {
timestamp = parsed_strings_value.timestamp();
if (static_cast<size_t>(start_offset) > old_value.length()) {
old_value.resize(start_offset);
new_value = old_value.append(value.data());
Expand All @@ -823,6 +828,7 @@ Status RedisStrings::Setrange(const Slice& key, int64_t start_offset, const Slic
}
*ret = static_cast<int32_t>(new_value.length());
StringsValue strings_value(new_value);
strings_value.set_timestamp(timestamp);
return db_->Put(default_write_options_, key, strings_value.Encode());
} else if (s.IsNotFound()) {
std::string tmp(start_offset, '\0');
Expand Down
Loading