Skip to content

Commit

Permalink
feat!: SortedSetGetScores polish. (#245)
Browse files Browse the repository at this point in the history
* SortedSetGetScoresHit
  * Make members private
  * Add Scores() accessor
* SortedSetScoreElement -> SortedSetGetScore
  * They're not elements, and they're not just scores.
  • Loading branch information
schwern authored and cprice404 committed Mar 14, 2023
1 parent 3c56625 commit 31de897
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
10 changes: 5 additions & 5 deletions momento/sorted_set_get_scores.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (r *SortedSetGetScoresRequest) makeGrpcRequest(metadata context.Context, cl
func (r *SortedSetGetScoresRequest) interpretGrpcResponse() error {
switch grpcResp := r.grpcResponse.SortedSet.(type) {
case *pb.XSortedSetGetScoreResponse_Found:
r.response = &responses.SortedSetGetScoresHit{
Elements: convertSortedSetScoreElement(grpcResp.Found.GetElements()),
}
r.response = responses.NewSortedSetGetScoresHit(
convertSortedSetScoreElement(grpcResp.Found.GetElements()),
)
case *pb.XSortedSetGetScoreResponse_Missing:
r.response = &responses.SortedSetGetScoresMiss{}
default:
Expand All @@ -70,8 +70,8 @@ func (r *SortedSetGetScoresRequest) interpretGrpcResponse() error {
return nil
}

func convertSortedSetScoreElement(grpcSetElements []*pb.XSortedSetGetScoreResponse_XSortedSetGetScoreResponsePart) []responses.SortedSetScoreElement {
var rList []responses.SortedSetScoreElement
func convertSortedSetScoreElement(grpcSetElements []*pb.XSortedSetGetScoreResponse_XSortedSetGetScoreResponsePart) []responses.SortedSetGetScore {
var rList []responses.SortedSetGetScore
for _, element := range grpcSetElements {
switch element.Result {
case pb.ECacheResult_Hit:
Expand Down
31 changes: 16 additions & 15 deletions momento/sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,26 +371,27 @@ var _ = Describe("SortedSet", func() {
},
)

Expect(
sharedContext.Client.SortedSetGetScores(
sharedContext.Ctx,
&SortedSetGetScoresRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Values: []Value{
String("first"), String("last"), String("dne"),
},
getResp, err := sharedContext.Client.SortedSetGetScores(
sharedContext.Ctx,
&SortedSetGetScoresRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Values: []Value{
String("first"), String("last"), String("dne"),
},
),
).To(Equal(
&SortedSetGetScoresHit{
Elements: []SortedSetScoreElement{
},
)
Expect(err).To(BeNil())
switch resp := getResp.(type) {
case *SortedSetGetScoresHit:
Expect(resp.Scores()).To(Equal(
[]SortedSetGetScore{
SortedSetScore(9999),
SortedSetScore(-9999),
&SortedSetScoreMiss{},
},
},
))
))
}
})

It(`returns an error when element values are nil`, func() {
Expand Down
20 changes: 16 additions & 4 deletions responses/sorted_set_get_scores.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package responses

type SortedSetScoreElement interface {
isSortedSetScoreElement()
}
// High level responses.

type SortedSetGetScoresResponse interface {
isSortedSetGetScoresResponse()
Expand All @@ -15,11 +13,25 @@ func (SortedSetGetScoresMiss) isSortedSetGetScoresResponse() {}

// SortedSetGetScoresHit Hit Response to a cache SortedSetScore api request.
type SortedSetGetScoresHit struct {
Elements []SortedSetScoreElement
scores []SortedSetGetScore
}

func (SortedSetGetScoresHit) isSortedSetGetScoresResponse() {}

func NewSortedSetGetScoresHit(scores []SortedSetGetScore) *SortedSetGetScoresHit {
return &SortedSetGetScoresHit{scores: scores}
}

func (r SortedSetGetScoresHit) Scores() []SortedSetGetScore {
return r.scores
}

// Responses for individual scores.

type SortedSetGetScore interface {
isSortedSetScoreElement()
}

type SortedSetScore float64

func (SortedSetScore) isSortedSetScoreElement() {}
Expand Down

0 comments on commit 31de897

Please sign in to comment.