Skip to content

Commit

Permalink
Remove the need to sort
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Liang <[email protected]>
  • Loading branch information
edlng committed Jan 25, 2025
1 parent 2528175 commit 2e5eba6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
8 changes: 4 additions & 4 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4543,8 +4543,8 @@ func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) (Result[K
// Return value:
//
// An object containing the following elements:
// - The key name of the set from which the element was popped
// - An array of member scores of the popped elements in ascending order.
// - The key name of the set from which the element was popped.
// - An array of member scores of the popped elements.
// Returns `nil` if no member could be popped and the timeout expired.
//
// For example:
Expand Down Expand Up @@ -4609,8 +4609,8 @@ func (client *baseClient) BZMPop(
// Return value:
//
// An object containing the following elements:
// - The key name of the set from which the element was popped
// - An array of member scores of the popped elements in ascending order.
// - The key name of the set from which the element was popped.
// - An array of member scores of the popped elements.
// Returns `nil` if no member could be popped and the timeout expired.
//
// For example:
Expand Down
6 changes: 0 additions & 6 deletions go/api/response_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "C"
import (
"fmt"
"reflect"
"sort"
"strconv"
"unsafe"

Expand Down Expand Up @@ -578,11 +577,6 @@ func handleKeyWithArrayOfMembersAndScoresResponse(
memberAndScoreArray = append(memberAndScoreArray, MemberAndScore{k, v})
}

// Ensure consistent output
sort.Slice(memberAndScoreArray, func(i, j int) bool {
return memberAndScoreArray[i].Score < memberAndScoreArray[j].Score
})

return CreateKeyWithArrayOfMembersAndScoresResult(KeyWithArrayOfMembersAndScores{key, memberAndScoreArray}), nil
}

Expand Down
18 changes: 7 additions & 11 deletions go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2915,18 +2915,14 @@ func (suite *GlideTestSuite) TestBZMPopAndBZMPopWithOptions() {
// Try to pop the top 2 elements from key1
res5, err := client.BZMPopWithOptions([]string{key1}, api.MAX, float64(0.1), options.NewZMPopOptions().SetCount(2))
assert.Nil(suite.T(), err)
assert.Equal(
assert.Equal(suite.T(), key1, res5.Value().Key)
assert.ElementsMatch(
suite.T(),
api.CreateKeyWithArrayOfMembersAndScoresResult(
api.KeyWithArrayOfMembersAndScores{
Key: key1,
MembersAndScores: []api.MemberAndScore{
{Member: "two", Score: 2.0},
{Member: "three", Score: 3.0},
},
},
),
res5,
[]api.MemberAndScore{
{Member: "three", Score: 3.0},
{Member: "two", Score: 2.0},
},
res5.Value().MembersAndScores,
)

// Try to pop the minimum value from key2
Expand Down

0 comments on commit 2e5eba6

Please sign in to comment.