From e181ca128281a4455b7254c0a5afdafe5b5d50bc Mon Sep 17 00:00:00 2001 From: Edric Cuartero Date: Fri, 31 Jan 2025 23:44:28 +0800 Subject: [PATCH] Go: Implement DBSize Server Management Cluster (#2995) * Implement DBSize Server Management Cluster Signed-off-by: EdricCua * Fix docs Signed-off-by: EdricCua * Fix docs Signed-off-by: EdricCua * ORT- Add resolutions for hybrid-node-tests and bump versions (#2987) * add resolutions for hybrid-node-tests and bump ORT versions Signed-off-by: BoazBD * format Signed-off-by: BoazBD --------- Signed-off-by: BoazBD Signed-off-by: EdricCua * Go: Implement Server Management Command DBSize (#2991) * Implement DBSize Command Signed-off-by: EdricCua * GO: Implement Copy Command (#2980) * Implement Copy Command Signed-off-by: EdricCua * Moved documentation comments to base_client file and made changes to GlideClient for pkgsite to work (#2981) * moved docs from interfaces to base client Signed-off-by: Edward Liang Signed-off-by: EdricCua * quickfix of changing glideClient to become GlideClient (#3000) Signed-off-by: Edward Liang Signed-off-by: EdricCua * Go: Add command XRange and XRevRange (#2989) * Go: Add command XRange and XRevRange Signed-off-by: TJ Zhang Signed-off-by: EdricCua * Go: Added config folder for request_routing_config_test.go and errors folder for errors.go (#2996) * Implemented Time Command Signed-off-by: Niharika Bhavaraju * Fixed code review changes Signed-off-by: Niharika Bhavaraju * Added Time command (cluster) Signed-off-by: Niharika Bhavaraju * Fixed code review comments Signed-off-by: Niharika Bhavaraju * Added route,errors folders Signed-off-by: Niharika Bhavaraju * Fixed failing tests Signed-off-by: Niharika Bhavaraju --------- Signed-off-by: Niharika Bhavaraju Signed-off-by: EdricCua * Implement DBSize Cluster Signed-off-by: EdricCua * Implement DBSize Cluster Signed-off-by: EdricCua * Implement DBSize Cluster Signed-off-by: EdricCua * Implement DBSize Cluster Signed-off-by: EdricCua * Implement DBSize Cluster Signed-off-by: EdricCua * Implement DBSize Cluster Signed-off-by: EdricCua * Implement DBSize Cluster Signed-off-by: EdricCua * Fix merge conflict Signed-off-by: EdricCua * Fix review comment Signed-off-by: EdricCua * Fix docs for RouteOption Signed-off-by: EdricCua --------- Signed-off-by: EdricCua Signed-off-by: BoazBD Signed-off-by: Edward Liang Signed-off-by: TJ Zhang Signed-off-by: Niharika Bhavaraju Co-authored-by: BoazBD <50696333+BoazBD@users.noreply.github.com> Co-authored-by: Edward Liang <76571219+edlng@users.noreply.github.com> Co-authored-by: tjzhang-BQ <111323543+tjzhang-BQ@users.noreply.github.com> Co-authored-by: Niharika Bhavaraju <31915502+niharikabhavaraju@users.noreply.github.com> --- go/api/glide_cluster_client.go | 25 ++++++++++++++++++++ go/api/options/db_size_options.go | 16 +++++++++++++ go/api/options/route_options.go | 3 +++ go/api/server_management_cluster_commands.go | 4 +++- go/integTest/cluster_commands_test.go | 11 +++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 go/api/options/db_size_options.go diff --git a/go/api/glide_cluster_client.go b/go/api/glide_cluster_client.go index eb967bced1..9c72a86562 100644 --- a/go/api/glide_cluster_client.go +++ b/go/api/glide_cluster_client.go @@ -298,3 +298,28 @@ func (client *GlideClusterClient) TimeWithOptions(opts options.RouteOption) (Clu } return handleTimeClusterResponse(result) } + +// Returns the number of keys in the database. +// +// Return value: +// +// The number of keys in the database. +// +// Example: +// +// route := api.SimpleNodeRoute(api.RandomRoute) +// options := options.NewDBOptionsBuilder().SetRoute(route) +// result, err := client.DBSizeWithOption(route) +// if err != nil { +// // handle error +// } +// fmt.Println(result) // Output: 1 +// +// [valkey.io]: https://valkey.io/commands/dbsize/ +func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (int64, error) { + result, err := client.executeCommandWithRoute(C.DBSize, []string{}, opts.Route) + if err != nil { + return defaultIntResponse, err + } + return handleIntResponse(result) +} diff --git a/go/api/options/db_size_options.go b/go/api/options/db_size_options.go new file mode 100644 index 0000000000..7ebdb6a6de --- /dev/null +++ b/go/api/options/db_size_options.go @@ -0,0 +1,16 @@ +package options + +import "github.com/valkey-io/valkey-glide/go/glide/api/config" + +type DBSizeOptions struct { + Route config.Route +} + +func NewTimeOptionsBuilder() *DBSizeOptions { + return &DBSizeOptions{} +} + +func (dbSizeOptions *DBSizeOptions) SetRoute(route config.Route) *DBSizeOptions { + dbSizeOptions.Route = route + return dbSizeOptions +} diff --git a/go/api/options/route_options.go b/go/api/options/route_options.go index 1f1cbd2b20..177f470529 100644 --- a/go/api/options/route_options.go +++ b/go/api/options/route_options.go @@ -4,6 +4,9 @@ package options import "github.com/valkey-io/valkey-glide/go/glide/api/config" +// An extension to command option types with Routes type RouteOption struct { + // Specifies the routing configuration for the command. + // The client will route the command to the nodes defined by `route`. Route config.Route } diff --git a/go/api/server_management_cluster_commands.go b/go/api/server_management_cluster_commands.go index b49737c05b..87a04e2813 100644 --- a/go/api/server_management_cluster_commands.go +++ b/go/api/server_management_cluster_commands.go @@ -4,7 +4,7 @@ package api import "github.com/valkey-io/valkey-glide/go/glide/api/options" -// ServerManagementClusterCommands supports commands for the "Server Management Commands" group for cluster client. +// ServerManagementCommands supports commands for the "Server Management" group for a cluster client. // // See [valkey.io] for details. // @@ -15,4 +15,6 @@ type ServerManagementClusterCommands interface { InfoWithOptions(options ClusterInfoOptions) (ClusterValue[string], error) TimeWithOptions(routeOption options.RouteOption) (ClusterValue[[]string], error) + + DBSizeWithOptions(routeOption options.RouteOption) (int64, error) } diff --git a/go/integTest/cluster_commands_test.go b/go/integTest/cluster_commands_test.go index 52bca71abb..19a8167dce 100644 --- a/go/integTest/cluster_commands_test.go +++ b/go/integTest/cluster_commands_test.go @@ -244,3 +244,14 @@ func (suite *GlideTestSuite) TestTimeWithInvalidRoute() { assert.True(suite.T(), result.IsEmpty()) assert.Empty(suite.T(), result.SingleValue()) } + +func (suite *GlideTestSuite) TestDBSizeRandomRoute() { + client := suite.defaultClusterClient() + route := config.Route(config.RandomRoute) + options := options.RouteOption{Route: route} + result, err := client.DBSizeWithOptions(options) + assert.NoError(suite.T(), err) + assert.NotNil(suite.T(), result) + assert.NotEmpty(suite.T(), result) + assert.Greater(suite.T(), result, int64(0)) +}