mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-28 03:57:02 +02:00
18 lines
321 B
Go
18 lines
321 B
Go
|
package redis
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func shrinkDeadline(ctx context.Context, timeout time.Duration) time.Time {
|
||
|
var timeoutTime = time.Now().Add(timeout)
|
||
|
if ctx == nil {
|
||
|
return timeoutTime
|
||
|
}
|
||
|
if deadline, ok := ctx.Deadline(); ok && timeoutTime.After(deadline) {
|
||
|
return deadline
|
||
|
}
|
||
|
return timeoutTime
|
||
|
}
|