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

feat: adding list API continued #18

Merged
merged 4 commits into from
Oct 17, 2022
Merged

feat: adding list API continued #18

merged 4 commits into from
Oct 17, 2022

Conversation

pgautier404
Copy link
Collaborator

Adds the remaining list API operations: pop front, pop back, length, and erase. Also adds __toString() in the response base class and overrides the base implementation in the response subtypes that hold data.

Comment on lines +255 to +256
validateCacheName($cacheName);
validateListName($listName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we want to catch InvalidArgumentError for those?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We already do! It's an SdkError subclass which is handled in the first catch below.

validateRange($beginIndex, $count);
$listEraseRequest = new _ListEraseRequest();
$listEraseRequest->setListName($listName);
if (!is_null($beginIndex) && !is_null($count)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this if we are already checking with validateRange?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see. Those are optional, and if they're null, delete all the items.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. This is not a validation of the data. If these values are both supplied we need to erase a range of items and if neither value is supplied we need to erase the entire list. The validation makes sure that one or the other of those is true.

Copy link
Collaborator

@malandis malandis left a comment

Choose a reason for hiding this comment

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

One question and a couple small questions. Looks great!


if (!function_exists('validateRange'))
{
function validateRange(?int $beginIndex, ?int $count)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to prevent users from passing count value larger than the actual size of the list??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Validating that would require us to make a call to get the length of the list, and we don't want to make a round trip to the cache server for client side validation in my opinion. A number larger than the size of the list just deletes the rest of the list from the offset without complaining, so that round trip wouldn't buy us anything anyway. If you strongly disagree (or anyone else reading this disagrees) let me know and we can talk about it.

That's a good thing to add to the tests in case the behavior ever changes . . . I'll do that.

Copy link
Contributor

@poppoerika poppoerika Oct 17, 2022

Choose a reason for hiding this comment

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

As I wrote this question, I was thinking the same thing about calling another API to get length will add latency so that's probably not something we want to do.
But I didn't know the behavior you explained when a number larger than the size of the list is passed, and I think it makes sense. and thank you for the explanation!

@@ -290,6 +314,10 @@ public function value() : string
return $this->value;
}

public function __toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this PHP convention? i.e. Are PHP developers expected to echo cacheGetResponseHit object?
Sorry I misunderstand how __toString() works, but I didn't see any method like this in .NET SDK.

Copy link
Collaborator Author

@pgautier404 pgautier404 Oct 17, 2022

Choose a reason for hiding this comment

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

These are the PHP convention equivalent to the ToString() methods in .NET. I added one to each of the non-incubating SDK response types in momentohq/client-sdk-dotnet#252. Your comment does raise the issue that these are not implemented in our incubating response types . . . I'll add a ticket for that on the .NET repo.

$this->assertEquals(array_slice($values, 2), $response->asHit()->values());
}

public function testListEraseRange_LargeCountValue()
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding this test!

poppoerika
poppoerika previously approved these changes Oct 17, 2022
Copy link
Contributor

@poppoerika poppoerika left a comment

Choose a reason for hiding this comment

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

Looks good to me!

$this->assertEquals(4, $response->asSuccess()->length());

$response = $this->client->listErase($this->TEST_CACHE_NAME, $listName);
$this->assertNotEmpty($response->asSuccess());
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also assertNotNull??

Copy link
Collaborator

@malandis malandis left a comment

Choose a reason for hiding this comment

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

🥇

@pgautier404 pgautier404 merged commit c005907 into main Oct 17, 2022
@malandis malandis deleted the add-list-api-continued branch November 1, 2024 21:18
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.

3 participants