mirror of https://github.com/go-redis/redis.git
Add OnConnect context
This commit is contained in:
parent
e779df5ab1
commit
ef82e3705c
|
@ -55,7 +55,7 @@ type ClusterOptions struct {
|
|||
|
||||
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||
|
||||
OnConnect func(*Conn) error
|
||||
OnConnect func(ctx context.Context, cn *Conn) error
|
||||
|
||||
Username string
|
||||
Password string
|
||||
|
|
|
@ -39,7 +39,7 @@ type Options struct {
|
|||
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||
|
||||
// Hook that is called when new connection is established.
|
||||
OnConnect func(*Conn) error
|
||||
OnConnect func(ctx context.Context, cn *Conn) error
|
||||
|
||||
// Use the specified Username to authenticate the current connection with one of the connections defined in the ACL
|
||||
// list when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
|
||||
|
|
2
redis.go
2
redis.go
|
@ -269,7 +269,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
|
|||
}
|
||||
|
||||
if c.opt.OnConnect != nil {
|
||||
return c.opt.OnConnect(conn)
|
||||
return c.opt.OnConnect(ctx, conn)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -372,7 +372,7 @@ var _ = Describe("Client OnConnect", func() {
|
|||
BeforeEach(func() {
|
||||
opt := redisOptions()
|
||||
opt.DB = 0
|
||||
opt.OnConnect = func(cn *redis.Conn) error {
|
||||
opt.OnConnect = func(ctx context.Context, cn *redis.Conn) error {
|
||||
return cn.ClientSetName(ctx, "on_connect").Err()
|
||||
}
|
||||
|
||||
|
|
5
ring.go
5
ring.go
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
@ -62,7 +63,8 @@ type RingOptions struct {
|
|||
|
||||
// Following options are copied from Options struct.
|
||||
|
||||
OnConnect func(*Conn) error
|
||||
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||
OnConnect func(ctx context.Context, cn *Conn) error
|
||||
|
||||
Username string
|
||||
DB int
|
||||
|
@ -115,6 +117,7 @@ func (opt *RingOptions) init() {
|
|||
|
||||
func (opt *RingOptions) clientOptions() *Options {
|
||||
return &Options{
|
||||
Dialer: opt.Dialer,
|
||||
OnConnect: opt.OnConnect,
|
||||
|
||||
DB: opt.DB,
|
||||
|
|
|
@ -28,7 +28,7 @@ type FailoverOptions struct {
|
|||
// Following options are copied from Options struct.
|
||||
|
||||
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||
OnConnect func(*Conn) error
|
||||
OnConnect func(ctx context.Context, cn *Conn) error
|
||||
|
||||
Username string
|
||||
Password string
|
||||
|
@ -54,7 +54,8 @@ type FailoverOptions struct {
|
|||
|
||||
func (opt *FailoverOptions) options() *Options {
|
||||
return &Options{
|
||||
Addr: "FailoverClient",
|
||||
Addr: "FailoverClient",
|
||||
|
||||
Dialer: opt.Dialer,
|
||||
OnConnect: opt.OnConnect,
|
||||
|
||||
|
|
27
universal.go
27
universal.go
|
@ -20,23 +20,28 @@ type UniversalOptions struct {
|
|||
|
||||
// Common options.
|
||||
|
||||
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||
OnConnect func(*Conn) error
|
||||
Username string
|
||||
Password string
|
||||
MaxRetries int
|
||||
MinRetryBackoff time.Duration
|
||||
MaxRetryBackoff time.Duration
|
||||
DialTimeout time.Duration
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
|
||||
OnConnect func(ctx context.Context, cn *Conn) error
|
||||
|
||||
Username string
|
||||
Password string
|
||||
|
||||
MaxRetries int
|
||||
MinRetryBackoff time.Duration
|
||||
MaxRetryBackoff time.Duration
|
||||
|
||||
DialTimeout time.Duration
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
|
||||
PoolSize int
|
||||
MinIdleConns int
|
||||
MaxConnAge time.Duration
|
||||
PoolTimeout time.Duration
|
||||
IdleTimeout time.Duration
|
||||
IdleCheckFrequency time.Duration
|
||||
TLSConfig *tls.Config
|
||||
|
||||
TLSConfig *tls.Config
|
||||
|
||||
// Only cluster clients.
|
||||
|
||||
|
|
Loading…
Reference in New Issue