Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go: Fix return types, part 6 #2965

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 29 additions & 31 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (client *baseClient) MGet(keys []string) ([]Result[string], error) {
return nil, err
}

return handleStringArrayResponse(result)
return handleStringOrNilArrayResponse(result)
}

func (client *baseClient) Incr(key string) (int64, error) {
Expand Down Expand Up @@ -391,7 +391,7 @@ func (client *baseClient) HMGet(key string, fields []string) ([]Result[string],
return nil, err
}

return handleStringArrayResponse(result)
return handleStringOrNilArrayResponse(result)
}

func (client *baseClient) HSet(key string, values map[string]string) (int64, error) {
Expand Down Expand Up @@ -430,7 +430,7 @@ func (client *baseClient) HLen(key string) (int64, error) {
return handleIntResponse(result)
}

func (client *baseClient) HVals(key string) ([]Result[string], error) {
func (client *baseClient) HVals(key string) ([]string, error) {
result, err := client.executeCommand(C.HVals, []string{key})
if err != nil {
return nil, err
Expand All @@ -448,7 +448,7 @@ func (client *baseClient) HExists(key string, field string) (bool, error) {
return handleBoolResponse(result)
}

func (client *baseClient) HKeys(key string) ([]Result[string], error) {
func (client *baseClient) HKeys(key string) ([]string, error) {
result, err := client.executeCommand(C.HKeys, []string{key})
if err != nil {
return nil, err
Expand Down Expand Up @@ -527,13 +527,13 @@ func (client *baseClient) LPop(key string) (Result[string], error) {
return handleStringOrNilResponse(result)
}

func (client *baseClient) LPopCount(key string, count int64) ([]Result[string], error) {
func (client *baseClient) LPopCount(key string, count int64) ([]string, error) {
result, err := client.executeCommand(C.LPop, []string{key, utils.IntToString(count)})
if err != nil {
return nil, err
}

return handleStringArrayOrNullResponse(result)
return handleStringArrayOrNilResponse(result)
}

func (client *baseClient) LPos(key string, element string) (Result[int64], error) {
Expand All @@ -554,7 +554,7 @@ func (client *baseClient) LPosWithOptions(key string, element string, options *L
return handleIntOrNilResponse(result)
}

func (client *baseClient) LPosCount(key string, element string, count int64) ([]Result[int64], error) {
func (client *baseClient) LPosCount(key string, element string, count int64) ([]int64, error) {
result, err := client.executeCommand(C.LPos, []string{key, element, CountKeyword, utils.IntToString(count)})
if err != nil {
return nil, err
Expand All @@ -568,7 +568,7 @@ func (client *baseClient) LPosCountWithOptions(
element string,
count int64,
options *LPosOptions,
) ([]Result[int64], error) {
) ([]int64, error) {
result, err := client.executeCommand(
C.LPos,
append([]string{key, element, CountKeyword, utils.IntToString(count)}, options.toArgs()...),
Expand Down Expand Up @@ -768,7 +768,7 @@ func (client *baseClient) SMove(source string, destination string, member string
return handleBoolResponse(result)
}

func (client *baseClient) LRange(key string, start int64, end int64) ([]Result[string], error) {
func (client *baseClient) LRange(key string, start int64, end int64) ([]string, error) {
result, err := client.executeCommand(C.LRange, []string{key, utils.IntToString(start), utils.IntToString(end)})
if err != nil {
return nil, err
Expand Down Expand Up @@ -822,13 +822,13 @@ func (client *baseClient) RPop(key string) (Result[string], error) {
return handleStringOrNilResponse(result)
}

func (client *baseClient) RPopCount(key string, count int64) ([]Result[string], error) {
func (client *baseClient) RPopCount(key string, count int64) ([]string, error) {
result, err := client.executeCommand(C.RPop, []string{key, utils.IntToString(count)})
if err != nil {
return nil, err
}

return handleStringArrayOrNullResponse(result)
return handleStringArrayOrNilResponse(result)
}

func (client *baseClient) LInsert(
Expand All @@ -853,22 +853,22 @@ func (client *baseClient) LInsert(
return handleIntResponse(result)
}

func (client *baseClient) BLPop(keys []string, timeoutSecs float64) ([]Result[string], error) {
func (client *baseClient) BLPop(keys []string, timeoutSecs float64) ([]string, error) {
result, err := client.executeCommand(C.BLPop, append(keys, utils.FloatToString(timeoutSecs)))
if err != nil {
return nil, err
}

return handleStringArrayOrNullResponse(result)
return handleStringArrayOrNilResponse(result)
}

func (client *baseClient) BRPop(keys []string, timeoutSecs float64) ([]Result[string], error) {
func (client *baseClient) BRPop(keys []string, timeoutSecs float64) ([]string, error) {
result, err := client.executeCommand(C.BRPop, append(keys, utils.FloatToString(timeoutSecs)))
if err != nil {
return nil, err
}

return handleStringArrayOrNullResponse(result)
return handleStringArrayOrNilResponse(result)
}

func (client *baseClient) RPushX(key string, elements []string) (int64, error) {
Expand Down Expand Up @@ -1258,12 +1258,12 @@ func (client *baseClient) Unlink(keys []string) (int64, error) {
return handleIntResponse(result)
}

func (client *baseClient) Type(key string) (Result[string], error) {
func (client *baseClient) Type(key string) (string, error) {
result, err := client.executeCommand(C.Type, []string{key})
if err != nil {
return CreateNilStringResult(), err
return defaultStringResponse, err
}
return handleStringOrNilResponse(result)
return handleStringResponse(result)
}

func (client *baseClient) Touch(keys []string) (int64, error) {
Expand All @@ -1275,12 +1275,12 @@ func (client *baseClient) Touch(keys []string) (int64, error) {
return handleIntResponse(result)
}

func (client *baseClient) Rename(key string, newKey string) (Result[string], error) {
func (client *baseClient) Rename(key string, newKey string) (string, error) {
result, err := client.executeCommand(C.Rename, []string{key, newKey})
if err != nil {
return CreateNilStringResult(), err
return defaultStringResponse, err
}
return handleStringOrNilResponse(result)
return handleStringResponse(result)
}

func (client *baseClient) Renamenx(key string, newKey string) (bool, error) {
Expand Down Expand Up @@ -1579,16 +1579,15 @@ func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) (Result[K
// result, err := client.ZRange("my_sorted_set", options.NewRangeByIndexQuery(0, -1))
//
// // Retrieve members within a score range in descending order
//
// query := options.NewRangeByScoreQuery(options.NewScoreBoundary(3, false),
// options.NewInfiniteScoreBoundary(options.NegativeInfinity)).
//
// .SetReverse()
// query := options.NewRangeByScoreQuery(
// options.NewScoreBoundary(3, false),
// options.NewInfiniteScoreBoundary(options.NegativeInfinity)).
// SetReverse()
// result, err := client.ZRange("my_sorted_set", query)
// // `result` contains members which have scores within the range of negative infinity to 3, in descending order
//
// [valkey.io]: https://valkey.io/commands/zrange/
func (client *baseClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]Result[string], error) {
func (client *baseClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]string, error) {
args := make([]string, 0, 10)
args = append(args, key)
args = append(args, rangeQuery.ToArgs()...)
Expand Down Expand Up @@ -1623,10 +1622,9 @@ func (client *baseClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]
// result, err := client.ZRangeWithScores("my_sorted_set", options.NewRangeByIndexQuery(0, -1))
//
// // Retrieve members within a score range in descending order
//
// query := options.NewRangeByScoreQuery(options.NewScoreBoundary(3, false),
// options.NewInfiniteScoreBoundary(options.NegativeInfinity)).
//
// query := options.NewRangeByScoreQuery(
// options.NewScoreBoundary(3, false),
// options.NewInfiniteScoreBoundary(options.NegativeInfinity)).
// SetReverse()
// result, err := client.ZRangeWithScores("my_sorted_set", query)
// // `result` contains members with scores within the range of negative infinity to 3, in descending order
Expand Down
10 changes: 5 additions & 5 deletions go/api/generic_base_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,17 @@ type GenericBaseCommands interface {
// key - string
//
// Return value:
// If the key exists, the type of the stored value is returned. Otherwise, a none" string is returned.
// If the key exists, the type of the stored value is returned. Otherwise, a "none" string is returned.
//
// Example:
// result, err := client.Type([]string{"key"})
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: string
// fmt.Println(result) // Output: string
//
// [valkey.io]: Https://valkey.io/commands/type/
Type(key string) (Result[string], error)
Type(key string) (string, error)

// Renames key to new key.
// If new Key already exists it is overwritten.
Expand All @@ -397,10 +397,10 @@ type GenericBaseCommands interface {
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: OK
// fmt.Println(result) // Output: OK
//
// [valkey.io]: https://valkey.io/commands/rename/
Rename(key string, newKey string) (Result[string], error)
Rename(key string, newKey string) (string, error)

// Renames key to newkey if newKey does not yet exist.
//
Expand Down
17 changes: 6 additions & 11 deletions go/api/hash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,14 @@ type HashCommands interface {
// key - The key of the hash.
//
// Return value:
// A slice of Result[string]s containing all the values in the hash, or an empty slice when key does not exist.
// A slice containing all the values in the hash, or an empty slice when key does not exist.
//
// For example:
// values, err := client.HVals("myHash")
// // value1 equals api.CreateStringResult("value1")
// // value2 equals api.CreateStringResult("value2")
// // value3 equals api.CreateStringResult("value3")
// // values equals []api.Result[string]{value1, value2, value3}
// values: []string{"value1", "value2", "value3"}
//
// [valkey.io]: https://valkey.io/commands/hvals/
HVals(key string) ([]Result[string], error)
HVals(key string) ([]string, error)

// HExists returns if field is an existing field in the hash stored at key.
//
Expand Down Expand Up @@ -215,16 +212,14 @@ type HashCommands interface {
// key - The key of the hash.
//
// Return value:
// A slice of Result[string]s containing all the field names in the hash, or an empty slice when key does not exist.
// A slice containing all the field names in the hash, or an empty slice when key does not exist.
//
// For example:
// names, err := client.HKeys("my_hash")
// // field1 equals api.CreateStringResult("field_1")
// // field2 equals api.CreateStringResult("field_2")
// // names equals []api.Result[string]{field1, field2}
// names: []string{"field1", "field2"}
//
// [valkey.io]: https://valkey.io/commands/hkeys/
HKeys(key string) ([]Result[string], error)
HKeys(key string) ([]string, error)

// HStrLen returns the string length of the value associated with field in the hash stored at key.
// If the key or the field do not exist, 0 is returned.
Expand Down
Loading
Loading