mirror of https://github.com/go-redis/redis.git
Add Suffix support to default client set info (#2852)
* Add Suffix support to defualt client set info * Change ClientNameSuffix to IdentitySuffix * add tests
This commit is contained in:
parent
d8e3e95866
commit
a32be3d93d
|
@ -291,6 +291,17 @@ var _ = Describe("Commands", func() {
|
||||||
}()
|
}()
|
||||||
pipe.ClientSetInfo(ctx, libInfo)
|
pipe.ClientSetInfo(ctx, libInfo)
|
||||||
}).To(Panic())
|
}).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() {
|
It("should ConfigGet", func() {
|
||||||
|
|
|
@ -144,6 +144,9 @@ type Options struct {
|
||||||
|
|
||||||
// Disable set-lib on connect. Default is false.
|
// Disable set-lib on connect. Default is false.
|
||||||
DisableIndentity bool
|
DisableIndentity bool
|
||||||
|
|
||||||
|
// Add suffix to client name. Default is empty.
|
||||||
|
IdentitySuffix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *Options) init() {
|
func (opt *Options) init() {
|
||||||
|
|
|
@ -86,6 +86,8 @@ type ClusterOptions struct {
|
||||||
|
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
DisableIndentity bool // Disable set-lib on connect. Default is false.
|
DisableIndentity bool // Disable set-lib on connect. Default is false.
|
||||||
|
|
||||||
|
IdentitySuffix string // Add suffix to client name. Default is empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *ClusterOptions) init() {
|
func (opt *ClusterOptions) init() {
|
||||||
|
@ -291,6 +293,7 @@ func (opt *ClusterOptions) clientOptions() *Options {
|
||||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||||
DisableIndentity: opt.DisableIndentity,
|
DisableIndentity: opt.DisableIndentity,
|
||||||
|
IdentitySuffix: opt.IdentitySuffix,
|
||||||
TLSConfig: opt.TLSConfig,
|
TLSConfig: opt.TLSConfig,
|
||||||
// If ClusterSlots is populated, then we probably have an artificial
|
// If ClusterSlots is populated, then we probably have an artificial
|
||||||
// cluster whose nodes are not in clustering mode (otherwise there isn't
|
// cluster whose nodes are not in clustering mode (otherwise there isn't
|
||||||
|
|
3
redis.go
3
redis.go
|
@ -315,6 +315,9 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
|
||||||
if !c.opt.DisableIndentity {
|
if !c.opt.DisableIndentity {
|
||||||
libName := ""
|
libName := ""
|
||||||
libVer := Version()
|
libVer := Version()
|
||||||
|
if c.opt.IdentitySuffix != "" {
|
||||||
|
libName = c.opt.IdentitySuffix
|
||||||
|
}
|
||||||
libInfo := LibraryInfo{LibName: &libName}
|
libInfo := LibraryInfo{LibName: &libName}
|
||||||
conn.ClientSetInfo(ctx, libInfo)
|
conn.ClientSetInfo(ctx, libInfo)
|
||||||
libInfo = LibraryInfo{LibVer: &libVer}
|
libInfo = LibraryInfo{LibVer: &libVer}
|
||||||
|
|
2
ring.go
2
ring.go
|
@ -99,6 +99,7 @@ type RingOptions struct {
|
||||||
Limiter Limiter
|
Limiter Limiter
|
||||||
|
|
||||||
DisableIndentity bool
|
DisableIndentity bool
|
||||||
|
IdentitySuffix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *RingOptions) init() {
|
func (opt *RingOptions) init() {
|
||||||
|
@ -166,6 +167,7 @@ func (opt *RingOptions) clientOptions() *Options {
|
||||||
Limiter: opt.Limiter,
|
Limiter: opt.Limiter,
|
||||||
|
|
||||||
DisableIndentity: opt.DisableIndentity,
|
DisableIndentity: opt.DisableIndentity,
|
||||||
|
IdentitySuffix: opt.IdentitySuffix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ type FailoverOptions struct {
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
DisableIndentity bool
|
DisableIndentity bool
|
||||||
|
IdentitySuffix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *FailoverOptions) clientOptions() *Options {
|
func (opt *FailoverOptions) clientOptions() *Options {
|
||||||
|
@ -117,6 +118,7 @@ func (opt *FailoverOptions) clientOptions() *Options {
|
||||||
TLSConfig: opt.TLSConfig,
|
TLSConfig: opt.TLSConfig,
|
||||||
|
|
||||||
DisableIndentity: opt.DisableIndentity,
|
DisableIndentity: opt.DisableIndentity,
|
||||||
|
IdentitySuffix: opt.IdentitySuffix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ type UniversalOptions struct {
|
||||||
MasterName string
|
MasterName string
|
||||||
|
|
||||||
DisableIndentity bool
|
DisableIndentity bool
|
||||||
|
IdentitySuffix string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cluster returns cluster options created from the universal options.
|
// Cluster returns cluster options created from the universal options.
|
||||||
|
@ -112,6 +113,7 @@ func (o *UniversalOptions) Cluster() *ClusterOptions {
|
||||||
TLSConfig: o.TLSConfig,
|
TLSConfig: o.TLSConfig,
|
||||||
|
|
||||||
DisableIndentity: o.DisableIndentity,
|
DisableIndentity: o.DisableIndentity,
|
||||||
|
IdentitySuffix: o.IdentitySuffix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +159,7 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
|
||||||
TLSConfig: o.TLSConfig,
|
TLSConfig: o.TLSConfig,
|
||||||
|
|
||||||
DisableIndentity: o.DisableIndentity,
|
DisableIndentity: o.DisableIndentity,
|
||||||
|
IdentitySuffix: o.IdentitySuffix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +202,7 @@ func (o *UniversalOptions) Simple() *Options {
|
||||||
TLSConfig: o.TLSConfig,
|
TLSConfig: o.TLSConfig,
|
||||||
|
|
||||||
DisableIndentity: o.DisableIndentity,
|
DisableIndentity: o.DisableIndentity,
|
||||||
|
IdentitySuffix: o.IdentitySuffix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue