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

#500: Added JSON.RESP Command #751

Merged
merged 9 commits into from
Sep 30, 2024

Conversation

psrvere
Copy link
Contributor

@psrvere psrvere commented Sep 27, 2024

Old PR - #631 (closed)

This PR fixes #500

The PR

  • Adds support for JSON.RESP command
  • Adds unit and integrations test for the same
  • Modifies resp.go to support boolean and integer encoding, and adds unit tests for the same
  • Adds a utility helper IsFloatToIntPossible

@psrvere psrvere marked this pull request as ready for review September 27, 2024 09:27
@psrvere
Copy link
Contributor Author

psrvere commented Sep 27, 2024

@JyotinderSingh - Please review this PR.

I closed the old PR due to some issues I was facing merging with master. You had left 4 comments there. 3 of them are addressed in 3 commits above. 1 was a question on type switch for which I have left a comment there.

Copy link
Collaborator

@JyotinderSingh JyotinderSingh left a 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 the JSON.RESP command, @psrvere! The changes mostly look good, had a few comments.

internal/clientio/resp.go Outdated Show resolved Hide resolved
internal/clientio/resp.go Outdated Show resolved Hide resolved
Comment on lines +181 to +188
intValue, isInteger := utils.IsFloatToIntPossible(v.(float64))
if isInteger {
return []byte(fmt.Sprintf(":%d\r\n", intValue))
}

// if it is a float, encode like a string
str := strconv.FormatFloat(v.(float64), 'f', -1, 64)
return encodeString(str)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this modified logic doesn't end up messing up cases where someone stores a whole number in floating point representation? Something like 5.0? How does redis behave in such cases?

Copy link
Contributor Author

@psrvere psrvere Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A whole number in floating point representation is shown as string in Redis and Dice master branch.

On Dice master branch:

set a 1
OK
get a
(integer) 1
set a 1.34
OK
get a
"1.34"
set a 1.00
OK
get a
"1.00"

The behaviour of JSONResp feature branch is identical as master branch for above cases.

On Redis:

set a 1
OK
get a
"1" ---- Integers are also encoded as strings in Redis (different behaviour)
set a 1.34
OK
get a
"1.34"
set a 1.00
OK
get a
"1.00"

I am also working on #69. Let me take up integer difference there.

I did run all unit tests for eval_test.go and all integration tests and they all passed.

internal/eval/eval.go Show resolved Hide resolved
@JyotinderSingh
Copy link
Collaborator

Please resolve conflicts.

@psrvere
Copy link
Contributor Author

psrvere commented Sep 30, 2024

@JyotinderSingh - addressed all comments. Please review.

Copy link
Collaborator

@JyotinderSingh JyotinderSingh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing the reviews. LGTM.

@JyotinderSingh JyotinderSingh changed the title Added JSON.RESP Command #500: Added JSON.RESP Command Sep 30, 2024
@JyotinderSingh JyotinderSingh merged commit 4542766 into DiceDB:master Sep 30, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for command JSON.RESP
2 participants