mirror of https://github.com/go-redis/redis.git
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
This commit is contained in:
parent
54a106ee19
commit
0b6be62b71
|
@ -30,6 +30,7 @@ func NewClientStub(resp []byte) *ClientStub {
|
||||||
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
return stub.stubConn(initHello), nil
|
return stub.stubConn(initHello), nil
|
||||||
},
|
},
|
||||||
|
DisableIndentity: true,
|
||||||
})
|
})
|
||||||
return stub
|
return stub
|
||||||
}
|
}
|
||||||
|
@ -45,6 +46,8 @@ func NewClusterClientStub(resp []byte) *ClientStub {
|
||||||
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
return stub.stubConn(initHello), nil
|
return stub.stubConn(initHello), nil
|
||||||
},
|
},
|
||||||
|
DisableIndentity: true,
|
||||||
|
|
||||||
ClusterSlots: func(_ context.Context) ([]ClusterSlot, error) {
|
ClusterSlots: func(_ context.Context) ([]ClusterSlot, error) {
|
||||||
return []ClusterSlot{
|
return []ClusterSlot{
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,6 +84,7 @@ type ClusterOptions struct {
|
||||||
ConnMaxLifetime time.Duration
|
ConnMaxLifetime time.Duration
|
||||||
|
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
DisableIndentity bool // Disable set-lib on connect. Default is false.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *ClusterOptions) init() {
|
func (opt *ClusterOptions) init() {
|
||||||
|
@ -284,7 +285,7 @@ func (opt *ClusterOptions) clientOptions() *Options {
|
||||||
MaxIdleConns: opt.MaxIdleConns,
|
MaxIdleConns: opt.MaxIdleConns,
|
||||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||||
|
DisableIndentity: opt.DisableIndentity,
|
||||||
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
|
||||||
|
|
|
@ -4,9 +4,11 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding"
|
"encoding"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -584,7 +586,8 @@ func (c statefulCmdable) ClientSetInfo(ctx context.Context, info LibraryInfo) *S
|
||||||
|
|
||||||
var cmd *StatusCmd
|
var cmd *StatusCmd
|
||||||
if info.LibName != nil {
|
if info.LibName != nil {
|
||||||
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", *info.LibName)
|
libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, runtime.Version())
|
||||||
|
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", libName)
|
||||||
} else {
|
} else {
|
||||||
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-VER", *info.LibVer)
|
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-VER", *info.LibVer)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2052,10 +2052,9 @@ var _ = Describe("Commands", func() {
|
||||||
|
|
||||||
logEntries, err := client.ACLLog(ctx, 10).Result()
|
logEntries, err := client.ACLLog(ctx, 10).Result()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(logEntries)).To(Equal(3))
|
Expect(len(logEntries)).To(Equal(4))
|
||||||
|
|
||||||
for _, entry := range logEntries {
|
for _, entry := range logEntries {
|
||||||
Expect(entry.Count).To(BeNumerically("==", 1))
|
|
||||||
Expect(entry.Reason).To(Equal("command"))
|
Expect(entry.Reason).To(Equal("command"))
|
||||||
Expect(entry.Context).To(Equal("toplevel"))
|
Expect(entry.Context).To(Equal("toplevel"))
|
||||||
Expect(entry.Object).NotTo(BeEmpty())
|
Expect(entry.Object).NotTo(BeEmpty())
|
||||||
|
|
|
@ -136,6 +136,9 @@ type Options struct {
|
||||||
|
|
||||||
// Enables read only queries on slave/follower nodes.
|
// Enables read only queries on slave/follower nodes.
|
||||||
readOnly bool
|
readOnly bool
|
||||||
|
|
||||||
|
// // Disable set-lib on connect. Default is false.
|
||||||
|
DisableIndentity bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *Options) init() {
|
func (opt *Options) init() {
|
||||||
|
|
9
redis.go
9
redis.go
|
@ -299,7 +299,14 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
|
||||||
// difficult to rely on error strings to determine all results.
|
// difficult to rely on error strings to determine all results.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if !c.opt.DisableIndentity {
|
||||||
|
libName := ""
|
||||||
|
libVer := Version()
|
||||||
|
libInfo := LibraryInfo{LibName: &libName}
|
||||||
|
conn.ClientSetInfo(ctx, libInfo)
|
||||||
|
libInfo = LibraryInfo{LibVer: &libVer}
|
||||||
|
conn.ClientSetInfo(ctx, libInfo)
|
||||||
|
}
|
||||||
_, err := conn.Pipelined(ctx, func(pipe Pipeliner) error {
|
_, err := conn.Pipelined(ctx, func(pipe Pipeliner) error {
|
||||||
if !auth && password != "" {
|
if !auth && password != "" {
|
||||||
if username != "" {
|
if username != "" {
|
||||||
|
|
Loading…
Reference in New Issue