Skip to content

Commit

Permalink
Add clientName field
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-congo committed Feb 29, 2024
1 parent 50286f1 commit 3422c91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions go/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type baseClientConfiguration struct {
credentials *RedisCredentials
readFrom ReadFrom
requestTimeout int
clientName string
}

func (config *baseClientConfiguration) toProtobuf() *protobuf.ConnectionRequest {
Expand All @@ -99,6 +100,10 @@ func (config *baseClientConfiguration) toProtobuf() *protobuf.ConnectionRequest
request.RequestTimeout = uint32(config.requestTimeout)
}

if config.clientName != "" {
request.ClientName = config.clientName
}

return &request
}

Expand Down Expand Up @@ -208,6 +213,13 @@ func (config *RedisClientConfiguration) WithRequestTimeout(requestTimeout int) *
return config
}

// WithClientName sets the client name to be used for the client. Will be used with CLIENT SETNAME command during connection
// establishment.
func (config *RedisClientConfiguration) WithClientName(clientName string) *RedisClientConfiguration {
config.clientName = clientName
return config
}

// WithReconnectStrategy sets the [BackoffStrategy] used to determine how and when to reconnect, in case of connection
// failures. If not set, a default backoff strategy will be used.
func (config *RedisClientConfiguration) WithReconnectStrategy(strategy *BackoffStrategy) *RedisClientConfiguration {
Expand Down Expand Up @@ -288,3 +300,10 @@ func (config *RedisClusterClientConfiguration) WithRequestTimeout(requestTimeout
config.requestTimeout = requestTimeout
return config
}

// WithClientName sets the client name to be used for the client. Will be used with CLIENT SETNAME command during connection
// establishment.
func (config *RedisClusterClientConfiguration) WithClientName(clientName string) *RedisClusterClientConfiguration {
config.clientName = clientName
return config
}
3 changes: 3 additions & 0 deletions go/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestConfig_allFieldsSet(t *testing.T) {
username := "username"
password := "password"
timeout := 3
clientName := "client name"
retries, factor, base := 5, 10, 50
databaseId := 1

Expand All @@ -50,6 +51,7 @@ func TestConfig_allFieldsSet(t *testing.T) {
WithReadFrom(PreferReplica).
WithCredentials(NewRedisCredentials(username, password)).
WithRequestTimeout(timeout).
WithClientName(clientName).
WithReconnectStrategy(NewBackoffStrategy(retries, factor, base)).
WithDatabaseId(databaseId)

Expand All @@ -59,6 +61,7 @@ func TestConfig_allFieldsSet(t *testing.T) {
ClusterModeEnabled: false,
AuthenticationInfo: &protobuf.AuthenticationInfo{Username: username, Password: password},
RequestTimeout: uint32(timeout),
ClientName: clientName,
ConnectionRetryStrategy: &protobuf.ConnectionRetryStrategy{
NumberOfRetries: uint32(retries),
Factor: uint32(factor),
Expand Down

0 comments on commit 3422c91

Please sign in to comment.