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

Method deadline

internal/pool/conn.go:980–1008  ·  internal/pool/conn.go::Conn.deadline

deadline computes the effective deadline time based on context and timeout. It updates the usedAt timestamp to now. Uses cached time to avoid expensive syscall (max 50ms staleness is acceptable for deadline calculation).

(ctx context.Context, timeout time.Duration)

Source from the content-addressed store, hash-verified

978// It updates the usedAt timestamp to now.
979// Uses cached time to avoid expensive syscall (max 50ms staleness is acceptable for deadline calculation).
980func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time {
981 // Use cached time for deadline calculation (called 2x per command: read + write)
982 nowNs := getCachedTimeNs()
983 cn.SetUsedAtNs(nowNs)
984 tm := time.Unix(0, nowNs)
985
986 if timeout > 0 {
987 tm = tm.Add(timeout)
988 }
989
990 if ctx != nil {
991 deadline, ok := ctx.Deadline()
992 if ok {
993 if timeout == 0 {
994 return deadline
995 }
996 if deadline.Before(tm) {
997 return deadline
998 }
999 return tm
1000 }
1001 }
1002
1003 if timeout > 0 {
1004 return tm
1005 }
1006
1007 return noDeadline
1008}

Callers 2

WithReaderMethod · 0.95
WithWriterMethod · 0.95

Calls 3

SetUsedAtNsMethod · 0.95
getCachedTimeNsFunction · 0.85
AddMethod · 0.65

Tested by

no test coverage detected