@param int $lastUpdateId
@param int $limit
@param int $timeout

@return \Generator
@resolve Update[]
770797
public function getUpdates($lastUpdateId = null, int $limit = 5, int $timeout = 30) : \Generator
    {
        if ($lastUpdateId !== null) {
            $this->lastUpdateId = $lastUpdateId;
        }

        $method = new GetUpdates($this->lastUpdateId + 1, $limit, $timeout);

        $updates = yield from $this->execute($method);
        $this->lastUpdateId = $method->getLastUpdateId();

        return $updates;
    }
132323
public void update(LimitOrder limitOrder) {

    update(getOrders(limitOrder.getType()), limitOrder);
    updateDate(limitOrder.getTimestamp());
  }
947317
public static function history($limit=50, $uid=null)
	{
		$model = self::all();

		if ($limit)
		{
			$model->limit((int)$limit);
		}

		if ($uid)
		{
			$model->whereEquals('uid', $uid);
		}

		return $model->order('created', 'desc')->rows();
	}
636991
public function get_session_lock($rowid, $timeout) {
        parent::get_session_lock($rowid, $timeout);

        $fullname = $this->dbname.'-'.$this->prefix.'-session-'.$rowid;
        $sql = "SELECT GET_LOCK('$fullname', $timeout)";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = $this->mysqli->query($sql);
        $this->query_end($result);

        if ($result) {
            $arr = $result->fetch_assoc();
            $result->close();

            if (reset($arr) == 1) {
                return;
            } else {
                throw new dml_sessionwait_exception();
            }
        }
    }
756337
public function update($data, Criteria $where, $limit=false)
    {
        if(empty($data))
            throw new Exception("Can't insert an empty row");

        return $this->_connection->execute(sprintf(
            'UPDATE %s SET %s WHERE %s%s',
            $this->_name->quoted(),
            $this->_buildSet($data),
            $where,
            $limit ? ' LIMIT '.intval($limit) : ''
            ), array_values($data)
        );
    }
1254389
final public function runMulti($idleTimeout = null, callable $callback = null)
    {
        $this->resetRetryCount();

        $successful = false;
        while (! $successful && $this->getRetryCount() < $this->getRetryLimit()) {
            $successful = $this->runOnce($idleTimeout, $callback);
            $this->increaseRetryCount();

            yield $successful;
        }
    }
6089
public function generateLimit($limitCount, $limitOffset, &$limit)
    {
        $limit = "";

        if (empty($limitCount)) {
            return;
        }

        $limit = "$limitCount";

        if (! empty($limitOffset)) {
            $limit .= ",$limitOffset";
        }
    }
644787
protected function getLastSearchesFromSession($limit)
    {
        $lastSearches = $this->session->getLastSearches();
        $lastSearches = array_slice(array_reverse(array_unique($lastSearches)), 0, $limit);

        return $lastSearches;
    }
1081556
public function refreshToken($refreshToken, $timeOut = 7200, $prefix = '')
    {
        $token = Cache::get($refreshToken);
        if (empty($token)) {
            throw new Exception('refresh_token已经过期');
        }
        $permission = Cache::get($token);
        if (empty($permission)) {
            throw new Exception('token已经过期');
        }
        $token = md5($prefix . $this->randCode(32) . $this->saltToken . time());
        $freshTOken = md5($prefix . $this->randCode(32) . $this->saltToken . time());
        Cache::set($token, $permission, $timeOut);
        Cache::set($freshTOken, $token);
        return [
            'token' => $token,
            'refresh_token' => $freshTOken,
            'expire' => $timeOut
        ];

    }
