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: Fix command options classes. #3104

Merged
merged 7 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
371 changes: 207 additions & 164 deletions go/api/base_client.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions go/api/generic_base_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ type GenericBaseCommands interface {

Expire(key string, seconds int64) (bool, error)

ExpireWithOptions(key string, seconds int64, expireCondition ExpireCondition) (bool, error)
ExpireWithOptions(key string, seconds int64, expireCondition options.ExpireCondition) (bool, error)

ExpireAt(key string, unixTimestampInSeconds int64) (bool, error)

ExpireAtWithOptions(key string, unixTimestampInSeconds int64, expireCondition ExpireCondition) (bool, error)
ExpireAtWithOptions(key string, unixTimestampInSeconds int64, expireCondition options.ExpireCondition) (bool, error)

PExpire(key string, milliseconds int64) (bool, error)

PExpireWithOptions(key string, milliseconds int64, expireCondition ExpireCondition) (bool, error)
PExpireWithOptions(key string, milliseconds int64, expireCondition options.ExpireCondition) (bool, error)

PExpireAt(key string, unixTimestampInMilliSeconds int64) (bool, error)

PExpireAtWithOptions(key string, unixTimestampInMilliSeconds int64, expireCondition ExpireCondition) (bool, error)
PExpireAtWithOptions(key string, unixTimestampInMilliSeconds int64, expireCondition options.ExpireCondition) (bool, error)

ExpireTime(key string) (int64, error)

Expand All @@ -52,7 +52,7 @@ type GenericBaseCommands interface {

Restore(key string, ttl int64, value string) (Result[string], error)

RestoreWithOptions(key string, ttl int64, value string, option *RestoreOptions) (Result[string], error)
RestoreWithOptions(key string, ttl int64, value string, option *options.RestoreOptions) (Result[string], error)

ObjectEncoding(key string) (Result[string], error)

Expand Down Expand Up @@ -80,5 +80,5 @@ type GenericBaseCommands interface {

Copy(source string, destination string) (bool, error)

CopyWithOptions(source string, destination string, option *CopyOptions) (bool, error)
CopyWithOptions(source string, destination string, option *options.CopyOptions) (bool, error)
}
20 changes: 14 additions & 6 deletions go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (client *GlideClient) Select(index int64) (string, error) {
//
// [valkey.io]: https://valkey.io/commands/info/
func (client *GlideClient) Info() (string, error) {
return client.InfoWithOptions(InfoOptions{[]Section{}})
return client.InfoWithOptions(options.InfoOptions{Sections: []options.Section{}})
}

// Gets information and statistics about the server.
Expand All @@ -194,16 +194,20 @@ func (client *GlideClient) Info() (string, error) {
//
// Example:
//
// opts := api.InfoOptions{Sections: []api.Section{api.Server}}
// opts := options.InfoOptions{Sections: []options.Section{options.Server}}
// response, err := standaloneClient.InfoWithOptions(opts)
// if err != nil {
// // handle error
// }
// fmt.Println(response)
//
// [valkey.io]: https://valkey.io/commands/info/
func (client *GlideClient) InfoWithOptions(options InfoOptions) (string, error) {
result, err := client.executeCommand(C.Info, options.toArgs())
func (client *GlideClient) InfoWithOptions(options options.InfoOptions) (string, error) {
optionArgs, err := options.ToArgs()
if err != nil {
return defaultStringResponse, err
}
result, err := client.executeCommand(C.Info, optionArgs)
if err != nil {
return defaultStringResponse, err
}
Expand Down Expand Up @@ -290,13 +294,17 @@ func (client *GlideClient) Ping() (string, error) {
//
// For example:
//
// options := options.NewPingOptionsBuilder().SetMessage("hello")
// options := options.NewPingOptions().SetMessage("hello")
// result, err := client.PingWithOptions(options)
// result: "hello"
//
// [valkey.io]: https://valkey.io/commands/ping/
func (client *GlideClient) PingWithOptions(pingOptions options.PingOptions) (string, error) {
result, err := client.executeCommand(C.Ping, pingOptions.ToArgs())
optionArgs, err := pingOptions.ToArgs()
if err != nil {
return defaultStringResponse, err
}
result, err := client.executeCommand(C.Ping, optionArgs)
if err != nil {
return defaultStringResponse, err
}
Expand Down
80 changes: 46 additions & 34 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func (client *GlideClusterClient) Info() (map[string]string, error) {
//
// Example:
//
// opts := api.ClusterInfoOptions{
// InfoOptions: &api.InfoOptions{Sections: []api.Section{api.Server}},
// Route: api.RandomRoute.ToPtr(),
// opts := options.ClusterInfoOptions{
// InfoOptions: &options.InfoOptions{Sections: []options.Section{options.Server}},
// RouteOption: &options.RouteOption{Route: config.RandomRoute},
// }
// response, err := clusterClient.InfoWithOptions(opts)
// if err != nil {
Expand All @@ -143,9 +143,13 @@ func (client *GlideClusterClient) Info() (map[string]string, error) {
// fmt.Println(response.SingleValue())
//
// [valkey.io]: https://valkey.io/commands/info/
func (client *GlideClusterClient) InfoWithOptions(options ClusterInfoOptions) (ClusterValue[string], error) {
if options.Route == nil {
response, err := client.executeCommand(C.Info, options.toArgs())
func (client *GlideClusterClient) InfoWithOptions(options options.ClusterInfoOptions) (ClusterValue[string], error) {
optionArgs, err := options.ToArgs()
if err != nil {
return createEmptyClusterValue[string](), err
}
if options.RouteOption == nil || options.RouteOption.Route == nil {
response, err := client.executeCommand(C.Info, optionArgs)
if err != nil {
return createEmptyClusterValue[string](), err
}
Expand All @@ -155,11 +159,11 @@ func (client *GlideClusterClient) InfoWithOptions(options ClusterInfoOptions) (C
}
return createClusterMultiValue[string](data), nil
}
response, err := client.executeCommandWithRoute(C.Info, options.toArgs(), *options.Route)
response, err := client.executeCommandWithRoute(C.Info, optionArgs, options.Route)
if err != nil {
return createEmptyClusterValue[string](), err
}
if (*options.Route).IsMultiNode() {
if options.Route.IsMultiNode() {
data, err := handleStringToStringMapResponse(response)
if err != nil {
return createEmptyClusterValue[string](), err
Expand Down Expand Up @@ -193,7 +197,7 @@ func (client *GlideClusterClient) InfoWithOptions(options ClusterInfoOptions) (C
//
// route := config.SimpleNodeRoute(config.RandomRoute)
// result, err := client.CustomCommandWithRoute([]string{"ping"}, route)
// result.SingleValue().(string): "PONG"
// result.SingleValue().(string): "ping"
//
// [Valkey GLIDE Wiki]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command
func (client *GlideClusterClient) CustomCommandWithRoute(
Expand Down Expand Up @@ -237,35 +241,34 @@ func (client *GlideClusterClient) Ping() (string, error) {
//
// Parameters:
//
// pingOptions - The PingOptions type.
// pingOptions - The [ClusterPingOptions] 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,
// }
// route := options.RouteOption{config.RandomRoute}
// opts := options.ClusterPingOptions{ &options.PingOptions{ "Hello" }, &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())
args, err := pingOptions.ToArgs()
if err != nil {
return defaultStringResponse, err
}
if pingOptions.RouteOption == nil || pingOptions.RouteOption.Route == nil {
response, err := client.executeCommand(C.Ping, args)
if err != nil {
return defaultStringResponse, err
}
return handleStringResponse(response)
}

response, err := client.executeCommandWithRoute(C.Ping, pingOptions.ToArgs(), *pingOptions.Route)
response, err := client.executeCommandWithRoute(C.Ping, args, pingOptions.Route)
if err != nil {
return defaultStringResponse, err
}
Expand All @@ -280,7 +283,7 @@ func (client *GlideClusterClient) PingWithOptions(pingOptions options.ClusterPin
//
// Parameters:
//
// options - The TimeOptions type.
// options - The [RouteOption] type.
//
// Return value:
//
Expand All @@ -290,11 +293,9 @@ func (client *GlideClusterClient) PingWithOptions(pingOptions options.ClusterPin
//
// Example:
//
// route := config.Route(config.RandomRoute)
// opts := options.ClusterTimeOptions{
// Route: &route,
// }
// fmt.Println(clusterResponse.SingleValue()) // Output: [1737994354 547816]
// opts := options.RouteOption{config.RandomRoute}
// response := client.TimeWithOptions(opts)
// fmt.Println(response.SingleValue()) // Output: [1737994354 547816]
//
// [valkey.io]: https://valkey.io/commands/time/
func (client *GlideClusterClient) TimeWithOptions(opts options.RouteOption) (ClusterValue[[]string], error) {
Expand All @@ -307,15 +308,18 @@ func (client *GlideClusterClient) TimeWithOptions(opts options.RouteOption) (Clu

// Returns the number of keys in the database.
//
// Parameters:
//
// options - The [RouteOption] type.
//
// 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)
// options := options.RouteOption{config.RandomRoute}
// result, err := client.DBSizeWithOption(options)
// if err != nil {
// // handle error
// }
Expand All @@ -335,15 +339,16 @@ func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (i
//
// Parameters:
//
// message - The provided message.
// echoOptions - The [ClusterEchoOptions] type.
//
// Return value:
//
// A map where each address is the key and its corresponding node response is the information for the default sections.
//
// Example:
//
// response, err := clusterClient.EchoWithOptions(opts)
// options := options.ClusterEchoOptions{&options.EchoOptions{"Hi"}, &options.RouteOption{config.AllNodes}}
// response, err := clusterClient.EchoWithOptions(options)
// if err != nil {
// // handle error
// }
Expand All @@ -353,12 +358,19 @@ func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (i
//
// [valkey.io]: https://valkey.io/commands/echo/
func (client *GlideClusterClient) EchoWithOptions(echoOptions options.ClusterEchoOptions) (ClusterValue[string], error) {
response, err := client.executeCommandWithRoute(C.Echo, echoOptions.ToArgs(),
echoOptions.RouteOption.Route)
args, err := echoOptions.ToArgs()
if err != nil {
return createEmptyClusterValue[string](), err
}
var route config.Route
if echoOptions.RouteOption != nil && echoOptions.RouteOption.Route != nil {
route = echoOptions.RouteOption.Route
}
response, err := client.executeCommandWithRoute(C.Echo, args, route)
if err != nil {
return createEmptyClusterValue[string](), err
}
if echoOptions.RouteOption.Route != nil &&
if echoOptions.RouteOption != nil && echoOptions.RouteOption.Route != nil &&
(echoOptions.RouteOption.Route).IsMultiNode() {
data, err := handleStringToStringMapResponse(response)
if err != nil {
Expand Down
29 changes: 19 additions & 10 deletions go/api/list_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

package api

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

// Supports commands and transactions for the "List" group of commands for standalone and cluster clients.
//
// See [valkey.io] for details.
Expand All @@ -16,11 +20,11 @@ type ListCommands interface {

LPos(key string, element string) (Result[int64], error)

LPosWithOptions(key string, element string, options *LPosOptions) (Result[int64], error)
LPosWithOptions(key string, element string, options *options.LPosOptions) (Result[int64], error)

LPosCount(key string, element string, count int64) ([]int64, error)

LPosCountWithOptions(key string, element string, count int64, options *LPosOptions) ([]int64, error)
LPosCountWithOptions(key string, element string, count int64, options *options.LPosOptions) ([]int64, error)

RPush(key string, elements []string) (int64, error)

Expand All @@ -38,7 +42,7 @@ type ListCommands interface {

RPopCount(key string, count int64) ([]string, error)

LInsert(key string, insertPosition InsertPosition, pivot string, element string) (int64, error)
LInsert(key string, insertPosition options.InsertPosition, pivot string, element string) (int64, error)

BLPop(keys []string, timeoutSecs float64) ([]string, error)

Expand All @@ -48,28 +52,33 @@ type ListCommands interface {

LPushX(key string, elements []string) (int64, error)

LMPop(keys []string, listDirection ListDirection) (map[string][]string, error)
LMPop(keys []string, listDirection options.ListDirection) (map[string][]string, error)

LMPopCount(keys []string, listDirection ListDirection, count int64) (map[string][]string, error)
LMPopCount(keys []string, listDirection options.ListDirection, count int64) (map[string][]string, error)

BLMPop(keys []string, listDirection ListDirection, timeoutSecs float64) (map[string][]string, error)
BLMPop(keys []string, listDirection options.ListDirection, timeoutSecs float64) (map[string][]string, error)

BLMPopCount(
keys []string,
listDirection ListDirection,
listDirection options.ListDirection,
count int64,
timeoutSecs float64,
) (map[string][]string, error)

LSet(key string, index int64, element string) (string, error)

LMove(source string, destination string, whereFrom ListDirection, whereTo ListDirection) (Result[string], error)
LMove(
source string,
destination string,
whereFrom options.ListDirection,
whereTo options.ListDirection,
) (Result[string], error)

BLMove(
source string,
destination string,
whereFrom ListDirection,
whereTo ListDirection,
whereFrom options.ListDirection,
whereTo options.ListDirection,
timeoutSecs float64,
) (Result[string], error)
}
2 changes: 1 addition & 1 deletion go/api/options/base_scan_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type BaseScanOptions struct {
count int64
}

func NewBaseScanOptionsBuilder() *BaseScanOptions {
func NewBaseScanOptions() *BaseScanOptions {
return &BaseScanOptions{}
}

Expand Down
2 changes: 1 addition & 1 deletion go/api/options/bitcount_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type BitCountOptions struct {
bitMapIndexType BitmapIndexType
}

func NewBitCountOptionsBuilder() *BitCountOptions {
func NewBitCountOptions() *BitCountOptions {
return &BitCountOptions{}
}

Expand Down
Loading
Loading