Skip to content

Commit

Permalink
fix
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 4, 2025
1 parent 41ea849 commit b4ef178
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 10 additions & 1 deletion go/utils/transform_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b4ef178

Please sign in to comment.