-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: the error bugs in getrange and setrange in pika 3.5 version #3106
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
Merged
wangshao1
merged 2 commits into
OpenAtomFoundation:3.5
from
YuCai18:hotfix3.5/fix_getsetrange
Jun 13, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,10 +440,39 @@ Status PikaCache::Appendxx(std::string& key, std::string &value) { | |
| return Status::NotFound("key not exist"); | ||
| } | ||
|
|
||
| /* | ||
| Added boundary checks for start and end parameters to the PikaCache::GetRange function, | ||
| and used the full_value variable to store the actual length of string type, | ||
| avoiding excessive memory allocation by sdsnewlen. | ||
| */ | ||
| Status PikaCache::GetRange(std::string& key, int64_t start, int64_t end, std::string *value) { | ||
| int cache_index = CacheIndex(key); | ||
| std::lock_guard lm(*cache_mutexs_[cache_index]); | ||
| return caches_[cache_index]->GetRange(key, start, end, value); | ||
| std::string full_value; | ||
| auto s = caches_[cache_index]->Get(key, &full_value); | ||
| if (!s.ok()) { | ||
| return s; | ||
| } | ||
| int64_t strlen = full_value.size(); | ||
|
|
||
| if (start < 0) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redis官方的实现也支持传负值吗? |
||
| start = strlen + start; | ||
| } | ||
| if (end < 0) { | ||
| end = strlen + end; | ||
| } | ||
|
|
||
| if (start < 0) start = 0; | ||
| if (end < 0) end = 0; | ||
| if (end >= strlen) end = strlen - 1; | ||
|
|
||
| if (start > end || strlen == 0) { | ||
| value->clear(); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| *value = full_value.substr(start, end - start + 1); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| Status PikaCache::SetRangeIfKeyExist(std::string& key, int64_t start, std::string &value) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1215,6 +1215,17 @@ void SetrangeCmd::DoInitial() { | |
| return; | ||
| } | ||
| value_ = argv_[3]; | ||
| // Read the proto-max-bulk-len parameter settings in the pika configuration file pika_conf | ||
| const int64_t PROTO_MAX_BULK_LEN = g_pika_conf->proto_max_bulk_len(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 临时变量不要全大写 |
||
| //Handle the overflow issue of offset_ | ||
| if (offset_ < 0) { | ||
| res_.SetRes(CmdRes::kInvalidInt, "offset is out of range"); | ||
| return; | ||
| } | ||
| if (offset_ > PROTO_MAX_BULK_LEN - static_cast<int64_t>(value_.size())) { | ||
| res_.SetRes(CmdRes::kErrOther, "string exceeds maximum allowed size (proto-max-bulk-len)"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| void SetrangeCmd::Do() { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个参数我理解其实就是限制了string类型的value大小,是不是换个别的名字更好理解?