Skip to content

Commit

Permalink
Go: Implement DBSize Server Management Cluster (#2995)
Browse files Browse the repository at this point in the history
* Implement DBSize Server Management Cluster

Signed-off-by: EdricCua <[email protected]>

* Fix docs

Signed-off-by: EdricCua <[email protected]>

* Fix docs

Signed-off-by: EdricCua <[email protected]>

* 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 <[email protected]>

* format

Signed-off-by: BoazBD <[email protected]>

---------

Signed-off-by: BoazBD <[email protected]>
Signed-off-by: EdricCua <[email protected]>

* Go: Implement Server Management Command DBSize (#2991)

* Implement DBSize Command

Signed-off-by: EdricCua <[email protected]>

* GO: Implement Copy Command (#2980)

* Implement Copy Command

Signed-off-by: EdricCua <[email protected]>

* 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 <[email protected]>
Signed-off-by: EdricCua <[email protected]>

* quickfix of changing glideClient to become GlideClient (#3000)

Signed-off-by: Edward Liang <[email protected]>
Signed-off-by: EdricCua <[email protected]>

* Go: Add command XRange and XRevRange (#2989)

* Go: Add command XRange and XRevRange

Signed-off-by: TJ Zhang <[email protected]>
Signed-off-by: EdricCua <[email protected]>

* 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 <[email protected]>

* Fixed code review changes

Signed-off-by: Niharika Bhavaraju <[email protected]>

* Added Time command (cluster)

Signed-off-by: Niharika Bhavaraju <[email protected]>

* Fixed code review comments

Signed-off-by: Niharika Bhavaraju <[email protected]>

* Added route,errors folders

Signed-off-by: Niharika Bhavaraju <[email protected]>

* Fixed failing tests

Signed-off-by: Niharika Bhavaraju <[email protected]>

---------

Signed-off-by: Niharika Bhavaraju <[email protected]>
Signed-off-by: EdricCua <[email protected]>

* Implement DBSize Cluster

Signed-off-by: EdricCua <[email protected]>

* Implement DBSize Cluster

Signed-off-by: EdricCua <[email protected]>

* Implement DBSize Cluster

Signed-off-by: EdricCua <[email protected]>

* Implement DBSize Cluster

Signed-off-by: EdricCua <[email protected]>

* Implement DBSize Cluster

Signed-off-by: EdricCua <[email protected]>

* Implement DBSize Cluster

Signed-off-by: EdricCua <[email protected]>

* Implement DBSize Cluster

Signed-off-by: EdricCua <[email protected]>

* Fix merge conflict

Signed-off-by: EdricCua <[email protected]>

* Fix review comment

Signed-off-by: EdricCua <[email protected]>

* Fix docs for RouteOption

Signed-off-by: EdricCua <[email protected]>

---------

Signed-off-by: EdricCua <[email protected]>
Signed-off-by: BoazBD <[email protected]>
Signed-off-by: Edward Liang <[email protected]>
Signed-off-by: TJ Zhang <[email protected]>
Signed-off-by: Niharika Bhavaraju <[email protected]>
Co-authored-by: BoazBD <[email protected]>
Co-authored-by: Edward Liang <[email protected]>
Co-authored-by: tjzhang-BQ <[email protected]>
Co-authored-by: Niharika Bhavaraju <[email protected]>
  • Loading branch information
5 people authored Jan 31, 2025
1 parent 41f423e commit e181ca1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
25 changes: 25 additions & 0 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
16 changes: 16 additions & 0 deletions go/api/options/db_size_options.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions go/api/options/route_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion go/api/server_management_cluster_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand All @@ -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)
}
11 changes: 11 additions & 0 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit e181ca1

Please sign in to comment.