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 ConfigResetStat #3121

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Go: Add password update api ([#3346](https://github.com/valkey-io/valkey-glide/pull/3346))
* Go: Add `GeoHash` ([#3439](https://github.com/valkey-io/valkey-glide/pull/3439))
* Go/Core: Move FFI to a dedicated folder for reusability ([#3372](https://github.com/valkey-io/valkey-glide/pull/3372))
* Go: Add `Config Reset Stat` ([#3121](https://github.com/valkey-io/valkey-glide/pull/3121))

#### Breaking Changes

Expand Down
15 changes: 15 additions & 0 deletions go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,18 @@ func (client *GlideClient) FlushDBWithOptions(mode options.FlushMode) (string, e
}
return handleStringResponse(result)
}

// Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM.
//
// Return value:
//
// OK to confirm that the statistics were successfully reset.
//
// [valkey.io]: https://valkey.io/commands/config-resetstat/
func (client *GlideClient) ConfigResetStat() (string, error) {
response, err := client.executeCommand(C.ConfigResetStat, []string{})
if err != nil {
return DefaultStringResponse, err
}
return handleStringResponse(response)
}
35 changes: 35 additions & 0 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,38 @@ func (client *GlideClusterClient) ScanWithOptions(
nextCursor, keys, err := handleScanResponse(response)
return *options.NewClusterScanCursorWithId(nextCursor), keys, err
}

// Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM
//
// Return value:
//
// OK to confirm that the statistics were successfully reset.
//
// [valkey.io]: https://valkey.io/commands/config-resetstat/
func (client *GlideClusterClient) ConfigResetStat() (string, error) {
response, err := client.executeCommand(C.ConfigResetStat, []string{})
if err != nil {
return DefaultStringResponse, err
}
return handleStringResponse(response)
}

// Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM.
//
// Parameters:
//
// route - Specifies the routing configuration for the command. The client will route the
// command to the nodes defined by route.
//
// Return value:
//
// OK to confirm that the statistics were successfully reset.
//
// [valkey.io]: https://valkey.io/commands/config-resetstat/
func (client *GlideClusterClient) ConfigResetStatWithOptions(opts options.RouteOption) (string, error) {
response, err := client.executeCommandWithRoute(C.ConfigResetStat, []string{}, opts.Route)
if err != nil {
return DefaultStringResponse, err
}
return handleStringResponse(response)
}
4 changes: 4 additions & 0 deletions go/api/server_management_cluster_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ type ServerManagementClusterCommands interface {
FlushDB() (string, error)

FlushDBWithOptions(options options.FlushClusterOptions) (string, error)

ConfigResetStat() (string, error)

ConfigResetStatWithOptions(routeOption options.RouteOption) (string, error)
}
23 changes: 23 additions & 0 deletions go/api/server_management_cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,26 @@ func ExampleGlideClusterClient_FlushDBWithOptions() {

// Output: OK
}

func ExampleGlideClusterClient_ConfigResetStat() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
result, err := client.ConfigResetStat()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)

// Output: OK
}

func ExampleGlideClusterClient_ConfigResetStatWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
opts := options.RouteOption{Route: nil}
result, err := client.ConfigResetStatWithOptions(opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)

// Output: OK
}
2 changes: 2 additions & 0 deletions go/api/server_management_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ type ServerManagementCommands interface {
FlushDB() (string, error)

FlushDBWithOptions(mode options.FlushMode) (string, error)

ConfigResetStat() (string, error)
}
12 changes: 12 additions & 0 deletions go/api/server_management_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,15 @@ func ExampleGlideClient_FlushDBWithOptions() {

// Output: OK
}

func ExampleGlideClient_ConfigResetStat() {
var client *GlideClient = getExampleGlideClient() // example helper function
response, err := client.ConfigResetStat()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(response)

// Output:
// OK
}
25 changes: 25 additions & 0 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,3 +1099,28 @@ func (suite *GlideTestSuite) TestUpdateConnectionPasswordCluster_ImmediateAuthWr
_, err = adminClient.CustomCommand([]string{"CONFIG", "SET", "requirepass", ""})
assert.NoError(suite.T(), err)
}

func (suite *GlideTestSuite) TestConfigResetStatCluster() {
client := suite.defaultClusterClient()

// ConfigResetStat with option or with multiple options without route
suite.verifyOK(client.ConfigResetStat())
}

func (suite *GlideTestSuite) TestConfigResetStatWithOptions() {
client := suite.defaultClusterClient()

// ConfigResetStat with option or with multiple options without route
opts := options.RouteOption{Route: nil}
suite.verifyOK(client.ConfigResetStatWithOptions(opts))

// same sections with random route
route := config.Route(config.RandomRoute)
opts = options.RouteOption{Route: route}
suite.verifyOK(client.ConfigResetStatWithOptions(opts))

// default sections, multi node route
route = config.Route(config.AllPrimaries)
opts = options.RouteOption{Route: route}
suite.verifyOK(client.ConfigResetStatWithOptions(opts))
}
5 changes: 5 additions & 0 deletions go/integTest/standalone_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,8 @@ func (suite *GlideTestSuite) TestUpdateConnectionPassword_ImmediateAuthWrongPass
_, err = adminClient.ConfigSet(map[string]string{"requirepass": ""})
assert.NoError(suite.T(), err)
}

func (suite *GlideTestSuite) TestConfigResetStat() {
client := suite.defaultClient()
suite.verifyOK(client.ConfigResetStat())
}
Loading