diff --git a/commands.go b/commands.go index 546ebafb..db595944 100644 --- a/commands.go +++ b/commands.go @@ -309,7 +309,7 @@ func (c statefulCmdable) ClientSetInfo(ctx context.Context, info LibraryInfo) *S var cmd *StatusCmd if info.LibName != nil { - libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, runtime.Version()) + libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, internal.ReplaceSpaces(runtime.Version())) cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", libName) } else { cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-VER", *info.LibVer) diff --git a/commands_test.go b/commands_test.go index 5af2797e..d30a9d8b 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2105,7 +2105,7 @@ var _ = Describe("Commands", func() { logEntries, err := client.ACLLog(ctx, 10).Result() Expect(err).NotTo(HaveOccurred()) - Expect(len(logEntries)).To(Equal(1)) + Expect(len(logEntries)).To(Equal(4)) for _, entry := range logEntries { Expect(entry.Reason).To(Equal("command")) @@ -2121,7 +2121,7 @@ var _ = Describe("Commands", func() { limitedLogEntries, err := client.ACLLog(ctx, 2).Result() Expect(err).NotTo(HaveOccurred()) - Expect(len(limitedLogEntries)).To(Equal(1)) + Expect(len(limitedLogEntries)).To(Equal(2)) }) It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() { diff --git a/internal/util.go b/internal/util.go index 77ca4ee1..ed81ad7a 100644 --- a/internal/util.go +++ b/internal/util.go @@ -2,6 +2,7 @@ package internal import ( "context" + "strings" "time" "github.com/redis/go-redis/v9/internal/util" @@ -44,3 +45,22 @@ func isLower(s string) bool { } return true } + +func ReplaceSpaces(s string) string { + // Pre-allocate a builder with the same length as s to minimize allocations. + // This is a basic optimization; adjust the initial size based on your use case. + var builder strings.Builder + builder.Grow(len(s)) + + for _, char := range s { + if char == ' ' { + // Replace space with a hyphen. + builder.WriteRune('-') + } else { + // Copy the character as-is. + builder.WriteRune(char) + } + } + + return builder.String() +} diff --git a/redis.go b/redis.go index 33477b53..d25a0d31 100644 --- a/redis.go +++ b/redis.go @@ -334,22 +334,24 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { pipe.ClientSetName(ctx, c.opt.ClientName) } - if !c.opt.DisableIndentity { - libName := "" - libVer := Version() - if c.opt.IdentitySuffix != "" { - libName = c.opt.IdentitySuffix - } - pipe.ClientSetInfo(ctx, WithLibraryName(libName)) - pipe.ClientSetInfo(ctx, WithLibraryVersion(libVer)) - } - return nil }) if err != nil { return err } + if !c.opt.DisableIndentity { + libName := "" + libVer := Version() + if c.opt.IdentitySuffix != "" { + libName = c.opt.IdentitySuffix + } + p := conn.Pipeline() + p.ClientSetInfo(ctx, WithLibraryName(libName)) + p.ClientSetInfo(ctx, WithLibraryVersion(libVer)) + _, _ = p.Exec(ctx) + } + if c.opt.OnConnect != nil { return c.opt.OnConnect(ctx, conn) } diff --git a/sentinel.go b/sentinel.go index 9ace0886..188f8849 100644 --- a/sentinel.go +++ b/sentinel.go @@ -153,6 +153,9 @@ func (opt *FailoverOptions) sentinelOptions(addr string) *Options { ConnMaxLifetime: opt.ConnMaxLifetime, TLSConfig: opt.TLSConfig, + + DisableIndentity: opt.DisableIndentity, + IdentitySuffix: opt.IdentitySuffix, } } @@ -190,6 +193,9 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions { ConnMaxLifetime: opt.ConnMaxLifetime, TLSConfig: opt.TLSConfig, + + DisableIndentity: opt.DisableIndentity, + IdentitySuffix: opt.IdentitySuffix, } }