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

#640: Add BITFIELD_RO command #956

Conversation

iamskp11
Copy link
Contributor

@iamskp11 iamskp11 commented Oct 5, 2024

This PR closes #640 - BITFIELD_RO command.

  1. Integration tests
image
  1. Unit tests
image

@iamskp11
Copy link
Contributor Author

iamskp11 commented Oct 5, 2024

Hey @JyotinderSingh @lucifercr07 @apoorvyadav1111 , please review this PR for adding BITFIELD_RO command.
Thanks

@apoorvyadav1111
Copy link
Contributor

Hi @iamskp11 , Thanks for the changes. I have some suggestions regarding refactoring the code for both evals to ensure consistency in any future modifications in one. I ll be reviewing the code thoroughly in the morning and comment the suggestions, if you would consider them.
Thanks

@iamskp11
Copy link
Contributor Author

iamskp11 commented Oct 5, 2024

Hi @iamskp11 , Thanks for the changes. I have some suggestions regarding refactoring the code for both evals to ensure consistency in any future modifications in one. I ll be reviewing the code thoroughly in the morning and comment the suggestions, if you would consider them. Thanks

Sure @apoorvyadav1111 .
Also, I went through Redis implementation for BITFIELD and BITFIELD_RO, and they have simply used a flag, to differentiate between the two. I was thinking maybe we can also do similar.

@apoorvyadav1111
Copy link
Contributor

Yes I had similar in mind. Although we can have two functions; one to parse ops and another to run ops. The one which parses ops need the flag. The one which runs it will not will execute the ops irrespective of the type of command .

@iamskp11
Copy link
Contributor Author

iamskp11 commented Oct 5, 2024

Yes I had similar in mind. Although we can have two functions; one to parse ops and another to run ops. The one which parses ops need the flag. The one which runs it will not will execute the ops irrespective of the type of command .

Didn't get this @apoorvyadav1111 . I think parsing ops function should not worry about command/flag. Let that parse the ops, and if we get update/set commands, we can throw error if it is with RO flag.

@iamskp11
Copy link
Contributor Author

iamskp11 commented Oct 7, 2024

Hey @apoorvyadav1111 @JyotinderSingh @lucifercr07 , can you have a look at #994 , and review it. It uses a generic method for BITFIELD and BITFIELD_RO commands, with a flag for allowing only GET subcommand.

@apoorvyadav1111
Copy link
Contributor

Hi @iamskp11 , the idea is to change the current bitfield and bitfield_ro commands into :

  1. parseOps(args, isReadOnly) (ops BitFieldOp[], err) : function returns ops array or error if parseing failed.
  2. executeOps(ops): function runs the operations and internally returns the result or error.

With these changes, pseudocode for bitfield would be:

ops:= parseOps(args, false)
return executeOps(ops)

and bitfield_ro would be:

ops:= parseOps(args, true)
return executeOps(ops)

You can make changes according to when you refactor them. The idea is to reuse the logic in bitfield.
If need be, I can make code suggestions in the review as well.

Apoorv

Copy link
Contributor

@apoorvyadav1111 apoorvyadav1111 left a comment

Choose a reason for hiding this comment

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

Hi, let's improve the bitfield and bitfield_ro as discussed. We can connect over discord to discuss more.

@iamskp11
Copy link
Contributor Author

iamskp11 commented Oct 7, 2024

@apoorvyadav1111 , thats great. Now, I got your idea. Will share the PR soon. Thanks a lot!

@apoorvyadav1111
Copy link
Contributor

apoorvyadav1111 commented Oct 7, 2024

Hi @iamskp11 , let me take a look at 994 before you create another PR. I just glanced it and it might work as well. I just want to ensure efforts are not wasted if 994 looks good

@iamskp11 iamskp11 marked this pull request as draft October 7, 2024 16:02
@iamskp11 iamskp11 marked this pull request as ready for review October 8, 2024 15:03
@iamskp11
Copy link
Contributor Author

iamskp11 commented Oct 8, 2024

Hey @apoorvyadav1111 , have done the changes as per your suggestion. Integration and unit tests work fine for both BITFIELD and BITFIELD_RO. Please review.
Requesting @JyotinderSingh @lucifercr07 to have a look and review.

Copy link
Contributor

@apoorvyadav1111 apoorvyadav1111 left a comment

Choose a reason for hiding this comment

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

Hi, the code looks good to me and is what I had in mind. Regarding moving parsing functions to utils, I am not sure. Maybe @JyotinderSingh can share his views on this. In any case, it should be a small change even if we move the code back to eval.go.

Thanks for taking up my suggestion.
Apoorv

internal/server/utils/bitfield.go Outdated Show resolved Hide resolved
internal/eval/eval.go Outdated Show resolved Hide resolved
internal/eval/eval.go Outdated Show resolved Hide resolved
internal/eval/eval.go Outdated Show resolved Hide resolved
@iamskp11
Copy link
Contributor Author

Have done the function name changes , @JyotinderSingh . PR is now ready for review

@apoorvyadav1111
Copy link
Contributor

Hi @iamskp11 , Please respond and resolve the review comments from @JyotinderSingh .

@iamskp11
Copy link
Contributor Author

iamskp11 commented Oct 12, 2024

Hi @iamskp11 , Please respond and resolve the review comments from @JyotinderSingh .

Hi @apoorvyadav1111 , have done that in my previous commit. It's ready for review. b4601ac
Responded to all review comments and closed all except one.

@JyotinderSingh JyotinderSingh changed the title Add BITFIELD_RO command #640: Add BITFIELD_RO command Oct 13, 2024
@JyotinderSingh JyotinderSingh merged commit 76e571c into DiceDB:master Oct 13, 2024
2 checks passed
kakdeykaushik pushed a commit to kakdeykaushik/dice that referenced this pull request Oct 19, 2024
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 BITFIELD_RO
3 participants