Skip to content

Commit 0b6be62

Browse files
authored
Identify client on connect (#2708)
* Update CLIENT-SETINFO to support suffixes * Update CLIENT-SETINFO * fix acl log test * add setinfo option to cluster * change to DisableIndentity * change to DisableIndentity
1 parent 54a106e commit 0b6be62

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

bench_decode_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func NewClientStub(resp []byte) *ClientStub {
3030
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
3131
return stub.stubConn(initHello), nil
3232
},
33+
DisableIndentity: true,
3334
})
3435
return stub
3536
}
@@ -45,6 +46,8 @@ func NewClusterClientStub(resp []byte) *ClientStub {
4546
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
4647
return stub.stubConn(initHello), nil
4748
},
49+
DisableIndentity: true,
50+
4851
ClusterSlots: func(_ context.Context) ([]ClusterSlot, error) {
4952
return []ClusterSlot{
5053
{

cluster.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ type ClusterOptions struct {
8383
ConnMaxIdleTime time.Duration
8484
ConnMaxLifetime time.Duration
8585

86-
TLSConfig *tls.Config
86+
TLSConfig *tls.Config
87+
DisableIndentity bool // Disable set-lib on connect. Default is false.
8788
}
8889

8990
func (opt *ClusterOptions) init() {
@@ -277,15 +278,15 @@ func (opt *ClusterOptions) clientOptions() *Options {
277278
ReadTimeout: opt.ReadTimeout,
278279
WriteTimeout: opt.WriteTimeout,
279280

280-
PoolFIFO: opt.PoolFIFO,
281-
PoolSize: opt.PoolSize,
282-
PoolTimeout: opt.PoolTimeout,
283-
MinIdleConns: opt.MinIdleConns,
284-
MaxIdleConns: opt.MaxIdleConns,
285-
ConnMaxIdleTime: opt.ConnMaxIdleTime,
286-
ConnMaxLifetime: opt.ConnMaxLifetime,
287-
288-
TLSConfig: opt.TLSConfig,
281+
PoolFIFO: opt.PoolFIFO,
282+
PoolSize: opt.PoolSize,
283+
PoolTimeout: opt.PoolTimeout,
284+
MinIdleConns: opt.MinIdleConns,
285+
MaxIdleConns: opt.MaxIdleConns,
286+
ConnMaxIdleTime: opt.ConnMaxIdleTime,
287+
ConnMaxLifetime: opt.ConnMaxLifetime,
288+
DisableIndentity: opt.DisableIndentity,
289+
TLSConfig: opt.TLSConfig,
289290
// If ClusterSlots is populated, then we probably have an artificial
290291
// cluster whose nodes are not in clustering mode (otherwise there isn't
291292
// much use for ClusterSlots config). This means we cannot execute the

commands.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"context"
55
"encoding"
66
"errors"
7+
"fmt"
78
"io"
89
"net"
910
"reflect"
11+
"runtime"
1012
"strings"
1113
"time"
1214

@@ -584,7 +586,8 @@ func (c statefulCmdable) ClientSetInfo(ctx context.Context, info LibraryInfo) *S
584586

585587
var cmd *StatusCmd
586588
if info.LibName != nil {
587-
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", *info.LibName)
589+
libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, runtime.Version())
590+
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", libName)
588591
} else {
589592
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-VER", *info.LibVer)
590593
}

commands_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,10 +2052,9 @@ var _ = Describe("Commands", func() {
20522052

20532053
logEntries, err := client.ACLLog(ctx, 10).Result()
20542054
Expect(err).NotTo(HaveOccurred())
2055-
Expect(len(logEntries)).To(Equal(3))
2055+
Expect(len(logEntries)).To(Equal(4))
20562056

20572057
for _, entry := range logEntries {
2058-
Expect(entry.Count).To(BeNumerically("==", 1))
20592058
Expect(entry.Reason).To(Equal("command"))
20602059
Expect(entry.Context).To(Equal("toplevel"))
20612060
Expect(entry.Object).NotTo(BeEmpty())

options.go

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

137137
// Enables read only queries on slave/follower nodes.
138138
readOnly bool
139+
140+
// // Disable set-lib on connect. Default is false.
141+
DisableIndentity bool
139142
}
140143

141144
func (opt *Options) init() {

redis.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,14 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
299299
// difficult to rely on error strings to determine all results.
300300
return err
301301
}
302-
302+
if !c.opt.DisableIndentity {
303+
libName := ""
304+
libVer := Version()
305+
libInfo := LibraryInfo{LibName: &libName}
306+
conn.ClientSetInfo(ctx, libInfo)
307+
libInfo = LibraryInfo{LibVer: &libVer}
308+
conn.ClientSetInfo(ctx, libInfo)
309+
}
303310
_, err := conn.Pipelined(ctx, func(pipe Pipeliner) error {
304311
if !auth && password != "" {
305312
if username != "" {

0 commit comments

Comments
 (0)