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 2: float64 instead of Result[float64] and bool #2941

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
122 changes: 61 additions & 61 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ func (client *baseClient) MSet(keyValueMap map[string]string) (Result[string], e
return handleStringResponse(result)
}

func (client *baseClient) MSetNX(keyValueMap map[string]string) (Result[bool], error) {
func (client *baseClient) MSetNX(keyValueMap map[string]string) (bool, error) {
result, err := client.executeCommand(C.MSetNX, utils.MapToString(keyValueMap))
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}

return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) MGet(keys []string) ([]Result[string], error) {
Expand Down Expand Up @@ -279,16 +279,16 @@ func (client *baseClient) IncrBy(key string, amount int64) (int64, error) {
return handleIntResponse(result)
}

func (client *baseClient) IncrByFloat(key string, amount float64) (Result[float64], error) {
func (client *baseClient) IncrByFloat(key string, amount float64) (float64, error) {
result, err := client.executeCommand(
C.IncrByFloat,
[]string{key, utils.FloatToString(amount)},
)
if err != nil {
return CreateNilFloat64Result(), err
return defaultFloatResponse, err
}

return handleDoubleResponse(result)
return handleFloatResponse(result)
}

func (client *baseClient) Decr(key string) (int64, error) {
Expand Down Expand Up @@ -403,13 +403,13 @@ func (client *baseClient) HSet(key string, values map[string]string) (int64, err
return handleIntResponse(result)
}

func (client *baseClient) HSetNX(key string, field string, value string) (Result[bool], error) {
func (client *baseClient) HSetNX(key string, field string, value string) (bool, error) {
result, err := client.executeCommand(C.HSetNX, []string{key, field, value})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}

return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) HDel(key string, fields []string) (int64, error) {
Expand Down Expand Up @@ -439,13 +439,13 @@ func (client *baseClient) HVals(key string) ([]Result[string], error) {
return handleStringArrayResponse(result)
}

func (client *baseClient) HExists(key string, field string) (Result[bool], error) {
func (client *baseClient) HExists(key string, field string) (bool, error) {
result, err := client.executeCommand(C.HExists, []string{key, field})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}

return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) HKeys(key string) ([]Result[string], error) {
Expand Down Expand Up @@ -475,13 +475,13 @@ func (client *baseClient) HIncrBy(key string, field string, increment int64) (in
return handleIntResponse(result)
}

func (client *baseClient) HIncrByFloat(key string, field string, increment float64) (Result[float64], error) {
func (client *baseClient) HIncrByFloat(key string, field string, increment float64) (float64, error) {
result, err := client.executeCommand(C.HIncrByFloat, []string{key, field, utils.FloatToString(increment)})
if err != nil {
return CreateNilFloat64Result(), err
return defaultFloatResponse, err
}

return handleDoubleResponse(result)
return handleFloatResponse(result)
}

func (client *baseClient) HScan(key string, cursor string) (Result[string], []Result[string], error) {
Expand Down Expand Up @@ -634,13 +634,13 @@ func (client *baseClient) SCard(key string) (int64, error) {
return handleIntResponse(result)
}

func (client *baseClient) SIsMember(key string, member string) (Result[bool], error) {
func (client *baseClient) SIsMember(key string, member string) (bool, error) {
result, err := client.executeCommand(C.SIsMember, []string{key, member})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}

return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) SDiff(keys []string) (map[Result[string]]struct{}, error) {
Expand Down Expand Up @@ -717,13 +717,13 @@ func (client *baseClient) SPop(key string) (Result[string], error) {
return handleStringResponse(result)
}

func (client *baseClient) SMIsMember(key string, members []string) ([]Result[bool], error) {
func (client *baseClient) SMIsMember(key string, members []string) ([]bool, error) {
result, err := client.executeCommand(C.SMIsMember, append([]string{key}, members...))
if err != nil {
return nil, err
}

return handleBooleanArrayResponse(result)
return handleBoolArrayResponse(result)
}

func (client *baseClient) SUnion(keys []string) (map[Result[string]]struct{}, error) {
Expand Down Expand Up @@ -760,12 +760,12 @@ func (client *baseClient) SScanWithOptions(
return handleScanResponse(result)
}

func (client *baseClient) SMove(source string, destination string, member string) (Result[bool], error) {
func (client *baseClient) SMove(source string, destination string, member string) (bool, error) {
result, err := client.executeCommand(C.SMove, []string{source, destination, member})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) LRange(key string, start int64, end int64) ([]Result[string], error) {
Expand Down Expand Up @@ -1103,104 +1103,104 @@ func (client *baseClient) Exists(keys []string) (int64, error) {
return handleIntResponse(result)
}

func (client *baseClient) Expire(key string, seconds int64) (Result[bool], error) {
func (client *baseClient) Expire(key string, seconds int64) (bool, error) {
result, err := client.executeCommand(C.Expire, []string{key, utils.IntToString(seconds)})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}

return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) ExpireWithOptions(key string, seconds int64, expireCondition ExpireCondition) (Result[bool], error) {
func (client *baseClient) ExpireWithOptions(key string, seconds int64, expireCondition ExpireCondition) (bool, error) {
expireConditionStr, err := expireCondition.toString()
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
result, err := client.executeCommand(C.Expire, []string{key, utils.IntToString(seconds), expireConditionStr})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) ExpireAt(key string, unixTimestampInSeconds int64) (Result[bool], error) {
func (client *baseClient) ExpireAt(key string, unixTimestampInSeconds int64) (bool, error) {
result, err := client.executeCommand(C.ExpireAt, []string{key, utils.IntToString(unixTimestampInSeconds)})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}

return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) ExpireAtWithOptions(
key string,
unixTimestampInSeconds int64,
expireCondition ExpireCondition,
) (Result[bool], error) {
) (bool, error) {
expireConditionStr, err := expireCondition.toString()
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
result, err := client.executeCommand(
C.ExpireAt,
[]string{key, utils.IntToString(unixTimestampInSeconds), expireConditionStr},
)
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) PExpire(key string, milliseconds int64) (Result[bool], error) {
func (client *baseClient) PExpire(key string, milliseconds int64) (bool, error) {
result, err := client.executeCommand(C.PExpire, []string{key, utils.IntToString(milliseconds)})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) PExpireWithOptions(
key string,
milliseconds int64,
expireCondition ExpireCondition,
) (Result[bool], error) {
) (bool, error) {
expireConditionStr, err := expireCondition.toString()
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
result, err := client.executeCommand(C.PExpire, []string{key, utils.IntToString(milliseconds), expireConditionStr})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) PExpireAt(key string, unixTimestampInMilliSeconds int64) (Result[bool], error) {
func (client *baseClient) PExpireAt(key string, unixTimestampInMilliSeconds int64) (bool, error) {
result, err := client.executeCommand(C.PExpireAt, []string{key, utils.IntToString(unixTimestampInMilliSeconds)})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) PExpireAtWithOptions(
key string,
unixTimestampInMilliSeconds int64,
expireCondition ExpireCondition,
) (Result[bool], error) {
) (bool, error) {
expireConditionStr, err := expireCondition.toString()
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
result, err := client.executeCommand(
C.PExpireAt,
[]string{key, utils.IntToString(unixTimestampInMilliSeconds), expireConditionStr},
)
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) ExpireTime(key string) (int64, error) {
Expand Down Expand Up @@ -1291,12 +1291,12 @@ func (client *baseClient) Rename(key string, newKey string) (Result[string], err
return handleStringOrNullResponse(result)
}

func (client *baseClient) Renamenx(key string, newKey string) (Result[bool], error) {
func (client *baseClient) Renamenx(key string, newKey string) (bool, error) {
result, err := client.executeCommand(C.RenameNX, []string{key, newKey})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) XAdd(key string, values [][]string) (Result[string], error) {
Expand Down Expand Up @@ -1379,7 +1379,7 @@ func (client *baseClient) zAddIncrBase(key string, opts *options.ZAddOptions) (R
return CreateNilFloat64Result(), err
}

return handleDoubleResponse(result)
return handleFloatOrNilResponse(result)
}

func (client *baseClient) ZAddIncr(
Expand Down Expand Up @@ -1409,13 +1409,13 @@ func (client *baseClient) ZAddIncrWithOptions(
return client.zAddIncrBase(key, incrOpts)
}

func (client *baseClient) ZIncrBy(key string, increment float64, member string) (Result[float64], error) {
func (client *baseClient) ZIncrBy(key string, increment float64, member string) (float64, error) {
result, err := client.executeCommand(C.ZIncrBy, []string{key, utils.FloatToString(increment), member})
if err != nil {
return CreateNilFloat64Result(), err
return defaultFloatResponse, err
}

return handleDoubleResponse(result)
return handleFloatResponse(result)
}

func (client *baseClient) ZPopMin(key string) (map[Result[string]]Result[float64], error) {
Expand Down Expand Up @@ -1571,12 +1571,12 @@ func (client *baseClient) ZRangeWithScores(
return handleStringDoubleMapResponse(result)
}

func (client *baseClient) Persist(key string) (Result[bool], error) {
func (client *baseClient) Persist(key string) (bool, error) {
result, err := client.executeCommand(C.Persist, []string{key})
if err != nil {
return CreateNilBoolResult(), err
return defaultBoolResponse, err
}
return handleBooleanResponse(result)
return handleBoolResponse(result)
}

func (client *baseClient) ZRank(key string, member string) (Result[int64], error) {
Expand Down
Loading
Loading