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: Implement Cluster ConfigGet and ConfigSet #3274

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Go: Add `LastSave` ([#3086](https://github.com/valkey-io/valkey-glide/pull/3086))
* Go: Add `Config Reset Stat` ([#3121](https://github.com/valkey-io/valkey-glide/pull/3121))
* Go: Add `GeoSearch` and `GeoSearchStore` ([#3385](https://github.com/valkey-io/valkey-glide/pull/3385))
* Go: Add `Cluster Config Set & Get` ([#3274](https://github.com/valkey-io/valkey-glide/pull/3274))

#### Breaking Changes

Expand Down
103 changes: 103 additions & 0 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/valkey-io/valkey-glide/go/api/config"
"github.com/valkey-io/valkey-glide/go/api/errors"
"github.com/valkey-io/valkey-glide/go/api/options"
"github.com/valkey-io/valkey-glide/go/utils"
)

// GlideClusterClient interface compliance check.
Expand Down Expand Up @@ -747,3 +748,105 @@ func (client *GlideClusterClient) ConfigResetStatWithOptions(opts options.RouteO
}
return handleStringResponse(response)
}

// Sets configuration parameters to the specified values.
// Starting from server version 7, command supports multiple parameters.
// The command will be sent to all nodes.
//
// Parameters:
//
// parameters - A map consisting of configuration parameters and their respective values to set.
//
// Return value:
//
// OK if all configurations have been successfully set. Otherwise, raises an error.
//
// [valkey.io]: https://valkey.io/commands/config-set/
func (client *GlideClusterClient) ConfigSet(
parameters map[string]string,
) (string, error) {
result, err := client.executeCommand(C.ConfigSet, utils.MapToString(parameters))
if err != nil {
return DefaultStringResponse, err
}
return handleStringResponse(result)
}

// Sets configuration parameters to the specified values
// Starting from server version 7, command supports multiple parameters.
//
// Parameters:
//
// parameters - A map consisting of configuration parameters and their respective values to set.
// opts - Specifies the routing configuration for the command. The client will route the
// command to the nodes defined by route.
//
// Return value:
//
// OK if all configurations have been successfully set. Otherwise, raises an error.
//
// [valkey.io]: https://valkey.io/commands/config-set/
func (client *GlideClusterClient) ConfigSetWithOptions(
parameters map[string]string, opts options.RouteOption,
) (string, error) {
result, err := client.executeCommandWithRoute(C.ConfigSet, utils.MapToString(parameters), opts.Route)
if err != nil {
return DefaultStringResponse, err
}
return handleStringResponse(result)
}

// Get the values of configuration parameters.
// Starting from server version 7, command supports multiple parameters.
// The command will be sent to a random node.
//
// Parameters:
//
// parameters - An array of configuration parameter names to retrieve values for.
//
// Return value:
//
// A map of values corresponding to the configuration parameters.
//
// [valkey.io]: https://valkey.io/commands/config-get/
func (client *GlideClusterClient) ConfigGet(
parameters []string,
) (ClusterValue[interface{}], error) {
res, err := client.executeCommand(C.ConfigGet, parameters)
if err != nil {
return createEmptyClusterValue[interface{}](), err
}
data, err := handleInterfaceResponse(res)
if err != nil {
return createEmptyClusterValue[interface{}](), err
}
return createClusterValue[interface{}](data), nil
}

// Get the values of configuration parameters.
// Starting from server version 7, command supports multiple parameters.
//
// Parameters:
//
// parameters - An array of configuration parameter names to retrieve values for.
// opts - Specifies the routing configuration for the command. The client will route the
// command to the nodes defined by route.
//
// Return value:
//
// A map of values corresponding to the configuration parameters.
//
// [valkey.io]: https://valkey.io/commands/config-get/
func (client *GlideClusterClient) ConfigGetWithOptions(
parameters []string, opts options.RouteOption,
) (ClusterValue[interface{}], error) {
res, err := client.executeCommandWithRoute(C.ConfigGet, parameters, opts.Route)
if err != nil {
return createEmptyClusterValue[interface{}](), err
}
data, err := handleInterfaceResponse(res)
if err != nil {
return createEmptyClusterValue[interface{}](), err
}
return createClusterValue[interface{}](data), nil
}
8 changes: 8 additions & 0 deletions go/api/server_management_cluster_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ type ServerManagementClusterCommands interface {
ConfigResetStat() (string, error)

ConfigResetStatWithOptions(routeOption options.RouteOption) (string, error)

ConfigSet(parameters map[string]string) (string, error)

ConfigSetWithOptions(parameters map[string]string, routeOption options.RouteOption) (string, error)

ConfigGet(parameters []string) (ClusterValue[interface{}], error)

ConfigGetWithOptions(parameters []string, routeOption options.RouteOption) (ClusterValue[interface{}], error)
}
61 changes: 58 additions & 3 deletions go/api/server_management_cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func ExampleGlideClusterClient_InfoWithOptions() {

func ExampleGlideClusterClient_TimeWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function

route := config.Route(config.RandomRoute)
opts := options.RouteOption{
Route: route,
Expand All @@ -69,7 +68,6 @@ func ExampleGlideClusterClient_TimeWithOptions() {

func ExampleGlideClusterClient_DBSizeWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function

route := config.SimpleNodeRoute(config.RandomRoute)
opts := options.RouteOption{
Route: route,
Expand All @@ -78,7 +76,6 @@ func ExampleGlideClusterClient_DBSizeWithOptions() {
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}

fmt.Println(result)

// Output: 0
Expand Down Expand Up @@ -241,3 +238,61 @@ func ExampleGlideClusterClient_ConfigResetStatWithOptions() {

// Output: OK
}

func ExampleGlideClusterClient_ConfigSet() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
configParam := map[string]string{"timeout": "1000", "maxmemory": "1GB"}
result, err := client.ConfigSet(configParam)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)

// Output:
// OK
}

func ExampleGlideClusterClient_ConfigSetWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
opts := options.RouteOption{Route: config.RandomRoute}
configParam := map[string]string{"timeout": "1000", "maxmemory": "1GB"}
result, err := client.ConfigSetWithOptions(configParam, opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)

// Output:
// OK
}

func ExampleGlideClusterClient_ConfigGet() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
configParamSet := map[string]string{"timeout": "1000"}
client.ConfigSet(configParamSet)
configParamGet := []string{"timeout"}
result, err := client.ConfigGet(configParamGet)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result.MultiValue())

// Output:
// map[timeout:1000]
}

func ExampleGlideClusterClient_ConfigGetWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
opts := options.RouteOption{Route: config.RandomRoute}
configParamSet := map[string]string{"timeout": "1000"}
client.ConfigSetWithOptions(configParamSet, opts)
configParamGet := []string{"timeout"}
result, err := client.ConfigGetWithOptions(configParamGet, opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result.MultiValue())

// Output:
// map[timeout:1000]
}
45 changes: 45 additions & 0 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package integTest

import (
"fmt"
"math/rand"
"strings"

Expand Down Expand Up @@ -1238,3 +1239,47 @@ func (suite *GlideTestSuite) TestConfigResetStatWithOptions() {
opts = options.RouteOption{Route: route}
suite.verifyOK(client.ConfigResetStatWithOptions(opts))
}

func (suite *GlideTestSuite) TestConfigSetGet() {
client := suite.defaultClusterClient()
t := suite.T()
configParam := map[string]string{"timeout": "1000"}
suite.verifyOK(client.ConfigSet(configParam))
configGetParam := []string{"timeout"}
resp, err := client.ConfigGet(configGetParam)
assert.NoError(t, err)
assert.Contains(t, strings.ToLower(fmt.Sprint(resp)), strings.ToLower("timeout"))
}

func (suite *GlideTestSuite) TestConfigSetGetWithOptions() {
client := suite.defaultClusterClient()
t := suite.T()
// ConfigResetStat with option or with multiple options without route
opts := options.RouteOption{Route: nil}
configParam := map[string]string{"timeout": "1000"}
suite.verifyOK(client.ConfigSetWithOptions(configParam, opts))
configGetParam := []string{"timeout"}
resp, err := client.ConfigGetWithOptions(configGetParam, opts)
assert.NoError(t, err)
assert.Contains(t, strings.ToLower(fmt.Sprint(resp)), strings.ToLower("timeout"))

// same sections with random route
route := config.Route(config.RandomRoute)
opts = options.RouteOption{Route: route}
suite.verifyOK(client.ConfigSetWithOptions(configParam, opts))
resp, err = client.ConfigGetWithOptions(configGetParam, opts)
assert.NoError(t, err)
assert.Contains(t, strings.ToLower(fmt.Sprint(resp)), strings.ToLower("timeout"))

// default sections, multi node route
route = config.Route(config.AllPrimaries)
opts = options.RouteOption{Route: route}
suite.verifyOK(client.ConfigSetWithOptions(configParam, opts))
resp, err = client.ConfigGetWithOptions(configGetParam, opts)
assert.NoError(t, err)
assert.True(t, resp.IsMultiValue())
for _, messages := range resp.MultiValue() {
mapString := fmt.Sprint(messages)
assert.Contains(t, strings.ToLower(mapString), strings.ToLower("timeout"))
}
}
Loading