Skip to content

Commit

Permalink
Add Suffix support to default client set info (redis#2852)
Browse files Browse the repository at this point in the history
* Add Suffix support to defualt client set info

* Change ClientNameSuffix to IdentitySuffix

* add tests
  • Loading branch information
ofekshenawa authored Jan 4, 2024
1 parent d8e3e95 commit a32be3d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ var _ = Describe("Commands", func() {
}()
pipe.ClientSetInfo(ctx, libInfo)
}).To(Panic())
// Test setting the default options for libName, libName suffix and libVer
clientInfo := client.ClientInfo(ctx).Val()
Expect(clientInfo.LibName).To(ContainSubstring("go-redis(go-redis,"))
// Test setting the libName suffix in options
opt := redisOptions()
opt.IdentitySuffix = "suffix"
client2 := redis.NewClient(opt)
defer client2.Close()
clientInfo = client2.ClientInfo(ctx).Val()
Expect(clientInfo.LibName).To(ContainSubstring("go-redis(suffix,"))

})

It("should ConfigGet", func() {
Expand Down
3 changes: 3 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ type Options struct {

// Disable set-lib on connect. Default is false.
DisableIndentity bool

// Add suffix to client name. Default is empty.
IdentitySuffix string
}

func (opt *Options) init() {
Expand Down
3 changes: 3 additions & 0 deletions osscluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type ClusterOptions struct {

TLSConfig *tls.Config
DisableIndentity bool // Disable set-lib on connect. Default is false.

IdentitySuffix string // Add suffix to client name. Default is empty.
}

func (opt *ClusterOptions) init() {
Expand Down Expand Up @@ -291,6 +293,7 @@ func (opt *ClusterOptions) clientOptions() *Options {
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
DisableIndentity: opt.DisableIndentity,
IdentitySuffix: opt.IdentitySuffix,
TLSConfig: opt.TLSConfig,
// If ClusterSlots is populated, then we probably have an artificial
// cluster whose nodes are not in clustering mode (otherwise there isn't
Expand Down
3 changes: 3 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
if !c.opt.DisableIndentity {
libName := ""
libVer := Version()
if c.opt.IdentitySuffix != "" {
libName = c.opt.IdentitySuffix
}
libInfo := LibraryInfo{LibName: &libName}
conn.ClientSetInfo(ctx, libInfo)
libInfo = LibraryInfo{LibVer: &libVer}
Expand Down
2 changes: 2 additions & 0 deletions ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type RingOptions struct {
Limiter Limiter

DisableIndentity bool
IdentitySuffix string
}

func (opt *RingOptions) init() {
Expand Down Expand Up @@ -166,6 +167,7 @@ func (opt *RingOptions) clientOptions() *Options {
Limiter: opt.Limiter,

DisableIndentity: opt.DisableIndentity,
IdentitySuffix: opt.IdentitySuffix,
}
}

Expand Down
2 changes: 2 additions & 0 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type FailoverOptions struct {
TLSConfig *tls.Config

DisableIndentity bool
IdentitySuffix string
}

func (opt *FailoverOptions) clientOptions() *Options {
Expand Down Expand Up @@ -117,6 +118,7 @@ func (opt *FailoverOptions) clientOptions() *Options {
TLSConfig: opt.TLSConfig,

DisableIndentity: opt.DisableIndentity,
IdentitySuffix: opt.IdentitySuffix,
}
}

Expand Down
4 changes: 4 additions & 0 deletions universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type UniversalOptions struct {
MasterName string

DisableIndentity bool
IdentitySuffix string
}

// Cluster returns cluster options created from the universal options.
Expand Down Expand Up @@ -112,6 +113,7 @@ func (o *UniversalOptions) Cluster() *ClusterOptions {
TLSConfig: o.TLSConfig,

DisableIndentity: o.DisableIndentity,
IdentitySuffix: o.IdentitySuffix,
}
}

Expand Down Expand Up @@ -157,6 +159,7 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
TLSConfig: o.TLSConfig,

DisableIndentity: o.DisableIndentity,
IdentitySuffix: o.IdentitySuffix,
}
}

Expand Down Expand Up @@ -199,6 +202,7 @@ func (o *UniversalOptions) Simple() *Options {
TLSConfig: o.TLSConfig,

DisableIndentity: o.DisableIndentity,
IdentitySuffix: o.IdentitySuffix,
}
}

Expand Down

0 comments on commit a32be3d

Please sign in to comment.