485023
public function createUpdateQuery($old, $new, $prefix = "")
    {
        $update = [];

        foreach ($new as $key => $value) {
            if (is_array($old) && array_key_exists($key, $old)) {
                if (is_array($value) && strstr(key($value), '$') !== false) {
                    $update[key($value)][$prefix . $key] = $value[key($value)];
                } elseif (is_array($value) && is_array($old[$key])) {
                    if (!empty($old[$key])) {
                        $embeddedUpdate = array_merge_recursive($update, $this->createUpdateQuery($old[$key], $value, $prefix . $key . "."));
                        if (isset($embeddedUpdate['$unset']) && array_values($old[$key]) === $old[$key] && $value !== null && count(array_filter(array_keys($value), 'is_string')) == 0) {
                            $update['$set'][$prefix . $key] = array_values($value);
                        } else {
                            foreach ($embeddedUpdate as $updateOperator => $value) {
                                if (!isset($update[$updateOperator])) {
                                    $update[$updateOperator] = [];
                                }
                                $update[$updateOperator] += $value;
                            }
                        }
                    } elseif (!empty($value)) {
                        $update['$set'][$prefix . $key] = $value;
                    }
                } else {
                    if ($value !== null && $value !== $old[$key]) {
                        if ($value instanceof \MongoDB\BSON\UTCDateTime && $old[$key] instanceof \MongoDB\BSON\UTCDateTime) {
                            if (serialize($value) != serialize($old[$key])) {
                                $update['$set'][$prefix . $key] = $value;
                            }
                        } else {
                            $update['$set'][$prefix . $key] = $value;
                        }
                    } elseif ($value === null && $old[$key] !== null) {
                        $update['$unset'][$prefix . $key] = 1;
                    }
                }
            } else {
                if (is_array($value) && strstr(key($value), '$') === false) {
                    $embeddedQuery = $this->createUpdateQuery([], $value, $prefix . $key . ".");
                    if (count($embeddedQuery) == 1 && key($embeddedQuery) == '$set') {
                        $update['$set'][$prefix . $key] = $value;
                    } else {
                        $update = array_merge_recursive($update, $embeddedQuery);
                    }
                } elseif (is_array($value) && strstr(key($value), '$') !== false) {
                    $update[key($value)][$prefix . $key] = $value[key($value)];
                } else {
                    $update['$set'][$prefix . $key] = $value;
                }
            }

            unset($new[$key]);
            unset($old[$key]);
        }
        if (is_array($old)) {
            foreach (array_keys($old) as $key) {
                $update['$unset'][$prefix . $key] = 1;
            }
        }

        if (isset($update['$set']['_id'])) {
            unset($update['$set']['_id']);
        }

        foreach ($update as $modifier => $value) {
            if (empty($value)) {
                unset($update[$modifier]);
            }
        }

        return $update;
    }
1065833
protected function readTableData(string $tableName, int $limit = null): array
    {
        assert($limit === null || $limit > 0);

        $builder = $this->getConnection()->createQueryBuilder();
        $builder
            ->select('*')
            ->from($tableName);

        $limit === null ?: $builder->setMaxResults($limit);

        $result = $builder->execute()->fetchAll(PDO::FETCH_ASSOC);

        return $result;
    }
1134572
public function getErrorsForUpgrade($limit)
    {
        $query = 'SELECT * FROM build_meta
                    WHERE meta_key IN (\'phpmd-data\', \'phpcs-data\', \'phpdoccheck-data\')
                    ORDER BY id ASC LIMIT :limit';

        $stmt = Database::getConnection('read')->prepare($query);

        $stmt->bindValue(':limit', $limit, \PDO::PARAM_INT);

        if ($stmt->execute()) {
            $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);

            $map = function ($item) {
                return new BuildMeta($item);
            };
            $rtn = array_map($map, $res);

            return $rtn;
        } else {
            return array();
        }
    }
73935
public function iterate($timeout)
    {

        // call parent method and sleep for the default timeout
        parent::iterate($timeout);

        // create the requested timer instance
        $this->synchronized(function ($self) {

            // create the calendar timer, only if we're NOT dispatched
            if ($self->dispatched === false) {
                $self->timer = CalendarTimer::builder()
                    ->setAutoTimer($self->timeoutMethod != null)
                    ->setScheduleExprSecond($self->schedule->getSecond())
                    ->setScheduleExprMinute($self->schedule->getMinute())
                    ->setScheduleExprHour($self->schedule->getHour())
                    ->setScheduleExprDayOfWeek($self->schedule->getDayOfWeek())
                    ->setScheduleExprDayOfMonth($self->schedule->getDayOfMonth())
                    ->setScheduleExprMonth($self->schedule->getMonth())
                    ->setScheduleExprYear($self->schedule->getYear())
                    ->setScheduleExprStartDate($self->schedule->getStart())
                    ->setScheduleExprEndDate($self->schedule->getEnd())
                    ->setScheduleExprTimezone($self->schedule->getTimezone())
                    ->setTimeoutMethod($self->timeoutMethod)
                    ->setTimerState(TimerState::CREATED)
                    ->setId(Uuid::uuid4()->__toString())
                    ->setPersistent($self->persistent)
                    ->setTimedObjectId($self->timerService->getTimedObjectInvoker()->getTimedObjectId())
                    ->setInfo($self->info)
                    ->setNewTimer(true)
                    ->build($self->timerService);

                // we're dispatched now
                $self->dispatched = true;
            }

        }, $this);

        // profile the size of the sessions
        if ($this->profileLogger) {
            $this->profileLogger->debug(
                sprintf('Size of session pool is: %d', sizeof($this->sessionPool))
            );
        }
    }
