Skip to content

Commit

Permalink
feat: implement sortedSetRemoveElement (#267)
Browse files Browse the repository at this point in the history
This implementation delegates to `sortedSetRemoveElements`.
  • Loading branch information
malandis authored and cprice404 committed Mar 14, 2023
1 parent ec8b864 commit 01c9adf
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 47 deletions.
19 changes: 19 additions & 0 deletions momento/cache_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,25 @@ func (c defaultScsClient) SortedSetGetScores(ctx context.Context, r *SortedSetGe
return r.response, nil
}

func (c defaultScsClient) SortedSetRemoveElement(ctx context.Context, r *SortedSetRemoveElementRequest) (responses.SortedSetRemoveElementResponse, error) {
if r.Value == nil {
return nil, convertMomentoSvcErrorToCustomerError(
momentoerrors.NewMomentoSvcErr(
momentoerrors.InvalidArgumentError, "value cannot be nil", nil,
),
)
}
newRequest := &SortedSetRemoveElementsRequest{
CacheName: r.CacheName,
SetName: r.SetName,
Values: []Value{r.Value},
}
if err := c.dataClient.makeRequest(ctx, newRequest); err != nil {
return nil, err
}
return &responses.SortedSetRemoveElementSuccess{}, nil
}

func (c defaultScsClient) SortedSetRemoveElements(ctx context.Context, r *SortedSetRemoveElementsRequest) (responses.SortedSetRemoveElementsResponse, error) {
if err := c.dataClient.makeRequest(ctx, r); err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions momento/sorted_set_remove_element.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package momento

type SortedSetRemoveElementRequest struct {
CacheName string
SetName string
Value Value
}
2 changes: 1 addition & 1 deletion momento/sorted_set_remove_elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ func (r *SortedSetRemoveElementsRequest) makeGrpcRequest(metadata context.Contex
}

func (r *SortedSetRemoveElementsRequest) interpretGrpcResponse() error {
r.response = &responses.SortedSetRemoveSuccess{}
r.response = &responses.SortedSetRemoveElementsSuccess{}
return nil
}
42 changes: 5 additions & 37 deletions momento/sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,45 +722,13 @@ var _ = Describe("SortedSet", func() {
})
})

Describe(`SortedSetPutElement`, func() {
// TODO
/*
It(`Puts an element with a string value`, func() {
resp, err := sharedContext.Client.SortedSetPutElement(
sharedContext.Ctx,
&SortedSetPutElementRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("aValue"),
Score: 42,
})
Expect(err).To(BeNil())
Expect(resp).To(BeAssignableToTypeOf(&SortedSetPutElementSuccess{}))
fetchResp, fetchErr := sharedContext.Client.SortedSetFetch(
sharedContext.Ctx,
&SortedSetFetchRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
},
)
Expect(fetchErr).To(BeNil())
switch fetchResp := fetchResp.(type) {
case *SortedSetFetchHit:
Expect(fetchResp.elements).To(Equal(
[]SortedSetElement{
&SortedSetElement{Value: "aValue", Score: 42},
},
))
}
})*/
})

Describe(`SortedSetPutElements`, func() {
// TODO: add tests for SortedSetPutElements
})

Describe(`SortedSetRemove`, func() {
// TODO: SortedSetRemoveElement

Describe(`SortedSetRemoveElements`, func() {
It(`Succeeds when the element does not exist`, func() {
Expect(
sharedContext.Client.SortedSetRemoveElements(
Expand All @@ -771,7 +739,7 @@ var _ = Describe("SortedSet", func() {
Values: []Value{String("dne")},
},
),
).To(BeAssignableToTypeOf(&SortedSetRemoveSuccess{}))
).To(BeAssignableToTypeOf(&SortedSetRemoveElementsSuccess{}))
})

It(`Removes elements`, func() {
Expand All @@ -794,7 +762,7 @@ var _ = Describe("SortedSet", func() {
},
},
),
).To(BeAssignableToTypeOf(&SortedSetRemoveSuccess{}))
).To(BeAssignableToTypeOf(&SortedSetRemoveElementsSuccess{}))

Expect(
sharedContext.Client.SortedSetFetch(
Expand Down
9 changes: 0 additions & 9 deletions responses/sorted_set_remove.go

This file was deleted.

9 changes: 9 additions & 0 deletions responses/sorted_set_remove_element.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package responses

type SortedSetRemoveElementResponse interface {
isSortedSetRemoveElementResponse()
}

type SortedSetRemoveElementSuccess struct{}

func (SortedSetRemoveElementSuccess) isSortedSetRemoveElementResponse() {}
9 changes: 9 additions & 0 deletions responses/sorted_set_remove_elements.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package responses

type SortedSetRemoveElementsResponse interface {
isSortedSetRemoveElementsResponse()
}

type SortedSetRemoveElementsSuccess struct{}

func (SortedSetRemoveElementsSuccess) isSortedSetRemoveElementsResponse() {}

0 comments on commit 01c9adf

Please sign in to comment.