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

Added support for GET in SET command #246

Closed
wants to merge 7 commits into from
Closed

Added support for GET in SET command #246

wants to merge 7 commits into from

Conversation

yaten2302
Copy link

Fixes #207

This PR adds a support for the GET command in the SET command as in redis - https://redis.io/docs/latest/commands/set/

@yaten2302 yaten2302 marked this pull request as ready for review August 6, 2024 18:07
Copy link
Contributor

@soumya-codes soumya-codes left a comment

Choose a reason for hiding this comment

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

Left a couple of comments. Please check.

@@ -187,6 +187,19 @@ func evalSET(args []string) []byte {
if obj != nil {
return RESP_NIL
}
case "GET":
obj := Get(key)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just call evalGET() method before the value has been updated and return the o/p of evalGET() as is. wdyt?

Copy link
Author

Choose a reason for hiding this comment

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

Okay, so, like, I've to use evalGET() function instead of Get(), am I right?

Copy link
Author

Choose a reason for hiding this comment

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

@soumya-codes , I've a doubt, that since by using the evalGET function, we need to pass an array

image

So, first, we've to push the key to an array and then pass it to the evalGET func, which will increase the fetching time, so can we just let it be Get() only? because in other cases also, the Get() function is only used!
What say?

tests/set_test.go Show resolved Hide resolved
tempObj := obj

if obj == nil {
return RESP_NIL
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it is better to just update the response here. Let us invoke PUT at just one place.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1. We don't have to call PUT in 2 places. Passing GET will just change the return value of the SET command.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, actually, previously I did by using Put in the end only, but there was a review from someone which mentioned that the value won't get updated if I didn't add Put at 2 places, this comment.

NVM, I'll make the changes 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need to add Put in two places but you will need a variable for a response and then you can return that in the end if it was of subtype GET instead of RESP_OK. If you just return it from here only then PUT never gets called and SET command doesn't execute. That is what I meant

Copy link
Author

Choose a reason for hiding this comment

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

Hey! srivastav-yash, apologies for the miscommunication. Now I have got your point. But, actually, before doing that, I'm first trying to fix the issue with XX and NX options. If we're giving both xx and get, then the tests are failing.

@@ -187,6 +187,19 @@ func evalSET(args []string) []byte {
if obj != nil {
return RESP_NIL
}
case "GET":
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are adding GET, we cannot now blindly return from XX and NX.

Copy link
Author

Choose a reason for hiding this comment

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

Actually, I'm not able to get it completely, could you please elaborate more on this

Copy link
Author

Choose a reason for hiding this comment

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

Hey @soumya-codes , I was just now running the tests with the XX option with the GET one. The test is failing. I think do we need to change the complete evalSET() func? I'm thinking of an approach for this, will update soon about it here 👍

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 GET in SET command
4 participants