Skip to content

Commit

Permalink
Fix the merge
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Jan 20, 2025
1 parent 864e8f3 commit 41bb312
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 59 deletions.
20 changes: 10 additions & 10 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,7 @@ func (client *baseClient) Sort(key string) ([]Result[string], error) {
if err != nil {
return nil, err
}
return handleStringArrayResponse(result)
return handleStringOrNilArrayResponse(result)
}

func (client *baseClient) SortWithOptions(key string, options *options.SortOptions) ([]Result[string], error) {
Expand All @@ -2828,15 +2828,15 @@ func (client *baseClient) SortWithOptions(key string, options *options.SortOptio
if err != nil {
return nil, err
}
return handleStringArrayResponse(result)
return handleStringOrNilArrayResponse(result)
}

func (client *baseClient) SortReadOnly(key string) ([]Result[string], error) {
result, err := client.executeCommand(C.SortReadOnly, []string{key})
if err != nil {
return nil, err
}
return handleStringArrayResponse(result)
return handleStringOrNilArrayResponse(result)
}

func (client *baseClient) SortReadOnlyWithOptions(key string, options *options.SortOptions) ([]Result[string], error) {
Expand All @@ -2845,26 +2845,26 @@ func (client *baseClient) SortReadOnlyWithOptions(key string, options *options.S
if err != nil {
return nil, err
}
return handleStringArrayResponse(result)
return handleStringOrNilArrayResponse(result)
}

func (client *baseClient) SortStore(key string, destination string) (Result[int64], error) {
func (client *baseClient) SortStore(key string, destination string) (int64, error) {
result, err := client.executeCommand(C.Sort, []string{key, "STORE", destination})
if err != nil {
return CreateNilInt64Result(), err
return defaultIntResponse, err
}
return handleIntOrNilResponse(result)
return handleIntResponse(result)
}

func (client *baseClient) SortStoreWithOptions(
key string,
destination string,
options *options.SortOptions,
) (Result[int64], error) {
) (int64, error) {
optionArgs := options.ToArgs()
result, err := client.executeCommand(C.Sort, append([]string{key, "STORE", destination}, optionArgs...))
if err != nil {
return CreateNilInt64Result(), err
return defaultIntResponse, err
}
return handleIntOrNilResponse(result)
return handleIntResponse(result)
}
10 changes: 4 additions & 6 deletions go/api/generic_base_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,10 @@ type GenericBaseCommands interface {
// Example:
//
// result, err := client.SortStore("key","destkey")
// result.Value(): 1
// result.IsNil(): false
// result: 1
//
// [valkey.io]: https://valkey.io/commands/sort/
SortStore(key string, destination string) (Result[int64], error)
SortStore(key string, destination string) (int64, error)

// Sorts the elements in the list, set, or sorted set at key and stores the result in
// destination. The sort command can be used to sort elements based on
Expand Down Expand Up @@ -648,11 +647,10 @@ type GenericBaseCommands interface {
//
// options := api.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).AddGetPattern("object_*").AddGetPattern("#")
// result, err := client.SortStore("key","destkey",options)
// result.Value(): 1
// result.IsNil(): false
// result: 1
//
// [valkey.io]: https://valkey.io/commands/sort/
SortStoreWithOptions(key string, destination string, sortOptions *options.SortOptions) (Result[int64], error)
SortStoreWithOptions(key string, destination string, sortOptions *options.SortOptions) (int64, error)

// Sorts the elements in the list, set, or sorted set at key and returns the result.
// The sortReadOnly command can be used to sort elements based on different criteria and apply
Expand Down
54 changes: 11 additions & 43 deletions go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3776,18 +3776,11 @@ func (suite *GlideTestSuite) TestSortStore_BasicSorting() {

assert.Nil(suite.T(), err)
assert.NotNil(suite.T(), result)
assert.Equal(suite.T(), int64(5), result.Value())
assert.Equal(suite.T(), int64(5), result)

sortedValues, err := client.LRange(sortedKey, 0, -1)
resultList := []api.Result[string]{
api.CreateStringResult("1"),
api.CreateStringResult("2"),
api.CreateStringResult("4"),
api.CreateStringResult("5"),
api.CreateStringResult("10"),
}
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), resultList, sortedValues)
assert.Equal(suite.T(), []string{"1", "2", "4", "5", "10"}, sortedValues)
})
}

Expand All @@ -3796,7 +3789,7 @@ func (suite *GlideTestSuite) TestSortStore_ErrorHandling() {
result, err := client.SortStore("{listKey}nonExistingKey", "{listKey}mydestinationKey")

assert.Nil(suite.T(), err)
assert.Equal(suite.T(), int64(0), result.Value())
assert.Equal(suite.T(), int64(0), result)
})
}

