Skip to content

Commit a32be3d

Browse files
authored
Add Suffix support to default client set info (#2852)
* Add Suffix support to defualt client set info * Change ClientNameSuffix to IdentitySuffix * add tests
1 parent d8e3e95 commit a32be3d

File tree

7 files changed

+28
-0
lines changed

7 files changed

+28
-0
lines changed

commands_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,17 @@ var _ = Describe("Commands", func() {
291291
}()
292292
pipe.ClientSetInfo(ctx, libInfo)
293293
}).To(Panic())
294+
// Test setting the default options for libName, libName suffix and libVer
295+
clientInfo := client.ClientInfo(ctx).Val()
296+
Expect(clientInfo.LibName).To(ContainSubstring("go-redis(go-redis,"))
297+
// Test setting the libName suffix in options
298+
opt := redisOptions()
299+
opt.IdentitySuffix = "suffix"
300+
client2 := redis.NewClient(opt)
301+
defer client2.Close()
302+
clientInfo = client2.ClientInfo(ctx).Val()
303+
Expect(clientInfo.LibName).To(ContainSubstring("go-redis(suffix,"))
304+
294305
})
295306

296307
It("should ConfigGet", func() {

options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ type Options struct {
144144

145145
// Disable set-lib on connect. Default is false.
146146
DisableIndentity bool
147+
148+
// Add suffix to client name. Default is empty.
149+
IdentitySuffix string
147150
}
148151

149152
func (opt *Options) init() {

osscluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ type ClusterOptions struct {
8686

8787
TLSConfig *tls.Config
8888
DisableIndentity bool // Disable set-lib on connect. Default is false.
89+
90+
IdentitySuffix string // Add suffix to client name. Default is empty.
8991
}
9092

9193
func (opt *ClusterOptions) init() {
@@ -291,6 +293,7 @@ func (opt *ClusterOptions) clientOptions() *Options {
291293
ConnMaxIdleTime: opt.ConnMaxIdleTime,
292294
ConnMaxLifetime: opt.ConnMaxLifetime,
293295
DisableIndentity: opt.DisableIndentity,
296+
IdentitySuffix: opt.IdentitySuffix,
294297
TLSConfig: opt.TLSConfig,
295298
// If ClusterSlots is populated, then we probably have an artificial
296299
// cluster whose nodes are not in clustering mode (otherwise there isn't

redis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
315315
if !c.opt.DisableIndentity {
316316
libName := ""
317317
libVer := Version()
318+
if c.opt.IdentitySuffix != "" {
319+
libName = c.opt.IdentitySuffix
320+
}
318321
libInfo := LibraryInfo{LibName: &libName}
319322
conn.ClientSetInfo(ctx, libInfo)
320323
libInfo = LibraryInfo{LibVer: &libVer}

ring.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type RingOptions struct {
9999
Limiter Limiter
100100

101101
DisableIndentity bool
102+
IdentitySuffix string
102103
}
103104

104105
func (opt *RingOptions) init() {
@@ -166,6 +167,7 @@ func (opt *RingOptions) clientOptions() *Options {
166167
Limiter: opt.Limiter,
167168

168169
DisableIndentity: opt.DisableIndentity,
170+
IdentitySuffix: opt.IdentitySuffix,
169171
}
170172
}
171173

sentinel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type FailoverOptions struct {
8181
TLSConfig *tls.Config
8282

8383
DisableIndentity bool
84+
IdentitySuffix string
8485
}
8586

8687
func (opt *FailoverOptions) clientOptions() *Options {
@@ -117,6 +118,7 @@ func (opt *FailoverOptions) clientOptions() *Options {
117118
TLSConfig: opt.TLSConfig,
118119

119120
DisableIndentity: opt.DisableIndentity,
121+
IdentitySuffix: opt.IdentitySuffix,
120122
}
121123
}
122124

universal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type UniversalOptions struct {
6767
MasterName string
6868

6969
DisableIndentity bool
70+
IdentitySuffix string
7071
}
7172

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

114115
DisableIndentity: o.DisableIndentity,
116+
IdentitySuffix: o.IdentitySuffix,
115117
}
116118
}
117119

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

159161
DisableIndentity: o.DisableIndentity,
162+
IdentitySuffix: o.IdentitySuffix,
160163
}
161164
}
162165

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

201204
DisableIndentity: o.DisableIndentity,
205+
IdentitySuffix: o.IdentitySuffix,
202206
}
203207
}
204208

0 commit comments

Comments
 (0)