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

Method _getConn

redis.go:402–434  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

400}
401
402func (c *baseClient) _getConn(ctx context.Context) (*pool.Conn, error) {
403 cn, err := c.connPool.Get(ctx)
404 if err != nil {
405 return nil, err
406 }
407
408 if cn.IsInited() {
409 return cn, nil
410 }
411
412 if err := c.initConn(ctx, cn); err != nil {
413 c.connPool.Remove(ctx, cn, err)
414 if err := errors.Unwrap(err); err != nil {
415 return nil, err
416 }
417 return nil, err
418 }
419
420 if dialStartNs := cn.GetDialStartNs(); dialStartNs > 0 {
421 if cb := pool.GetMetricConnectionCreateTimeCallback(); cb != nil {
422 duration := time.Duration(time.Now().UnixNano() - dialStartNs)
423 cb(ctx, duration, cn)
424 }
425 }
426
427 // initConn will transition to IDLE state, so we need to acquire it
428 // before returning it to the user.
429 if !cn.TryAcquire() {
430 return nil, fmt.Errorf("redis: connection is not usable")
431 }
432
433 return cn, nil
434}
435
436func (c *baseClient) reAuthConnection() func(poolCn *pool.Conn, credentials auth.Credentials) error {
437 return func(poolCn *pool.Conn, credentials auth.Credentials) error {

Callers 1

getConnMethod · 0.95

Calls 8

initConnMethod · 0.95
IsInitedMethod · 0.80
GetDialStartNsMethod · 0.80
GetMethod · 0.65
RemoveMethod · 0.65
UnwrapMethod · 0.45
TryAcquireMethod · 0.45

Tested by

no test coverage detected