Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Fix LPOP to support multiple arguments #1100 #1105

Closed
wants to merge 0 commits into from

Conversation

tren03
Copy link
Contributor

@tren03 tren03 commented Oct 15, 2024

This pull request addresses issue #1100, where the LPOP command needed to support an additional argument to specify the number of elements to pop from the left side of the list.

Changes:
Modified the LPOP command to accept either 1 or 2 arguments:
LPOP key: Pops a single element from the list (default behavior).
LPOP key count: Pops up to count elements from the list.

Validation:
If count is 0, an empty response is returned.

If count is negative, an "out of range" error is returned.
If count exceeds the number of available elements, it pops as many elements as available without error.
Invalid count (non-integer values) returns an appropriate error.
Popping from a non-existent or empty list returns nil.

Behavior:
Returns a single element if one element is popped.
Returns a list of elements if multiple elements are popped.

This is the dicedb output
dice-output

This is the output for redis over the same commands
redis-output

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 the fix! It would be great to have unit and integration tests validating these changes.

@tren03
Copy link
Contributor Author

tren03 commented Oct 16, 2024

Thanks for the fix! It would be great to have unit and integration tests validating these changes.

Thanks :), Yep I am on it.

@tren03
Copy link
Contributor Author

tren03 commented Oct 16, 2024

this is the unit-tests
unittest

this is the integration tests
integrationtest

any changes to make?

@tren03
Copy link
Contributor Author

tren03 commented Oct 25, 2024

Hey,
Its been a while since I heard back.
I saw that there was a slight conflict with my branch, so i fixed it with a merge.
Would love to get some updates on this issue.

@tren03 tren03 requested a review from JyotinderSingh October 29, 2024 12:39
@JyotinderSingh
Copy link
Collaborator

Hey, Its been a while since I heard back. I saw that there was a slight conflict with my branch, so i fixed it with a merge. Would love to get some updates on this issue.

whoops, didn't realise the comments were addressed. Going through this PR.

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 these changes @tren03! The implementation in itself looks solid, have left a few minor comments.

@@ -120,6 +120,7 @@ func TestEval(t *testing.T) {
testEvalSINTER(t, store)
testEvalOBJECTENCODING(t, store)
testEvalJSONSTRAPPEND(t, store)
testEvalLPOP(t, store)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we are calling testEvalLPOP twice here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to add similar tests to HTTP and Websocket directory as well. As a part of this exercise it would be great if you could help verify that the rest of the tests in this file are also replicated there.

Copy link
Contributor Author

@tren03 tren03 Oct 29, 2024

Choose a reason for hiding this comment

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

Hey,
I was working on porting the tests to http and websockets directory.
I noticed that the http server returns a float for LPUSH, where as localhost operation returns an integer.
Is this expected behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, I was working on porting the tests to http and websockets directory. I noticed that the http server returns a float for LPUSH, where as localhost operation returns an integer. Is this expected behaviour?
2024-10-30-132701_1166x219_scrot

Copy link
Contributor Author

@tren03 tren03 Nov 1, 2024

Choose a reason for hiding this comment

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

I did a mistake, in merging the branches,
This is my first so a bit nervous
I still have all the needed changes,

I have made another PR #1231 to continue the issue
Sorry for the inconvenience.

@tren03 tren03 closed this Nov 1, 2024
@tren03 tren03 force-pushed the lpop-multiple-args-fix-1100 branch from 5c75e85 to d9c41f2 Compare November 1, 2024 14:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants