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 update pass #2687

Open
wants to merge 8 commits into
base: release-1.2
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Go: Adding support for replacing connection configured password ([#2687](https://github.com/valkey-io/valkey-glide/pull/2687))
* Node, Python: Adding support for replacing connection configured password ([#2651](https://github.com/valkey-io/valkey-glide/pull/2651))
* Node: Add FT._ALIASLIST command([#2652](https://github.com/valkey-io/valkey-glide/pull/2652))
* Python: Python: `FT._ALIASLIST` command added([#2638](https://github.com/valkey-io/valkey-glide/pull/2638))
Expand Down
73 changes: 73 additions & 0 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ func (client *baseClient) executeCommand(requestType C.RequestType, args []strin
return payload.value, nil
}

func (client *baseClient) executeCommandRequest(message proto.Message) (*C.struct_CommandResponse, error) {
msg, err := proto.Marshal(message)
if err != nil {
return nil, err
}

resultChannel := make(chan payload)
resultChannelPtr := uintptr(unsafe.Pointer(&resultChannel))

requestBytes := C.CBytes(msg)
requestLen := len(msg)

C.send_command_request(
client.coreClient,
C.uintptr_t(resultChannelPtr),
(*C.uchar)(requestBytes),
C.uintptr_t(requestLen),
)
payload := <-resultChannel
if payload.error != nil {
return nil, payload.error
}

return payload.value, nil
}

// Zero copying conversion from go's []string into C pointers
func toCStrings(args []string) ([]C.uintptr_t, []C.ulong) {
cStrings := make([]C.uintptr_t, len(args))
Expand Down Expand Up @@ -540,3 +566,50 @@ func (client *baseClient) PingWithMessage(message string) (string, error) {
}
return response.Value(), nil
}

func (client *baseClient) ConfigGet(args []string) (map[Result[string]]Result[string], error) {
res, err := client.executeCommand(C.ConfigGet, args)
if err != nil {
return nil, err
}

return handleStringToStringMapResponse(res)
}

func (client *baseClient) ConfigSet(parameters map[string]string) (Result[string], error) {
result, err := client.executeCommand(C.ConfigSet, utils.MapToString(parameters))
if err != nil {
return CreateNilStringResult(), err
}

return handleStringResponse(result)
}

func (client *baseClient) CustomCommand(args []string) (interface{}, error) {
res, err := client.executeCommand(C.CustomCommand, args)
if err != nil {
return nil, err
}

resString, err := handleStringOrNullResponse(res)
if err != nil {
return nil, err
}

return resString.Value(), err
}

func (client *baseClient) UpdateConnectionPassword(password *string, reAuth bool) (Result[string], error) {
request := protobuf.CommandRequest{
Command: &protobuf.CommandRequest_UpdateConnectionPassword{
UpdateConnectionPassword: &protobuf.UpdateConnectionPassword{Password: password, ReAuth: reAuth},
},
}

res, err := client.executeCommandRequest(&request)
if err != nil {
return CreateNilStringResult(), err
}

return handleStringResponse(res)
}
194 changes: 194 additions & 0 deletions go/api/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,4 +731,198 @@ type ConnectionManagementCommands interface {
//
// [valkey.io]: https://valkey.io/commands/ping/
PingWithMessage(message string) (string, error)

// UpdateConnectionPassword updates the connection password and optionally re-authenticates.
//
// See [valkey.io] for details.
//
// Parameters:
// password - The new password to update, or null to remove the password.
// reAuth - If true, re-authenticates the connection with the new password.
//
// Return value:
// A Result containing the operation status, or an error if the password replacement fails.
//
// For example:
// result, err := client.UpdateConnectionPassword("newpass123", true)
// // result equals api.CreateStringResult("OK")
//
// [valkey.io]: https://valkey.io/commands/auth/
UpdateConnectionPassword(password *string, reAuth bool) (Result[string], error)
}

// ServerManagementClusterCommands supports commands and transactions for the "Server Management Commands" group for
// a cluster client.
//
// See [valkey.io] for details.
//
// [valkey.io]: https://valkey.io/commands/?group=server
type ServerManagementClusterCommands interface {
// ConfigGet retrieves the values of configuration parameters.
// The command will be sent to a random node.
//
// See [valkey.io] for details.
//
// Parameters:
// parameters - An array of configuration parameter names to retrieve values for
//
// Returns:
// - map[Result[string]]Result[string]: A map of values corresponding to the configuration parameters
// - error: An error if the operation fails
//
// For example:
// configParams, err := client.ConfigGet([]string{"timeout", "maxmemory"})
// // configParams["timeout"].Value() equals "1000"
// // configParams["maxmemory"].Value() equals "1GB"
//
// [valkey.io]: https://valkey.io/commands/config-get/
ConfigGet(args []string) (map[Result[string]]Result[string], error)

// ConfigSet sets configuration parameters to the specified values.
// The command will be sent to all nodes.
//
// See [valkey.io] for details.
//
// Parameters:
// parameters - A map consisting of configuration parameters and their respective values to set
//
// Returns:
// - Result[string]: "OK" if all configurations have been successfully set
// - error: An error if the operation fails
//
// For example:
// resp, err := client.ConfigSet(map[string]string{
// "timeout": "1000",
// "maxmemory": "1GB",
// })
// // resp.Value() equals "OK"
//
// [valkey.io]: https://valkey.io/commands/config-set/
ConfigSet(parameters map[string]string) (Result[string], error)

// CustomCommand executes a custom server command with the provided arguments.
//
// See [valkey.io] for details.
//
// Parameters:
// args - A slice containing the command name and its arguments.
//
// Return value:
// An interface{} that must be type asserted to the expected return type, or an error if the command execution fails.
//
// For example:
// result, err := client.CustomCommand([]string{"MYCOMMAND", "arg1", "arg2"})
// // Assuming command returns a string
// // strResult := result.(string)
// // strResult equals "command response"
//
// [valkey.io]: https://valkey.io/commands/
CustomCommand(args []string) (interface{}, error)
}

// ServerManagementCommands supports commands and transactions for the "Server Management" group for a
// standalone client.
//
// See [valkey.io] for details.
//
// [valkey.io]: https://valkey.io/commands/?group=server
type ServerManagementCommands interface {
// ConfigGet retrieves the values of configuration parameters.
//
// See [valkey.io] for details.
//
// Parameters:
// parameters - An array of configuration parameter names to retrieve values for
//
// Returns:
// - map[Result[string]]Result[string]: A map of values corresponding to the configuration parameters
// - error: An error if the operation fails
//
// For example:
// configParams, err := client.ConfigGet([]string{"timeout", "maxmemory"})
// // configParams["timeout"].Value() equals "1000"
// // configParams["maxmemory"].Value() equals "1GB"
//
// [valkey.io]: https://valkey.io/commands/config-get/
ConfigGet(args []string) (map[Result[string]]Result[string], error)

// ConfigSet sets configuration parameters to the specified values.
//
// See [valkey.io] for details.
//
// Parameters:
// parameters - A map consisting of configuration parameters and their respective values to set
//
// Returns:
// - Result[string]: "OK" if all configurations have been successfully set
// - error: An error if the operation fails
//
// For example:
// resp, err := client.ConfigSet(map[string]string{
// "timeout": "1000",
// "maxmemory": "1GB",
// })
// // resp.Value() equals "OK"
//
// [valkey.io]: https://valkey.io/commands/config-set/
ConfigSet(parameters map[string]string) (Result[string], error)
}

// GenericClusterCommands supports generic commands for cluster mode.
//
// See [valkey.io] for details.
//
// [valkey.io]: https://valkey.io/commands/?group=generic
type GenericClusterCommands interface {
// CustomCommand executes a single command without checking inputs. Every part of the command, including subcommands,
// should be added as a separate value in args. The command will be routed automatically based on the passed
// command's default request policy.
//
// See [wiki] for details.
//
// Parameters:
// args - Arguments for the custom command including the command name. For example: ["ping"]
//
// Returns:
// - interface{}: The returned value for the custom command. For example: "PONG" for ping command
// - error: An error if the operation fails
//
// For example:
// resp, err := client.CustomCommand([]string{"ping"})
// // If successful:
// // resp equals "PONG"
// // err equals nil
//
// [wiki]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command
CustomCommand(args []string) (interface{}, error)
}

// GenericCommands supports generic commands and transactions for standalone mode.
//
// See [valkey.io] for details.
//
// [valkey.io]: https://valkey.io/commands/?group=generic
type GenericCommands interface {
// CustomCommand executes a single command without checking inputs. Every part of the command,
// including subcommands, should be added as a separate value in args.
//
// See [wiki] for details.
//
// Parameters:
// args - Arguments for the custom command
//
// Returns:
// - interface{}: The returned value for the custom command
// - error: An error if the operation fails
//
// For example:
// // Simple ping command
// resp, err := client.CustomCommand([]string{"ping", "GLIDE"})
// // resp equals "GLIDE"
//
// // Get a list of all pub/sub clients
// result, err := client.CustomCommand([]string{"CLIENT", "LIST", "TYPE", "PUBSUB"})
//
// [wiki]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command
CustomCommand(args []string) (interface{}, error)
}
Loading