Set ttl for a key
@param string $key key
@param int $timeout ttl in milliseconds
@return bool operation result. If false ttl cound not be set, or key not found
@throws ConnectException exception on connection to redis instance
344133
public function expire($key, $timeout) {
        try {
            return $this->getRedis()->pexpire($key, $timeout);
        } catch (RedisException $ex) {
            throw new ConnectException();
        }
    }
382003
public function setnx($key, $value) {
        try {
            return $this->getRedis()->setnx($key, $value);
        } catch (RedisException $ex) {
            throw new ConnectException();
        }
    }
477338
public function setTimeout($timeout)
  {
    // Since this timeout is really for putting a bound on the time
    // we'll set them both to the same. If you need to specify a longer
    // CURLOPT_TIMEOUT, or a higher CONNECTTIMEOUT, the best thing to
    // do is use the setOptions method for the values individually.
    $this->options[CURLOPT_CONNECTTIMEOUT] = $timeout;
    $this->options[CURLOPT_TIMEOUT] = $timeout;
  }
780989
def raise_or_lock(self, key, timeout):
        
        acquired = Lock(
            self.redis,
            key,
            timeout=timeout,
            blocking=self.blocking,
            blocking_timeout=self.blocking_timeout
        ).acquire()

        if not acquired:
            # Time remaining in milliseconds
            # https://redis.io/commands/pttl
            ttl = self.redis.pttl(key)
            raise AlreadyQueued(ttl / 1000.)
137696
public static function setTimeout($timeout = 60) {
        if (!is_int($timeout) || $timeout < 0) {
            return false;
        }

        self::$timeout = $timeout;
        return true;
    }
708722
public function updateDir($key, $ttl)
    {
        if (!$ttl) {
            throw new EtcdException('TTL is required', 204);
        }

        return $this->httpPut($this->getKeyUrl($key), ['ttl' => (int) $ttl], [
            'dir' => 'true',
            'prevExist' => 'true',
        ]);
    }
403670
final public function expire($key, $ttl) {
		$method = 'setTimeout';
		if ($this->redistype == 'predis')
			$method = 'expire';
		$res = $this->connection->$method($key, $ttl);
		self::$logger->info(sprintf(
			"Redis: expire %s: %s.", $key, $ttl));
		return $res;
	}
1054602
public function set($key, $data) {
        if ($this->clustered) {
            $status = true;
            foreach ($this->setconnections as $connection) {
                $status = $connection->set($key, $data, $this->definition->get_ttl()) && $status;
            }
            return $status;
        }

        return $this->connection->set($key, $data, $this->definition->get_ttl());
    }
147491
public function setTimeout($timeout)
    {
        if ($timeout === null) {
            $this->timeout = null;
            $this->onConfigChanged();
            return;
        }

        $timeout = (int)$timeout;

        if ($timeout < 0) {
            throw new Exception\InvalidArgumentException('$timeout must be between positive (0+)');
        }

        $this->timeout = $timeout;
        $this->onConfigChanged();
    }
719020
public function setResult($key, $result, $ttl)
    {
        if (!($ttl instanceof Ttl)) {
            $ttl = new Ttl($ttl);
        }

        $expirationTimestamp = time() + $ttl->getTtl();
        $value = new Value($result, $expirationTimestamp);

        $this->valueStore->set($key, $value, $ttl->getRealTtl());
    }
694498
public function connect($timeout = 0.5)
    {
        if (!extension_loaded('swoole'))
        {
            throw new \Exception('swoole extension is required for WebSocketAsync');
        }

        //没有onMessage
        if (!$this->_callback('message'))
        {
            throw new \Exception('no message event callback.');
        }

        $type = SWOOLE_TCP;
        if ($this->ssl)
        {
            $type |= SWOOLE_SSL;
        }

        $this->socket = new \swoole_client($type, SWOOLE_SOCK_ASYNC);
        if ($this->ssl_key_file)
        {
            $this->socket->set(array(
                'ssl_key_file' => $this->ssl_key_file,
                'ssl_cert_file' => $this->ssl_cert_file
            ));
        }

        $this->socket->on("connect", array($this, 'onConnect'));
        $this->socket->on("receive", array($this, 'onReceive'));
        $this->socket->on("error", array($this, 'onError'));
        $this->socket->on("close", array($this, 'onClose'));

        $this->socket->connect($this->host, $this->port, $timeout);
    }
414306
public function connect($timeout = 5.0)
    {
        if (true === $this->isConnected()) {
            return false;
        }

        $errorNumber = 0;
        $errorMessage = '';

        $this->connection = @fsockopen(
            $this->parameters['host'],
            $this->parameters['port'],
            $errorNumber,
            $errorMessage,
            $timeout
        );

        if (false === $this->isConnected()) {
            throw new GearmanConnectionException($errorMessage, $errorNumber);
        }

        return true;
    }
1077300
final public function check(string $addr, int $port = 0, int $timeout = 3, int $ttl = 30): Result {
        $key = sprintf("%s::%s:%d", static::class, $addr, $port);
        $result = $this->cache()->get($key);
        if (empty($result)) {
            $result = $this->checkAtOnce($addr, $port, $timeout);
            if (false === $this->cache()->set($key, $result, $ttl)) {
                throw new \Exception('set cache error: checker('.static::class.'), key('.$key.'), result('.$result.').');
            }
        }
        return $result;
    }
1178429
public function set($key, $value, $ttl = 0) {
        if (is_resource($value)) {
            return false;
        }
        $used_key = $this->getUsedKey($key);
        $res = $this->redis->set($used_key, $this->esc($value));

        if ($res !== 'OK') {
            return false;
        }

        if ($ttl === 0) {
            return true;
        }
        if ($ttl != 0 && $ttl > 2592000) {
            $ttl -= time();
        }
        if ($ttl <= 0) {
            return true;
        }

        return ($this->redis->expire($used_key, $ttl) == 1);
    }
914995
public function set($key, $value, $duration = null)
    {
        // TODO: Implement set() method.
        if ($this->connected) {
            return $this->conn->set($key, $value, null, $duration);
        }
    }
747524
public function setConnectionTimeout($timeout)
    {
        ValidationUtility::ensureInteger('$timeout', $timeout);

        if ($timeout < 0)
        {
            throw new \InvalidArgumentException('The given timeout value is negative.');
        }

        $this->connectionTimeout = $timeout;

        return $this;
    }
193988
public function retry($timeout, $callback)
    {
        $start = time();

        beginning:

        if ($output = $callback()) {
            return $output;
        }

        if (time() - $start < $timeout) {
            sleep(5);

            goto beginning;
        }

        throw new TimeoutException($output);
    }