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 Client Get and Set Name #3302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
462e86e
Implement Client Get-Set
EdricCua Mar 3, 2025
0b7178d
Implement Client Get-Set
EdricCua Mar 3, 2025
d98894f
Update from main
EdricCua Mar 3, 2025
2c9c856
Implement Client Get-Set Name
EdricCua Mar 3, 2025
ad8b8e6
Implement Client Get-Set Name
EdricCua Mar 3, 2025
575a46c
Implement Client Get-Set Name
EdricCua Mar 3, 2025
df3085d
Implement Client Get-Set Name
EdricCua Mar 3, 2025
bbce65e
Implement Client Get-Set Name
EdricCua Mar 3, 2025
8f7b23b
Implement Client Get-Set Name
EdricCua Mar 3, 2025
1f23c18
Implement Client Get-Set Name
EdricCua Mar 4, 2025
6cb9be1
Implement Client Get-Set Name
EdricCua Mar 4, 2025
2ff7059
Update from Main
EdricCua Mar 4, 2025
744d2a8
Fix commit issues
EdricCua Mar 5, 2025
9017462
Fix merge conflict
EdricCua Mar 5, 2025
bc93b24
Fix commit errors
EdricCua Mar 5, 2025
dfb7d8c
Fix commit errors
EdricCua Mar 5, 2025
2942f3a
Fix commit error
EdricCua Mar 5, 2025
a767ee1
Fix CI Job
EdricCua Mar 18, 2025
ea9cde6
Update from main
EdricCua Mar 18, 2025
8342eff
fix examples
EdricCua Mar 20, 2025
d7a53c8
fix examples
EdricCua Mar 20, 2025
d394099
update from main
EdricCua Mar 20, 2025
5670a71
update from main
EdricCua Mar 20, 2025
1dc63b8
fix review comment
EdricCua Mar 20, 2025
70acc8f
fix review comment
EdricCua Mar 21, 2025
3d1eafe
update from main
EdricCua Mar 21, 2025
9b8bc52
update from main
EdricCua Mar 24, 2025
a2c24dc
update from main
EdricCua Mar 26, 2025
6902f97
update from main
EdricCua Mar 28, 2025
ec13232
update from main
EdricCua Mar 28, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* Go: Add `Config Reset Stat` ([#3121](https://github.com/valkey-io/valkey-glide/pull/3121))
* Go: Add `GeoSearch` and `GeoSearchStore` ([#3385](https://github.com/valkey-io/valkey-glide/pull/3385))
* Go: Add `Cluster Config Set & Get` ([#3274](https://github.com/valkey-io/valkey-glide/pull/3274))

* Go: Add `Client Set & Get` ([#3302](https://github.com/valkey-io/valkey-glide/pull/3302))
#### Breaking Changes

#### Fixes
Expand Down
8 changes: 8 additions & 0 deletions go/api/connection_management_cluster_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ type ConnectionManagementClusterCommands interface {
ClientId() (ClusterValue[int64], error)

ClientIdWithOptions(routeOptions options.RouteOption) (ClusterValue[int64], error)

ClientSetName(connectionName string) (ClusterValue[string], error)

ClientSetNameWithOptions(connectionName string, routeOptions options.RouteOption) (ClusterValue[string], error)

ClientGetName() (ClusterValue[string], error)

ClientGetNameWithOptions(routeOptions options.RouteOption) (ClusterValue[string], error)
}
53 changes: 53 additions & 0 deletions go/api/connection_management_cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package api
import (
"fmt"

"github.com/google/uuid"
"github.com/valkey-io/valkey-glide/go/api/options"
)

Expand Down Expand Up @@ -88,3 +89,55 @@ func ExampleGlideClusterClient_ClientIdWithOptions() {

// Output: true
}

func ExampleGlideClusterClient_ClientSetName() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
connectionName := "ConnectionName-" + uuid.NewString()
result, err := client.ClientSetName(connectionName)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result.SingleValue())

// Output: OK
}

func ExampleGlideClusterClient_ClientGetName() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
connectionName := "ConnectionName-" + uuid.NewString()
client.ClientSetName(connectionName)
result, err := client.ClientGetName()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result.SingleValue() == connectionName)

// Output: true
}

func ExampleGlideClusterClient_ClientSetNameWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
connectionName := "ConnectionName-" + uuid.NewString()
opts := options.RouteOption{Route: nil}
result, err := client.ClientSetNameWithOptions(connectionName, opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result.SingleValue())

// Output: OK
}

func ExampleGlideClusterClient_ClientGetNameWithOptions() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
connectionName := "ConnectionName-" + uuid.NewString()
opts := options.RouteOption{Route: nil}
client.ClientSetNameWithOptions(connectionName, opts)
result, err := client.ClientGetNameWithOptions(opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result.SingleValue() == connectionName)

// Output: true
}
4 changes: 4 additions & 0 deletions go/api/connection_management_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ type ConnectionManagementCommands interface {
Echo(message string) (Result[string], error)

ClientId() (int64, error)

ClientGetName() (string, error)

ClientSetName(connectionName string) (string, error)
}
25 changes: 25 additions & 0 deletions go/api/connection_management_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package api
import (
"fmt"

"github.com/google/uuid"
"github.com/valkey-io/valkey-glide/go/api/options"
)

Expand Down Expand Up @@ -53,3 +54,27 @@ func ExampleGlideClient_ClientId() {

// Output: true
}

func ExampleGlideClient_ClientSetName() {
var client *GlideClient = getExampleGlideClient() // example helper function
result, err := client.ClientSetName("ConnectionName")
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)

// Output: OK
}

func ExampleGlideClient_ClientGetName() {
var client *GlideClient = getExampleGlideClient() // example helper function
connectionName := "ConnectionName-" + uuid.NewString()
client.ClientSetName(connectionName)
result, err := client.ClientGetName()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result == connectionName)

// Output: true
}
34 changes: 34 additions & 0 deletions go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,37 @@ func (client *GlideClient) ConfigResetStat() (string, error) {
}
return handleStringResponse(response)
}

