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 all 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
304 changes: 173 additions & 131 deletions go/api/base_client.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/api/bitmap_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ExampleGlideClient_BitCount() {
func ExampleGlideClient_BitCountWithOptions() {
var client *GlideClient = getExampleGlideClient() // example helper function

options := options.NewBitCountOptionsBuilder().
options := options.NewBitCountOptions().
SetStart(1).
SetEnd(1).
SetBitmapIndexType(options.BYTE)
Expand Down
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)
}
28 changes: 14 additions & 14 deletions go/api/generic_base_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func ExampleGlideClusterClient_Expire() {
func ExampleGlideClient_ExpireWithOptions() {
var client *GlideClient = getExampleGlideClient() // example helper function
result, err := client.Set("key", "someValue")
result1, err := client.ExpireWithOptions("key", 1, HasNoExpiry)
result1, err := client.ExpireWithOptions("key", 1, options.HasNoExpiry)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand All @@ -135,7 +135,7 @@ func ExampleGlideClient_ExpireWithOptions() {
func ExampleGlideClusterClient_ExpireWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
result, err := client.Set("key", "someValue")
result1, err := client.ExpireWithOptions("key", 1, HasNoExpiry)
result1, err := client.ExpireWithOptions("key", 1, options.HasNoExpiry)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func ExampleGlideClusterClient_ExpireAt() {
func ExampleGlideClient_ExpireAtWithOptions() {
var client *GlideClient = getExampleGlideClient() // example helper function
result, err := client.Set("key", "someValue")
result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, HasNoExpiry)
result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, options.HasNoExpiry)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand All @@ -195,7 +195,7 @@ func ExampleGlideClient_ExpireAtWithOptions() {
func ExampleGlideClusterClient_ExpireAtWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
result, err := client.Set("key", "someValue")
result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, HasNoExpiry)
result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, options.HasNoExpiry)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func ExampleGlideClusterClient_PExpire() {
func ExampleGlideClient_PExpireWithOptions() {
var client *GlideClient = getExampleGlideClient() // example helper function
result, err := client.Set("key", "someValue")
result1, err := client.PExpireWithOptions("key", int64(5*1000), HasNoExpiry)
result1, err := client.PExpireWithOptions("key", int64(5*1000), options.HasNoExpiry)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand All @@ -255,7 +255,7 @@ func ExampleGlideClient_PExpireWithOptions() {
func ExampleGlideClusterClient_PExpireWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
result, err := client.Set("key", "someValue")
result1, err := client.PExpireWithOptions("key", int64(5*1000), HasNoExpiry)
result1, err := client.PExpireWithOptions("key", int64(5*1000), options.HasNoExpiry)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand Down Expand Up @@ -300,7 +300,7 @@ func ExampleGlideClusterClient_PExpireAt() {
func ExampleGlideClient_PExpireAtWithOptions() {
var client *GlideClient = getExampleGlideClient() // example helper function
result, err := client.Set("key", "someValue")
result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, HasNoExpiry)
result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, options.HasNoExpiry)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand All @@ -315,7 +315,7 @@ func ExampleGlideClient_PExpireAtWithOptions() {
func ExampleGlideClusterClient_PExpireAtWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
result, err := client.Set("key", "someValue")
result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, HasNoExpiry)
result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, options.HasNoExpiry)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand Down Expand Up @@ -696,8 +696,8 @@ func ExampleGlideClient_RestoreWithOptions() {
result, err := client.Set("key1", "someValue")
dump, err := client.Dump("key1")
result1, err := client.Del([]string{"key1"})
result2, err := client.RestoreWithOptions("key1", 0, dump.Value(),
NewRestoreOptionsBuilder().SetReplace().SetABSTTL().SetEviction(FREQ, 10))
opts := options.NewRestoreOptions().SetReplace().SetABSTTL().SetEviction(options.FREQ, 10)
result2, err := client.RestoreWithOptions("key1", 0, dump.Value(), opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand All @@ -716,8 +716,8 @@ func ExampleGlideClusterClient_RestoreWithOptions() {
result, err := client.Set("key1", "someValue")
dump, err := client.Dump("key1")
result1, err := client.Del([]string{"key1"})
result2, err := client.RestoreWithOptions("key1", 0, dump.Value(),
NewRestoreOptionsBuilder().SetReplace().SetABSTTL().SetEviction(FREQ, 10))
opts := options.NewRestoreOptions().SetReplace().SetABSTTL().SetEviction(options.FREQ, 10)
result2, err := client.RestoreWithOptions("key1", 0, dump.Value(), opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
Expand Down Expand Up @@ -1156,7 +1156,7 @@ func ExampleGlideClient_CopyWithOptions() {
var client *GlideClient = getExampleGlideClient() // example helper function
client.Set("key1", "someValue")

opts := NewCopyOptionsBuilder().SetReplace()
opts := options.NewCopyOptions().SetReplace()
client.CopyWithOptions("key1", "key2", opts)

result, err := client.Get("key2")
Expand All @@ -1173,7 +1173,7 @@ func ExampleGlideClusterClient_CopyWithOptions() {

client.Set("{key}1", "someValue")

opts := NewCopyOptionsBuilder().SetReplace()
opts := options.NewCopyOptions().SetReplace()
client.CopyWithOptions("{key}1", "{key}2", opts)

result, err := client.Get("{key}2")
Expand Down
20 changes: 14 additions & 6 deletions go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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 @@ -173,16 +173,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 @@ -261,13 +265,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
Loading
Loading