File tree Expand file tree Collapse file tree 4 files changed +33
-0
lines changed Expand file tree Collapse file tree 4 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,23 @@ var timers = sync.Pool{
2727	},
2828}
2929
30+ type  ConnectEvent  struct  {
31+         Err  error 
32+ }
33+ 
34+ type  PoolHook  interface  {
35+         BeforeConnect (ctx  context.Context ) (context.Context , error )
36+         AfterConnect (ctx  context.Context , event  ConnectEvent ) error 
37+ }
38+ 
39+ type  hooks  struct   {
40+ 	hooks  []PoolHook 
41+ }
42+ 
43+ func  (hs  * hooks ) AddHook (hook  PoolHook ) {
44+ 	hs .hooks  =  append (hs .hooks , hook )
45+ }
46+ 
3047// Stats contains pool state information and accumulated stats. 
3148type  Stats  struct  {
3249	Hits      uint32  // number of times free connection was found in the pool 
@@ -39,6 +56,8 @@ type Stats struct {
3956}
4057
4158type  Pooler  interface  {
59+ 	AddHook (hook  PoolHook )
60+ 
4261	NewConn (context.Context ) (* Conn , error )
4362	CloseConn (* Conn ) error 
4463
@@ -70,6 +89,8 @@ type lastDialErrorWrap struct {
7089}
7190
7291type  ConnPool  struct  {
92+ 	hooks 
93+ 
7394	opt  * Options 
7495
7596	dialErrorsNum  uint32  // atomic 
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package pool
33import  "context" 
44
55type  SingleConnPool  struct  {
6+ 	hooks 
67	pool       Pooler 
78	cn         * Conn 
89	stickyErr  error 
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ func (e BadConnError) Unwrap() error {
3434//------------------------------------------------------------------------------ 
3535
3636type  StickyConnPool  struct  {
37+ 	hooks 
3738	pool    Pooler 
3839	shared  int32  // atomic 
3940
Original file line number Diff line number Diff line change 66	"fmt" 
77	"sync/atomic" 
88	"time" 
9+ 	"unsafe" 
910
1011	"github.com/go-redis/redis/v8/internal" 
1112	"github.com/go-redis/redis/v8/internal/pool" 
@@ -29,6 +30,11 @@ type Hook interface {
2930	AfterProcessPipeline (ctx  context.Context , cmds  []Cmder ) error 
3031}
3132
33+ type  fullHook  interface  {
34+ 	Hook 
35+ 	pool.PoolHook 
36+ }
37+ 
3238type  hooks  struct  {
3339	hooks  []Hook 
3440}
@@ -45,6 +51,10 @@ func (hs hooks) clone() hooks {
4551
4652func  (hs  * hooks ) AddHook (hook  Hook ) {
4753	hs .hooks  =  append (hs .hooks , hook )
54+ 	if  hook , ok  :=  hook .(fullHook ); ok  {
55+ 		client  :=  * (* Client )(unsafe .Pointer (hs ))
56+ 		client .baseClient .connPool .AddHook (hook )
57+ 	}
4858}
4959
5060func  (hs  hooks ) process (
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments