From a32be3d93d60b9b9a3711bb3c248684246168bae Mon Sep 17 00:00:00 2001 From: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com> Date: Thu, 4 Jan 2024 14:40:14 +0200 Subject: [PATCH] Add Suffix support to default client set info (#2852) * Add Suffix support to defualt client set info * Change ClientNameSuffix to IdentitySuffix * add tests --- commands_test.go | 11 +++++++++++ options.go | 3 +++ osscluster.go | 3 +++ redis.go | 3 +++ ring.go | 2 ++ sentinel.go | 2 ++ universal.go | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/commands_test.go b/commands_test.go index 4e9cf195d..af8b0c62f 100644 --- a/commands_test.go +++ b/commands_test.go @@ -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() { diff --git a/options.go b/options.go index 449a92521..dff52ae8b 100644 --- a/options.go +++ b/options.go @@ -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() { diff --git a/osscluster.go b/osscluster.go index b8a82d9bc..9e5eb0464 100644 --- a/osscluster.go +++ b/osscluster.go @@ -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() { @@ -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 diff --git a/redis.go b/redis.go index 9792af760..4dd862b84 100644 --- a/redis.go +++ b/redis.go @@ -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} diff --git a/ring.go b/ring.go index 0c031b5a6..4ae00542b 100644 --- a/ring.go +++ b/ring.go @@ -99,6 +99,7 @@ type RingOptions struct { Limiter Limiter DisableIndentity bool + IdentitySuffix string } func (opt *RingOptions) init() { @@ -166,6 +167,7 @@ func (opt *RingOptions) clientOptions() *Options { Limiter: opt.Limiter, DisableIndentity: opt.DisableIndentity, + IdentitySuffix: opt.IdentitySuffix, } } diff --git a/sentinel.go b/sentinel.go index 31ea3c77a..9ace0886b 100644 --- a/sentinel.go +++ b/sentinel.go @@ -81,6 +81,7 @@ type FailoverOptions struct { TLSConfig *tls.Config DisableIndentity bool + IdentitySuffix string } func (opt *FailoverOptions) clientOptions() *Options { @@ -117,6 +118,7 @@ func (opt *FailoverOptions) clientOptions() *Options { TLSConfig: opt.TLSConfig, DisableIndentity: opt.DisableIndentity, + IdentitySuffix: opt.IdentitySuffix, } } diff --git a/universal.go b/universal.go index 1e48d7b90..275bef3d6 100644 --- a/universal.go +++ b/universal.go @@ -67,6 +67,7 @@ type UniversalOptions struct { MasterName string DisableIndentity bool + IdentitySuffix string } // Cluster returns cluster options created from the universal options. @@ -112,6 +113,7 @@ func (o *UniversalOptions) Cluster() *ClusterOptions { TLSConfig: o.TLSConfig, DisableIndentity: o.DisableIndentity, + IdentitySuffix: o.IdentitySuffix, } } @@ -157,6 +159,7 @@ func (o *UniversalOptions) Failover() *FailoverOptions { TLSConfig: o.TLSConfig, DisableIndentity: o.DisableIndentity, + IdentitySuffix: o.IdentitySuffix, } } @@ -199,6 +202,7 @@ func (o *UniversalOptions) Simple() *Options { TLSConfig: o.TLSConfig, DisableIndentity: o.DisableIndentity, + IdentitySuffix: o.IdentitySuffix, } }