MCPcopy
hub / github.com/redis/go-redis / OnGet

Method OnGet

maintnotifications/pool_hook.go:123–137  ·  view source on GitHub ↗

OnGet is called when a connection is retrieved from the pool

(_ context.Context, conn *pool.Conn, _ bool)

Source from the content-addressed store, hash-verified

121
122// OnGet is called when a connection is retrieved from the pool
123func (ph *PoolHook) OnGet(_ context.Context, conn *pool.Conn, _ bool) (accept bool, err error) {
124 // Check if connection is marked for handoff
125 // This prevents using connections that have received MOVING notifications
126 if conn.ShouldHandoff() {
127 return false, ErrConnectionMarkedForHandoffWithState
128 }
129
130 // Check if connection is usable (not in UNUSABLE or CLOSED state)
131 // This ensures we don't return connections that are currently being handed off or re-authenticated.
132 if !conn.IsUsable() {
133 return false, ErrConnectionMarkedForHandoff
134 }
135
136 return true, nil
137}
138
139// OnPut is called when a connection is returned to the pool
140func (ph *PoolHook) OnPut(ctx context.Context, conn *pool.Conn) (shouldPool bool, shouldRemove bool, err error) {

Callers 1

TestConnectionHookFunction · 0.95

Calls 2

ShouldHandoffMethod · 0.80
IsUsableMethod · 0.80

Tested by 1

TestConnectionHookFunction · 0.76