Expand All @@ -3811,18 +3804,11 @@ func (suite *GlideTestSuite) TestSortStoreWithOptions_DescendingOrder() {

assert.Nil(suite.T(), err)
assert.NotNil(suite.T(), result)
assert.Equal(suite.T(), int64(5), result.Value())
assert.Equal(suite.T(), int64(5), result)

sortedValues, err := client.LRange(sortedKey, 0, -1)
resultList := []api.Result[string]{
api.CreateStringResult("50"),
api.CreateStringResult("40"),
api.CreateStringResult("30"),
api.CreateStringResult("20"),
api.CreateStringResult("10"),
}
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), resultList, sortedValues)
assert.Equal(suite.T(), []string{"50", "40", "30", "20", "10"}, sortedValues)
})
}

Expand All @@ -3837,16 +3823,10 @@ func (suite *GlideTestSuite) TestSortStoreWithOptions_AlphaSorting() {

assert.Nil(suite.T(), err)
assert.NotNil(suite.T(), result)
assert.Equal(suite.T(), int64(5), result.Value())
assert.Equal(suite.T(), int64(5), result)

sortedValues, err := client.LRange(sortedKey, 0, -1)
resultList := []api.Result[string]{
api.CreateStringResult("apple"),
api.CreateStringResult("banana"),
api.CreateStringResult("cherry"),
api.CreateStringResult("date"),
api.CreateStringResult("elderberry"),
}
resultList := []string{"apple", "banana", "cherry", "date", "elderberry"}
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), resultList, sortedValues)
})
Expand All @@ -3863,16 +3843,11 @@ func (suite *GlideTestSuite) TestSortStoreWithOptions_Limit() {

assert.Nil(suite.T(), err)
assert.NotNil(suite.T(), result)
assert.Equal(suite.T(), int64(3), result.Value())
assert.Equal(suite.T(), int64(3), result)

sortedValues, err := client.LRange(sortedKey, 0, -1)
resultList := []api.Result[string]{
api.CreateStringResult("20"),
api.CreateStringResult("30"),
api.CreateStringResult("40"),
}
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), resultList, sortedValues)
assert.Equal(suite.T(), []string{"20", "30", "40"}, sortedValues)
})
}

Expand Down Expand Up @@ -6513,17 +6488,10 @@ func (suite *GlideTestSuite) TestSortStoreWithOptions_ByPattern() {

assert.Nil(suite.T(), err)
assert.NotNil(suite.T(), result)
assert.Equal(suite.T(), int64(5), result.Value())
assert.Equal(suite.T(), int64(5), result)

sortedValues, err := client.LRange(sortedKey, 0, -1)
resultList := []api.Result[string]{
api.CreateStringResult("d"),
api.CreateStringResult("b"),
api.CreateStringResult("c"),
api.CreateStringResult("e"),
api.CreateStringResult("a"),
}
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), resultList, sortedValues)
assert.Equal(suite.T(), []string{"d", "b", "c", "e", "a"}, sortedValues)
})
}

0 comments on commit 41bb312

Please sign in to comment.