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

Merged
Merged
Changes from 1 commit
Commits
Show all changes
26 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
2b45648
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
Prev Previous commit
Next Next commit
Fix merge conflict
Signed-off-by: EdricCua <ecuartero@google.com>
EdricCua committed Jan 30, 2025
commit 88b9bf1d48c6a9d0aa6afc5686bfb2ac1ae6db90
101 changes: 101 additions & 0 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ package api
import "C"

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

@@ -166,6 +167,106 @@ func (client *GlideClusterClient) InfoWithOptions(options ClusterInfoOptions) (C
return createClusterSingleValue[string](data), nil
}

// CustomCommandWithRoute executes a single command, specified by args, without checking inputs. Every part of the command,
// including the command name and subcommands, should be added as a separate value in args. The returning value depends on
// the executed command.
//
// See [Valkey GLIDE Wiki] for details on the restrictions and limitations of the custom command API.
//
// Parameters:
//
// args - Arguments for the custom command including the command name.
// route - Specifies the routing configuration for the command. The client will route the
// command to the nodes defined by route.
//
// Return value:
//
// The returning value depends on the executed command and route.
//
// For example:
//
// route := config.SimpleNodeRoute(config.RandomRoute)
// result, err := client.CustomCommandWithRoute([]string{"ping"}, route)
// result.SingleValue().(string): "PONG"
//
// [Valkey GLIDE Wiki]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command
func (client *GlideClusterClient) CustomCommandWithRoute(
args []string,
route config.Route,
) (ClusterValue[interface{}], error) {
res, err := client.executeCommandWithRoute(C.CustomCommand, args, route)
if err != nil {
return createEmptyClusterValue[interface{}](), err
}
data, err := handleInterfaceResponse(res)
if err != nil {
return createEmptyClusterValue[interface{}](), err
}
return createClusterValue[interface{}](data), nil
}

// Pings the server.
// The command will be routed to all primary nodes.
//
// Return value:
//
// Returns "PONG".
//
// For example:
//
// result, err := clusterClient.Ping()
// fmt.Println(result) // Output: PONG
//
// [valkey.io]: https://valkey.io/commands/ping/
func (client *GlideClusterClient) Ping() (string, error) {
result, err := client.executeCommand(C.Ping, []string{})
if err != nil {
return defaultStringResponse, err
}
return handleStringResponse(result)
}

// Pings the server.
// The command will be routed to all primary nodes, unless `Route` is provided in `pingOptions`.
//
// Parameters:
//
// pingOptions - The PingOptions type.
//
// Return value:
//
// Returns the copy of message.
//
// For example:
//
// route := config.Route(config.RandomRoute)
// opts := options.ClusterPingOptions{
// PingOptions: &options.PingOptions{
// Message: "Hello",
// },
// Route: &route,
// }
// result, err := clusterClient.PingWithOptions(opts)
// fmt.Println(result) // Output: Hello
//
// [valkey.io]: https://valkey.io/commands/ping/
func (client *GlideClusterClient) PingWithOptions(pingOptions options.ClusterPingOptions) (string, error) {
if pingOptions.Route == nil {
response, err := client.executeCommand(C.Ping, pingOptions.ToArgs())
if err != nil {
return defaultStringResponse, err
}
return handleStringResponse(response)
}

response, err := client.executeCommandWithRoute(C.Ping, pingOptions.ToArgs(), *pingOptions.Route)
if err != nil {
return defaultStringResponse, err
}

return handleStringResponse(response)
}

// Returns the number of keys in the database.
//
// Return value:
79 changes: 79 additions & 0 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
@@ -108,6 +108,85 @@ func (suite *GlideTestSuite) TestInfoCluster() {
}
}

func (suite *GlideTestSuite) TestClusterCustomCommandWithRoute_Info() {
client := suite.defaultClusterClient()
route := config.SimpleNodeRoute(config.AllPrimaries)
result, err := client.CustomCommandWithRoute([]string{"INFO"}, route)
assert.Nil(suite.T(), err)
assert.True(suite.T(), result.IsMultiValue())
multiValue := result.MultiValue()
for _, value := range multiValue {
assert.True(suite.T(), strings.Contains(value.(string), "# Stats"))
}
}

func (suite *GlideTestSuite) TestClusterCustomCommandWithRoute_Echo() {
client := suite.defaultClusterClient()
route := config.SimpleNodeRoute(config.RandomRoute)
result, err := client.CustomCommandWithRoute([]string{"ECHO", "GO GLIDE GO"}, route)
assert.Nil(suite.T(), err)
assert.True(suite.T(), result.IsSingleValue())
assert.Equal(suite.T(), "GO GLIDE GO", result.SingleValue().(string))
}

func (suite *GlideTestSuite) TestClusterCustomCommandWithRoute_InvalidRoute() {
client := suite.defaultClusterClient()
invalidRoute := config.NewByAddressRoute("invalidHost", 9999)
result, err := client.CustomCommandWithRoute([]string{"PING"}, invalidRoute)
assert.NotNil(suite.T(), err)
assert.True(suite.T(), result.IsEmpty())
}

func (suite *GlideTestSuite) TestClusterCustomCommandWithRoute_AllNodes() {
client := suite.defaultClusterClient()
route := config.SimpleNodeRoute(config.AllNodes)
result, err := client.CustomCommandWithRoute([]string{"PING"}, route)
assert.Nil(suite.T(), err)
assert.True(suite.T(), result.IsSingleValue())
assert.Equal(suite.T(), "PONG", result.SingleValue())
}

func (suite *GlideTestSuite) TestPingWithOptions_NoRoute() {
client := suite.defaultClusterClient()
options := options.ClusterPingOptions{
PingOptions: &options.PingOptions{
Message: "hello",
},
Route: nil,
}
result, err := client.PingWithOptions(options)
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), "hello", result)
}

func (suite *GlideTestSuite) TestPingWithOptions_WithRoute() {
client := suite.defaultClusterClient()
route := config.Route(config.AllNodes)
options := options.ClusterPingOptions{
PingOptions: &options.PingOptions{
Message: "hello",
},
Route: &route,
}
result, err := client.PingWithOptions(options)
assert.Nil(suite.T(), err)
assert.Equal(suite.T(), "hello", result)
}

func (suite *GlideTestSuite) TestPingWithOptions_InvalidRoute() {
client := suite.defaultClusterClient()
invalidRoute := config.Route(config.NewByAddressRoute("invalidHost", 9999))
options := options.ClusterPingOptions{
PingOptions: &options.PingOptions{
Message: "hello",
},
Route: &invalidRoute,
}
result, err := client.PingWithOptions(options)
assert.NotNil(suite.T(), err)
assert.Empty(suite.T(), result)
}

func (suite *GlideTestSuite) TestDBSizeRandomRoute() {
client := suite.defaultClusterClient()
route := config.Route(config.RandomRoute)
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.