From bd5c7fe32db725724b2ebec98c89992a6fb57505 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 14 Jan 2025 14:36:01 -0800 Subject: [PATCH] renaming Signed-off-by: Yury-Fridlyand --- go/api/base_client.go | 48 ++++++++++++++++++------------------- go/api/response_handlers.go | 2 +- go/api/response_types.go | 3 +++ 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/go/api/base_client.go b/go/api/base_client.go index 040197da7a..f111365094 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -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) @@ -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) { @@ -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) { @@ -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) { @@ -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) @@ -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) @@ -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) @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) @@ -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) { @@ -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) @@ -1027,7 +1027,7 @@ func (client *baseClient) LMove( return CreateNilStringResult(), err } - return handleStringOrNullResponse(result) + return handleStringOrNilResponse(result) } func (client *baseClient) BLMove( @@ -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) @@ -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) @@ -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) { @@ -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) { @@ -1321,7 +1321,7 @@ func (client *baseClient) XAddWithOptions( if err != nil { return CreateNilStringResult(), err } - return handleStringOrNullResponse(result) + return handleStringOrNilResponse(result) } func (client *baseClient) ZAdd( diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index 11a241e5da..9de09211fb 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -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) diff --git a/go/api/response_types.go b/go/api/response_types.go index 6172c4ff2b..b2e9d23151 100644 --- a/go/api/response_types.go +++ b/go/api/response_types.go @@ -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