// Gets the name of the current connection.
//
// Return value:
//
// The name of the client connection as a string if a name is set, or nil if no name is assigned.
//
// [valkey.io]: https://valkey.io/commands/client-getname/
func (client *GlideClient) ClientGetName() (string, error) {
result, err := client.executeCommand(C.ClientGetName, []string{})
if err != nil {
return DefaultStringResponse, err
}
return handleStringResponse(result)
}

// Set the name of the current connection.
//
// Parameters:
//
// connectionName - Connection name of the current connection.
//
// Return value:
//
// OK - when connection name is set
//
// [valkey.io]: https://valkey.io/commands/client-setname/
func (client *GlideClient) ClientSetName(connectionName string) (string, error) {
result, err := client.executeCommand(C.ClientSetName, []string{connectionName})
if err != nil {
return DefaultStringResponse, err
}
return handleStringResponse(result)
}
107 changes: 107 additions & 0 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,110 @@ func (client *GlideClusterClient) ConfigGetWithOptions(
}
return createClusterValue[interface{}](data), nil
}

// Set the name of the current connection.
//
// Parameters:
//
// connectionName - Connection name of the current connection.
//
// Return value:
//
// OK - when connection name is set
//
// [valkey.io]: https://valkey.io/commands/client-setname/
func (client *GlideClusterClient) ClientSetName(connectionName string) (ClusterValue[string], error) {
response, err := client.executeCommand(C.ClientSetName, []string{connectionName})
if err != nil {
return createEmptyClusterValue[string](), err
}
data, err := handleStringResponse(response)
if err != nil {
return createEmptyClusterValue[string](), err
}
return createClusterSingleValue[string](data), nil
}

// Set the name of the current connection.
//
// Parameters:
//
// connectionName - Connection name of the current connection.
// opts - Specifies the routing configuration for the command. The client will route the
// command to the nodes defined by route.
//
// Return value:
//
// OK - when connection name is set
//
// [valkey.io]: https://valkey.io/commands/client-setname/
func (client *GlideClusterClient) ClientSetNameWithOptions(connectionName string, opts options.RouteOption) (ClusterValue[string], error) {
response, err := client.executeCommandWithRoute(C.ClientSetName, []string{connectionName}, opts.Route)
if err != nil {
return createEmptyClusterValue[string](), err
}
if opts.Route != nil &&
(opts.Route).IsMultiNode() {
data, err := handleStringToStringMapResponse(response)
if err != nil {
return createEmptyClusterValue[string](), err
}
return createClusterMultiValue[string](data), nil
}
data, err := handleStringResponse(response)
if err != nil {
return createEmptyClusterValue[string](), err
}
return createClusterSingleValue[string](data), nil
}

