diff --git a/go/api/base_client.go b/go/api/base_client.go index 104c444cfb..8bee42e84e 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -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) { @@ -2828,7 +2828,7 @@ 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) { @@ -2836,7 +2836,7 @@ func (client *baseClient) SortReadOnly(key string) ([]Result[string], error) { if err != nil { return nil, err } - return handleStringArrayResponse(result) + return handleStringOrNilArrayResponse(result) } func (client *baseClient) SortReadOnlyWithOptions(key string, options *options.SortOptions) ([]Result[string], error) { @@ -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) } diff --git a/go/api/generic_base_commands.go b/go/api/generic_base_commands.go index becf0d10c3..005d96fcf4 100644 --- a/go/api/generic_base_commands.go +++ b/go/api/generic_base_commands.go @@ -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 @@ -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 diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index 93ba2df16d..fe906564e7 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -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) }) } @@ -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) }) } @@ -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) }) } @@ -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) }) @@ -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) }) } @@ -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) }) }