396208
public function get($limit = null, $offset = null)
    {
        if (isset($limit)) {
            $this->limit($limit, $offset);
        }

        if (false !== ($result = $this->conn->query($this->builderCache))) {
            $result->setTotalRows($this->countAllResults(true));
        }

        $this->builderCache->reset();

        return $result;
    }
989084
public function timeout($timeout): ProcessBuilder
    {
        if ($timeout === null) {
            $this->timeout = null;

            return $this;
        }

        $timeout = (float) $timeout;

        if ($timeout < 0) {
            throw new DomainException('Timeout must be a positive number');
        }

        $this->timeout = $timeout;

        return $this;
    }
380080
public static function nblock($lock, \Closure $callback, $timeout = 120) {
        try {
            $redis = RedisClient::getRedis();
            if ($redis) {
                $cnt = $redis->incr($lock);
                if ($cnt != 1) {
                    return false;
                }
                $redis->setTimeout($lock, $timeout);
                try {
                    return $callback($redis);
                } catch (\Exception $e) {
                    log_warn($e->getMessage(), 'redis_lock');
                } finally {
                    $redis->decr($lock);
                }
            }
        } catch (\Exception $e) {
            log_warn($e->getMessage(), 'redis_lock');
        }

        return false;
    }
717763
public function readByUser(int $userId, int $expirationInSeconds, int $limit = null): array
    {
        try {
            /** @var TokenInterface[] $tokens */
            $tokens = parent::readByUser($userId, $expirationInSeconds, $limit);

            // select scope identifiers for tokens
            if (empty($tokens) === false) {
                $schema        = $this->getDatabaseSchema();
                $tokenIdColumn = $schema->getTokensScopesTokenIdentityColumn();
                $scopeIdColumn = $schema->getTokensScopesScopeIdentityColumn();

                $connection = $this->getConnection();
                $query      = $connection->createQueryBuilder();

                $tokenIds = array_keys($tokens);
                $query
                    ->select([$tokenIdColumn, $scopeIdColumn])
                    ->from($schema->getTokensScopesTable())
                    ->where($query->expr()->in($tokenIdColumn, $tokenIds))
                    ->orderBy($tokenIdColumn);

                $statement = $query->execute();
                $statement->setFetchMode(PDO::FETCH_ASSOC);
                $tokenScopePairs = $statement->fetchAll();

                $curTokenId = null;
                $curScopes  = null;
                // set selected scopes to tokens
                foreach ($tokenScopePairs as $pair) {
                    $tokenId = $pair[$tokenIdColumn];
                    $scopeId = $pair[$scopeIdColumn];

                    if ($curTokenId !== $tokenId) {
                        $assignScopes = $curTokenId !== null && empty($curScopes) === false;
                        $assignScopes ? $tokens[$curTokenId]->setScopeIdentifiers($curScopes) : null;
                        $curTokenId = $tokenId;
                        $curScopes  = [$scopeId];

                        continue;
                    }

                    $curScopes[] = $scopeId;
                }
                $curTokenId === null || empty($curScopes) === true ?:
                    $tokens[$curTokenId]->setScopeIdentifiers($curScopes);
            }

            return $tokens;
        } /** @noinspection PhpRedundantCatchClauseInspection */ catch (RepositoryException | DBALEx $exception) {
            $message = 'Token reading failed.';
            throw new RepositoryException($message, 0, $exception);
        }
    }