From b4ef1788a59d18924a5da63634ddb4ac0fdac131 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Fri, 3 Jan 2025 18:20:19 -0800 Subject: [PATCH] fix Signed-off-by: Yury-Fridlyand --- go/api/base_client.go | 4 ++-- go/api/glide_client.go | 2 +- go/utils/transform_utils.go | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/go/api/base_client.go b/go/api/base_client.go index 477f3b2579..09b671cba1 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -234,7 +234,7 @@ func (client *baseClient) GetExWithOptions(key string, options *GetExOptions) (R } func (client *baseClient) MSet(keyValueMap map[string]string) (Result[string], error) { - result, err := client.executeCommand(C.MSet, utils.ConvertMapToValueKeyStringArray(keyValueMap)) + result, err := client.executeCommand(C.MSet, utils.MapToString(keyValueMap)) if err != nil { return CreateNilStringResult(), err } @@ -243,7 +243,7 @@ func (client *baseClient) MSet(keyValueMap map[string]string) (Result[string], e } func (client *baseClient) MSetNX(keyValueMap map[string]string) (Result[bool], error) { - result, err := client.executeCommand(C.MSetNX, utils.ConvertMapToValueKeyStringArray(keyValueMap)) + result, err := client.executeCommand(C.MSetNX, utils.MapToString(keyValueMap)) if err != nil { return CreateNilBoolResult(), err } diff --git a/go/api/glide_client.go b/go/api/glide_client.go index 482c1d14ac..04e43266f2 100644 --- a/go/api/glide_client.go +++ b/go/api/glide_client.go @@ -73,7 +73,7 @@ func (client *GlideClient) CustomCommand(args []string) (interface{}, error) { // // [valkey.io]: https://valkey.io/commands/config-set/ func (client *GlideClient) ConfigSet(parameters map[string]string) (Result[string], error) { - result, err := client.executeCommand(C.ConfigSet, utils.ConvertMapToValueKeyStringArray(parameters)) + result, err := client.executeCommand(C.ConfigSet, utils.MapToString(parameters)) if err != nil { return CreateNilStringResult(), err } diff --git a/go/utils/transform_utils.go b/go/utils/transform_utils.go index 49ff5cd8c7..cde78a98b1 100644 --- a/go/utils/transform_utils.go +++ b/go/utils/transform_utils.go @@ -41,7 +41,16 @@ func ConvertMapToKeyValueStringArray(key string, args map[string]string) []strin return values } -// Flattens a map[string, V] to a value-key string array like { key1, value1, key2, value2, ..} +// Flattens the Map: { (key1, value1), (key2, value2), ..} to a slice { key1, value1, key2, value2, ..} +func MapToString(parameter map[string]string) []string { + flat := make([]string, 0, len(parameter)*2) + for key, value := range parameter { + flat = append(flat, key, value) + } + return flat +} + +// Flattens a map[string, V] to a value-key string array like { value1, key1, value2, key2..} func ConvertMapToValueKeyStringArray[V any](args map[string]V) []string { result := make([]string, 0, len(args)*2) for key, value := range args {