-
Notifications
You must be signed in to change notification settings - Fork 468
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
Support for the JSON.ARRPOP command #1874
Conversation
src/types/json.h
Outdated
auto popped_iter = val.array_range().begin(); | ||
if (index == -1 || index >= static_cast<int64_t>(val.size())) { | ||
popped_iter = val.array_range().end() - 1; | ||
} else if (index > 0) { | ||
popped_iter += index; | ||
} |
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.
I think if the index is negative, we need to calculate the real position from the end.
127.0.0.1:6666> json.set a $ [1,2,3,4]
OK
127.0.0.1:6666> json.arrpop a $ -2
1) "3"
127.0.0.1:6666>
I recommend you to try it by yourself : )
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.
I'm sorry I misunderstood Out-of-range indexes round to their respective array ends
stated in the doc.
I've fixed it based on the below code in RedisJson.
impl ArrayIndex for i64 {
fn normalize(self, len: i64) -> usize {
let index = if self < 0 {
len - len.min(-self)
} else if len > 0 {
(len - 1).min(self)
} else {
0
};
index as usize
}
}
Could you try to fix these issue reported by clang-tidy in CI? https://github.com/apache/kvrocks/actions/runs/6754872818/job/18363385655?pr=1874 |
Fixed. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Thank you for your contribution! |
This PR adds support for the JSON.ARRPOP command.
closes #1810.