// Gets the name of the current connection.
//
// Return value:
//
// The name of the client connection as a string if a name is set, or nil if no name is assigned.
//
// [valkey.io]: https://valkey.io/commands/client-getname/
func (client *GlideClusterClient) ClientGetName() (ClusterValue[string], error) {
response, err := client.executeCommand(C.ClientGetName, []string{})
if err != nil {
return createEmptyClusterValue[string](), err
}
data, err := handleStringResponse(response)
if err != nil {
return createEmptyClusterValue[string](), err
}
return createClusterSingleValue[string](data), nil
}

// Gets the name of the current connection.
//
// Parameters:
//
// opts - Specifies the routing configuration for the command. The client will route the
// command to the nodes defined by route.
//
// Return value:
//
// The name of the client connection as a string if a name is set, or nil if no name is assigned.
//
// [valkey.io]: https://valkey.io/commands/client-getname/
func (client *GlideClusterClient) ClientGetNameWithOptions(opts options.RouteOption) (ClusterValue[string], error) {
response, err := client.executeCommandWithRoute(C.ClientGetName, []string{}, opts.Route)
if err != nil {
return createEmptyClusterValue[string](), err
}
if opts.Route != nil &&
(opts.Route).IsMultiNode() {
data, err := handleStringToStringMapResponse(response)
if err != nil {
return createEmptyClusterValue[string](), err
}
return createClusterMultiValue[string](data), nil
}
data, err := handleStringResponse(response)
if err != nil {
return createEmptyClusterValue[string](), err
}
return createClusterSingleValue[string](data), nil
}
36 changes: 36 additions & 0 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,3 +1283,39 @@ func (suite *GlideTestSuite) TestConfigSetGetWithOptions() {
assert.Contains(t, strings.ToLower(mapString), strings.ToLower("timeout"))
}
}

func (suite *GlideTestSuite) TestClientSetGetName() {
client := suite.defaultClusterClient()
t := suite.T()
connectionName := "ConnectionName-" + uuid.NewString()
client.ClientSetName(connectionName)
response, err := client.ClientGetName()
assert.NoError(t, err)
assert.True(t, response.IsSingleValue())
}

func (suite *GlideTestSuite) TestClientSetGetNameWithRoute() {
client := suite.defaultClusterClient()
t := suite.T()

// ClientGetName with option or with multiple options without route
opts := options.RouteOption{Route: nil}
connectionName := "ConnectionName-" + uuid.NewString()
response, err := client.ClientSetNameWithOptions(connectionName, opts)
assert.NoError(t, err)
assert.True(t, response.IsSingleValue())
response, err = client.ClientGetNameWithOptions(opts)
assert.NoError(t, err)
assert.True(t, response.IsSingleValue())

// same sections with random route
connectionName = "ConnectionName-" + uuid.NewString()
route := config.Route(config.RandomRoute)
opts = options.RouteOption{Route: route}
response, err = client.ClientSetNameWithOptions(connectionName, opts)
assert.NoError(t, err)
assert.True(t, response.IsSingleValue())
response, err = client.ClientGetNameWithOptions(opts)
assert.NoError(t, err)
assert.True(t, response.IsSingleValue())
}
10 changes: 10 additions & 0 deletions go/integTest/standalone_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,13 @@ func (suite *GlideTestSuite) TestConfigResetStat() {
client := suite.defaultClient()
suite.verifyOK(client.ConfigResetStat())
}

func (suite *GlideTestSuite) TestClientGetSetName() {
client := suite.defaultClient()
t := suite.T()

suite.verifyOK(client.ClientSetName("ConnectionName"))
result, err := client.ClientGetName()
assert.Nil(t, err)
assert.Equal(t, result, "ConnectionName")
}
Loading