-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Added support for JSON.DEBUG #579
Conversation
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.
Thanks for adding support for JSON.DEBUG
command, @psrvere! The changes look good overall.
I've left a few comments.
internal/eval/eval.go
Outdated
reg := regexp.MustCompile(`^\$(\.|)\[(\d+|\*)\]`) | ||
matches := reg.FindStringSubmatch(path) | ||
|
||
if len(matches) == 3 { | ||
index, err := strconv.Atoi(matches[2]) | ||
if err != nil { | ||
return diceerrors.NewErrWithMessage("unable to extract index") | ||
} | ||
if index >= len(arr) { | ||
return clientio.RespEmptyArray | ||
} | ||
} | ||
} |
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.
Can you help me understand what's happening here? Maybe add a few comments here too.
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.
Also, we should avoid using regex in general since it is slow to compile and evaluate. However, if there is no better way, we can live with it.
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.
@JyotinderSingh - this handles an edge case where memory is requested for out of bound index in an array json. Without this bit of code, program would return an error Err Path '$.[4]' does not exist
for an array of length 3. Redis returns an empty array.
So this bit of code matches if arg is $[4] type, extracts the value 4 and compares it with array length to handle this case.
I will add comments here.
Please fix the linter warnings too. |
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.
Thanks for addressing the reviews. LGTM.
Fixes #491 #492 #493
@lucifercr07 @JyotinderSingh - please review.