Skip to content

Commit

Permalink
renaming
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 14, 2025
1 parent 8560323 commit bd5c7fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
48 changes: 24 additions & 24 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func toCStrings(args []string) ([]C.uintptr_t, []C.ulong) {
func (client *baseClient) Set(key string, value string) (string, error) {
result, err := client.executeCommand(C.Set, []string{key, value})
if err != nil {
return "", err
return defaultStringResponse, err
}

return handleStringResponse(result)
Expand All @@ -199,7 +199,7 @@ func (client *baseClient) SetWithOptions(key string, value string, options *SetO
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) Get(key string) (Result[string], error) {
Expand All @@ -208,7 +208,7 @@ func (client *baseClient) Get(key string) (Result[string], error) {
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) GetEx(key string) (Result[string], error) {
Expand All @@ -217,7 +217,7 @@ func (client *baseClient) GetEx(key string) (Result[string], error) {
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) GetExWithOptions(key string, options *GetExOptions) (Result[string], error) {
Expand All @@ -231,13 +231,13 @@ func (client *baseClient) GetExWithOptions(key string, options *GetExOptions) (R
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) MSet(keyValueMap map[string]string) (string, error) {
result, err := client.executeCommand(C.MSet, utils.MapToString(keyValueMap))
if err != nil {
return "", err
return defaultStringResponse, err
}

return handleStringResponse(result)
Expand Down Expand Up @@ -330,7 +330,7 @@ func (client *baseClient) SetRange(key string, offset int, value string) (Result
func (client *baseClient) GetRange(key string, start int, end int) (string, error) {
result, err := client.executeCommand(C.GetRange, []string{key, strconv.Itoa(start), strconv.Itoa(end)})
if err != nil {
return "", err
return defaultStringResponse, err
}

return handleStringResponse(result)
Expand All @@ -348,7 +348,7 @@ func (client *baseClient) Append(key string, value string) (Result[int64], error
func (client *baseClient) LCS(key1 string, key2 string) (string, error) {
result, err := client.executeCommand(C.LCS, []string{key1, key2})
if err != nil {
return "", err
return defaultStringResponse, err
}

return handleStringResponse(result)
Expand All @@ -364,7 +364,7 @@ func (client *baseClient) GetDel(key string) (Result[string], error) {
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) HGet(key string, field string) (Result[string], error) {
Expand All @@ -373,7 +373,7 @@ func (client *baseClient) HGet(key string, field string) (Result[string], error)
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) HGetAll(key string) (map[Result[string]]Result[string], error) {
Expand Down Expand Up @@ -524,7 +524,7 @@ func (client *baseClient) LPop(key string) (Result[string], error) {
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) LPopCount(key string, count int64) ([]Result[string], error) {
Expand Down Expand Up @@ -705,7 +705,7 @@ func (client *baseClient) SRandMember(key string) (Result[string], error) {
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) SPop(key string) (Result[string], error) {
Expand All @@ -714,7 +714,7 @@ func (client *baseClient) SPop(key string) (Result[string], error) {
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) SMIsMember(key string, members []string) ([]Result[bool], error) {
Expand Down Expand Up @@ -783,13 +783,13 @@ func (client *baseClient) LIndex(key string, index int64) (Result[string], error
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) LTrim(key string, start int64, end int64) (string, error) {
result, err := client.executeCommand(C.LTrim, []string{key, utils.IntToString(start), utils.IntToString(end)})
if err != nil {
return "", err
return defaultStringResponse, err
}

return handleStringResponse(result)
Expand Down Expand Up @@ -819,7 +819,7 @@ func (client *baseClient) RPop(key string) (Result[string], error) {
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) RPopCount(key string, count int64) ([]Result[string], error) {
Expand Down Expand Up @@ -1001,7 +1001,7 @@ func (client *baseClient) BLMPopCount(
func (client *baseClient) LSet(key string, index int64, element string) (string, error) {
result, err := client.executeCommand(C.LSet, []string{key, utils.IntToString(index), element})
if err != nil {
return "", err
return defaultStringResponse, err
}

return handleStringResponse(result)
Expand All @@ -1027,7 +1027,7 @@ func (client *baseClient) LMove(
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) BLMove(
Expand All @@ -1054,13 +1054,13 @@ func (client *baseClient) BLMove(
return CreateNilStringResult(), err
}

return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) Ping() (string, error) {
result, err := client.executeCommand(C.Ping, []string{})
if err != nil {
return "", err
return defaultStringResponse, err
}

return handleStringResponse(result)
Expand All @@ -1071,7 +1071,7 @@ func (client *baseClient) PingWithMessage(message string) (string, error) {

result, err := client.executeCommand(C.Ping, args)
if err != nil {
return "", err
return defaultStringResponse, err
}

return handleStringResponse(result)
Expand Down Expand Up @@ -1263,7 +1263,7 @@ func (client *baseClient) Type(key string) (Result[string], error) {
if err != nil {
return CreateNilStringResult(), err
}
return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) Touch(keys []string) (Result[int64], error) {
Expand All @@ -1280,7 +1280,7 @@ func (client *baseClient) Rename(key string, newKey string) (Result[string], err
if err != nil {
return CreateNilStringResult(), err
}
return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) Renamenx(key string, newKey string) (Result[bool], error) {
Expand Down Expand Up @@ -1321,7 +1321,7 @@ func (client *baseClient) XAddWithOptions(
if err != nil {
return CreateNilStringResult(), err
}
return handleStringOrNullResponse(result)
return handleStringOrNilResponse(result)
}

func (client *baseClient) ZAdd(
Expand Down
2 changes: 1 addition & 1 deletion go/api/response_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func handleStringResponse(response *C.struct_CommandResponse) (string, error) {
return res.Value(), err
}

func handleStringOrNullResponse(response *C.struct_CommandResponse) (Result[string], error) {
func handleStringOrNilResponse(response *C.struct_CommandResponse) (Result[string], error) {
defer C.free_command_response(response)

return convertCharArrayToString(response, true)
Expand Down
3 changes: 3 additions & 0 deletions go/api/response_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

package api

// A value to return alongside with error in case if command failed
var defaultStringResponse string

type Result[T any] struct {
val T
isNil bool
Expand Down

0 comments on commit bd5c7fe

Please sign in to comment.