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

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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
15 changes: 15 additions & 0 deletions go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,18 @@ func (client *GlideClient) PingWithOptions(pingOptions options.PingOptions) (str
}
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)
}
37 changes: 37 additions & 0 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,40 @@ 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
// The command will be routed a random node, unless `Route` in `routeOptions` is provided.
//
// 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
// The command will be routed a random node, unless `Route` in `routeOptions` is provided.
//
// 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 @@ -17,4 +17,8 @@ type ServerManagementClusterCommands interface {
TimeWithOptions(routeOption options.RouteOption) (ClusterValue[[]string], error)

DBSizeWithOptions(routeOption options.RouteOption) (int64, 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 @@ -82,3 +82,26 @@ func ExampleGlideClusterClient_DBSizeWithOptions() {

// Output: 0
}

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 @@ -25,4 +25,6 @@ type ServerManagementCommands interface {
DBSize() (int64, error)

Time() ([]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 @@ -113,3 +113,15 @@ func ExampleGlideClient_InfoWithOptions() {

// Output: response is of type string
}

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 @@ -729,3 +729,28 @@ func (suite *GlideTestSuite) TestClusterScanWithDifferentTypes() {
assert.NotContains(t, allKeys, elem)
}
}

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 @@ -516,3 +516,8 @@ func (suite *GlideTestSuite) TestTime_Error() {
assert.Nil(suite.T(), results)
assert.IsType(suite.T(), &errors.ClosingError{}, err)
}

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