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 DBSize Server Management Cluster #2995

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d0b68b2
Implement DBSize Server Management Cluster
EdricCua Jan 23, 2025
f8c079b
Fix docs
EdricCua Jan 27, 2025
647ace3
Fix docs
EdricCua Jan 27, 2025
ce21c43
ORT- Add resolutions for hybrid-node-tests and bump versions (#2987)
BoazBD Jan 23, 2025
ce9d639
Go: Implement Server Management Command DBSize (#2991)
EdricCua Jan 23, 2025
b3d24c4
GO: Implement Copy Command (#2980)
EdricCua Jan 23, 2025
9a91407
Moved documentation comments to base_client file and made changes to …
edlng Jan 24, 2025
3dba55c
quickfix of changing glideClient to become GlideClient (#3000)
edlng Jan 24, 2025
30c7d4e
Go: Add command XRange and XRevRange (#2989)
tjzhang-BQ Jan 24, 2025
9511625
Go: Added config folder for request_routing_config_test.go and errors…
niharikabhavaraju Jan 24, 2025
d2e2dd7
Merge remote-tracking branch 'origin' into Go-DBSize-ServerManagement…
EdricCua Jan 28, 2025
5c19e0a
Merge remote-tracking branch 'origin' into Go-DBSize-ServerManagement…
EdricCua Jan 28, 2025
329c906
Implement DBSize Cluster
EdricCua Jan 28, 2025
b5c1f36
Implement DBSize Cluster
EdricCua Jan 28, 2025
4978dff
Implement DBSize Cluster
EdricCua Jan 28, 2025
30ed5a2
Implement DBSize Cluster
EdricCua Jan 28, 2025
277d12c
Implement DBSize Cluster
EdricCua Jan 28, 2025
724f071
Implement DBSize Cluster
EdricCua Jan 28, 2025
60fd222
Implement DBSize Cluster
EdricCua Jan 28, 2025
0507f01
Merge remote-tracking branch 'origin' into Go-DBSize-ServerManagement…
EdricCua Jan 28, 2025
5bd1d69
Fix merge conflict
EdricCua Jan 28, 2025
8c5fed7
Fix merge conflict
EdricCua Jan 28, 2025
695cd77
Fix review comment
EdricCua Jan 28, 2025
ec183a4
Fix docs for RouteOption
EdricCua Jan 29, 2025
88b9bf1
Fix merge conflict
EdricCua Jan 30, 2025
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
30 changes: 30 additions & 0 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ package api
// #include "../lib.h"
import "C"

import (
"github.com/valkey-io/valkey-glide/go/glide/api/options"
)

// GlideClusterClient interface compliance check.
var _ GlideClusterClientCommands = (*GlideClusterClient)(nil)

// GlideClusterClientCommands is a client used for connection in cluster mode.
type GlideClusterClientCommands interface {
BaseClient
GenericClusterCommands
ServerManagementClusterCommands
}

// GlideClusterClient implements cluster mode operations by extending baseClient functionality.
Expand Down Expand Up @@ -69,3 +74,28 @@ func (client *GlideClusterClient) CustomCommand(args []string) (ClusterValue[int
}
return CreateClusterValue(data), nil
}

// Returns the number of keys in the currently selected database.
EdricCua marked this conversation as resolved.
Show resolved Hide resolved
//
// Return value:
//
// The number of keys in the currently selected database.
EdricCua marked this conversation as resolved.
Show resolved Hide resolved
//
// 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
}
9 changes: 9 additions & 0 deletions go/api/options/route_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

package options

import "github.com/valkey-io/valkey-glide/go/glide/api/config"

type RouteOption struct {
EdricCua marked this conversation as resolved.
Show resolved Hide resolved
Route config.Route
}
14 changes: 14 additions & 0 deletions go/api/server_management_cluster_commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

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.
//
// See [valkey.io] for details.
//
// [valkey.io]: https://valkey.io/commands/#server
type ServerManagementClusterCommands interface {
DBSizeWithOptions(routeOption options.RouteOption) (int64, error)
}
13 changes: 13 additions & 0 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"

"github.com/stretchr/testify/assert"
"github.com/valkey-io/valkey-glide/go/glide/api/config"
"github.com/valkey-io/valkey-glide/go/glide/api/options"
)

func (suite *GlideTestSuite) TestClusterCustomCommandInfo() {
Expand All @@ -27,3 +29,14 @@ func (suite *GlideTestSuite) TestClusterCustomCommandEcho() {
// ECHO is routed to a single random node
assert.Equal(suite.T(), "GO GLIDE GO", result.Value().(string))
}

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))
}
Loading