Skip to content

bug: Fix SETINFO ensuring it is set-and-forget #2915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bench_decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewClientStub(resp []byte) *ClientStub {
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
return stub.stubConn(initHello), nil
},
DisableIndentity: true,
DisableIdentity: true,
})
return stub
}
Expand All @@ -46,7 +46,7 @@ func NewClusterClientStub(resp []byte) *ClientStub {
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
return stub.stubConn(initHello), nil
},
DisableIndentity: true,
DisableIdentity: true,

ClusterSlots: func(_ context.Context) ([]ClusterSlot, error) {
return []ClusterSlot{
Expand Down
2 changes: 1 addition & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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() {
Expand Down
20 changes: 20 additions & 0 deletions internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"context"
"strings"
"time"

"github.com/redis/go-redis/v9/internal/util"
Expand Down Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type Options struct {
readOnly bool

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

// Add suffix to client name. Default is empty.
IdentitySuffix string
Expand Down
26 changes: 13 additions & 13 deletions osscluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ type ClusterOptions struct {
ConnMaxIdleTime time.Duration
ConnMaxLifetime time.Duration

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

IdentitySuffix string // Add suffix to client name. Default is empty.
}
Expand Down Expand Up @@ -286,17 +286,17 @@ func (opt *ClusterOptions) clientOptions() *Options {
WriteTimeout: opt.WriteTimeout,
ContextTimeoutEnabled: opt.ContextTimeoutEnabled,

PoolFIFO: opt.PoolFIFO,
PoolSize: opt.PoolSize,
PoolTimeout: opt.PoolTimeout,
MinIdleConns: opt.MinIdleConns,
MaxIdleConns: opt.MaxIdleConns,
MaxActiveConns: opt.MaxActiveConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
DisableIndentity: opt.DisableIndentity,
IdentitySuffix: opt.IdentitySuffix,
TLSConfig: opt.TLSConfig,
PoolFIFO: opt.PoolFIFO,
PoolSize: opt.PoolSize,
PoolTimeout: opt.PoolTimeout,
MinIdleConns: opt.MinIdleConns,
MaxIdleConns: opt.MaxIdleConns,
MaxActiveConns: opt.MaxActiveConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
DisableIdentity: opt.DisableIdentity,
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
// much use for ClusterSlots config). This means we cannot execute the
Expand Down
20 changes: 10 additions & 10 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,22 @@ 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.DisableIdentity {
libName := ""
libVer := Version()
if c.opt.IdentitySuffix != "" {
libName = c.opt.IdentitySuffix
}
conn.ClientSetInfo(ctx, WithLibraryName(libName))
conn.ClientSetInfo(ctx, WithLibraryVersion(libVer))
}

if c.opt.OnConnect != nil {
return c.opt.OnConnect(ctx, conn)
}
Expand Down
8 changes: 4 additions & 4 deletions ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ type RingOptions struct {
TLSConfig *tls.Config
Limiter Limiter

DisableIndentity bool
IdentitySuffix string
DisableIdentity bool
IdentitySuffix string
}

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

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

Expand Down
8 changes: 4 additions & 4 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ type FailoverOptions struct {

TLSConfig *tls.Config

DisableIndentity bool
IdentitySuffix string
DisableIdentity bool
IdentitySuffix string
}

func (opt *FailoverOptions) clientOptions() *Options {
Expand Down Expand Up @@ -117,8 +117,8 @@ func (opt *FailoverOptions) clientOptions() *Options {

TLSConfig: opt.TLSConfig,

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

Expand Down
16 changes: 8 additions & 8 deletions universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type UniversalOptions struct {

MasterName string

DisableIndentity bool
IdentitySuffix string
DisableIdentity bool
IdentitySuffix string
}

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

TLSConfig: o.TLSConfig,

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

Expand Down Expand Up @@ -158,8 +158,8 @@ func (o *UniversalOptions) Failover() *FailoverOptions {

TLSConfig: o.TLSConfig,

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

Expand Down Expand Up @@ -201,8 +201,8 @@ func (o *UniversalOptions) Simple() *Options {

TLSConfig: o.TLSConfig,

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

Expand Down