// TTL returns the remaining time-to-live for an item.
// A negative duration will be returned for items that do not have an
// expiration.
502497
func (tx *Tx) TTL(key string) (time.Duration, error) {
	if tx.db == nil {
		return 0, ErrTxClosed
	}
	item := tx.db.get(key)
	if item == nil {
		return 0, ErrNotFound
	} else if item.opts == nil || !item.opts.ex {
		return -1, nil
	}
	dur := item.opts.exat.Sub(time.Now())
	if dur < 0 {
		return 0, ErrNotFound
	}
	return dur, nil
}
324650
func (db *DB) LTTL(key []byte) (int64, error) {
	if err := checkKeySize(key); err != nil {
		return -1, err
	}

	return db.ttl(ListType, key)
}
591569
func ValidateLockTTL(ttl time.Duration) error {
	if ttl == Forever || ttl > MaxLockDuration {
		return trace.BadParameter("locks cannot exceed %v", MaxLockDuration)
	}
	return nil
}
591399
func (lru *TTLRUCache) AddWithTTL(key, val interface{}, ttl time.Duration) {
	lru.AddWithExpire(key, val, time.Now().Add(ttl))
}
1131387
func readTTL(rootDir string, bucket string, key string) (time.Duration, bool, error) {
	filename := filepath.Join(rootDir, bucket, "."+key+".ttl")

	bytes, err := ioutil.ReadFile(filename)
	if err != nil {
		if os.IsNotExist(err) {
			return legacy.Forever, false, nil
		}
		return legacy.Forever, false, trace.Wrap(err)
	}
	if len(bytes) == 0 {
		return legacy.Forever, false, nil
	}

	var expiryTime time.Time
	if err = expiryTime.UnmarshalText(bytes); err != nil {
		return legacy.Forever, false, trace.Wrap(err)
	}

	ttl := expiryTime.Sub(time.Now())
	if ttl < 0 {
		return legacy.Forever, true, nil
	}
	return ttl, false, nil
}
1197418
func TTL(t time.Duration) func(Call) error {
	return func(o Call) error {
		m, ok := o.(*Mutate)
		if !ok {
			return errors.New("'TTL' option can only be used with mutation queries")
		}

		buf := make([]byte, 8)
		binary.BigEndian.PutUint64(buf, uint64(t.Nanoseconds()/1e6))
		m.ttl = buf

		return nil
	}
}
290981
func (u *UserV2) SetTTL(clock clockwork.Clock, ttl time.Duration) {
	u.Metadata.SetTTL(clock, ttl)
}
612160
func SetTTL(duration time.Duration) Option {
	return func(m *MongoCache) {
		m.TTL = duration
	}
}
1345784
func (c *GithubConnectorV3) SetTTL(clock clockwork.Clock, ttl time.Duration) {
	c.Metadata.SetTTL(clock, ttl)
}
97417
func (soc *Socket) SetHeartbeatTtl(value time.Duration) error {
	if minor < 2 {
		return ErrorNotImplemented42
	}
	val := int(value / time.Millisecond)
	return soc.setInt(C.ZMQ_HEARTBEAT_TTL, val)
}
391246
func PoolTTL(d time.Duration) Option {
	return func(o *Options) {
		o.PoolTTL = d
	}
}
1055952
func (s *UpdateBranchInput) SetTtl(v string) *UpdateBranchInput {
	s.Ttl = &v
	return s
}
579950
func (db *DB) ZTTL(key []byte) (int64, error) {
	if err := checkKeySize(key); err != nil {
		return -1, err
	}

	return db.ttl(ZSetType, key)
}
503912
func (s *CreateTrafficPolicyInstanceInput) SetTTL(v int64) *CreateTrafficPolicyInstanceInput {
	s.TTL = &v
	return s
}
1125191
func MinTTL(a, b time.Duration) time.Duration {
	if a == 0 {
		return b
	}
	if b == 0 {
		return a
	}
	if a < b {
		return a
	}
	return b
}
752324
func (m *Metadata) SetTTL(clock clockwork.Clock, ttl time.Duration) {
	expireTime := clock.Now().UTC().Add(ttl)
	m.Expires = &expireTime
}
174061
func (pool *Pool) TTL(ttl time.Duration) *Pool {
	pool.conf.TTL = ttl
	return &Pool{redis: pool.redis, conf: pool.conf}
}