Merge branch '4.4' into 5.2

* 4.4:
  [Cache] Add server-commands support for Predis Replication Environments
  Speedup psalm
This commit is contained in:
Nicolas Grekas 2021-02-26 00:54:56 +01:00
commit 2068652fc9
7 changed files with 277 additions and 291 deletions

View File

@ -8,8 +8,11 @@ on:
paths: paths:
- 'src/Symfony/Component/Intl/Resources/data/**' - 'src/Symfony/Component/Intl/Resources/data/**'
jobs: defaults:
run:
shell: bash
jobs:
tests: tests:
name: Tests (intl-data) name: Tests (intl-data)
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -8,8 +8,11 @@ on:
paths: paths:
- 'src/Symfony/Bridge/PhpUnit/**' - 'src/Symfony/Bridge/PhpUnit/**'
jobs: defaults:
run:
shell: bash
jobs:
lint: lint:
name: Lint name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -3,6 +3,10 @@ name: Static analysis
on: on:
pull_request: ~ pull_request: ~
defaults:
run:
shell: bash
jobs: jobs:
psalm: psalm:
name: Psalm name: Psalm
@ -17,81 +21,38 @@ jobs:
ini-values: "memory_limit=-1" ini-values: "memory_limit=-1"
coverage: none coverage: none
- name: Checkout PR - name: Checkout target branch
uses: actions/checkout@v2
with:
path: pr
- name: Checkout base
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
ref: ${{ github.base_ref }} ref: ${{ github.base_ref }}
path: base
- name: Checkout PR
uses: actions/checkout@v2
- name: Configure composer - name: Configure composer
run: | run: |
cd base
COMPOSER_HOME="$(composer config home)" COMPOSER_HOME="$(composer config home)"
([ -d "$COMPOSER_HOME" ] || mkdir "$COMPOSER_HOME") && cp .github/composer-config.json "$COMPOSER_HOME/config.json" ([ -d "$COMPOSER_HOME" ] || mkdir "$COMPOSER_HOME") && cp .github/composer-config.json "$COMPOSER_HOME/config.json"
echo "COMPOSER_ROOT_VERSION=$(grep -m1 SYMFONY_VERSION .travis.yml | grep -o '[0-9.x]*').x-dev" >> $GITHUB_ENV echo "COMPOSER_ROOT_VERSION=$(grep -m1 SYMFONY_VERSION .travis.yml | grep -o '[0-9.x]*').x-dev" >> $GITHUB_ENV
- name: Determine composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ github.base_ref }}
restore-keys: composer-
- name: Install Psalm - name: Install Psalm
run: | run: |
composer require psalm/phar
cp ./vendor/bin/psalm.phar base/psalm.phar
cp ./vendor/bin/psalm.phar pr/psalm.phar
- name: Install dependencies for base
run: |
cd base
echo "::group::modify composer.json" echo "::group::modify composer.json"
composer remove symfony/phpunit-bridge --no-interaction --no-update composer remove --no-update --no-interaction symfony/phpunit-bridge
composer require --no-update phpunit/phpunit php-http/discovery psr/event-dispatcher composer require --no-update psalm/phar phpunit/phpunit php-http/discovery psr/event-dispatcher
echo "::endgroup::" echo "::endgroup::"
echo "::group::composer update" echo "::group::composer update"
composer update --no-progress --ansi composer update --no-progress --ansi
git checkout composer.json
echo "::endgroup::" echo "::endgroup::"
./vendor/bin/psalm.phar --version
- name: Generate Psalm baseline - name: Generate Psalm baseline
run: | run: |
cd base git checkout -m ${{ github.base_ref }}
./psalm.phar --set-baseline=.github/psalm/psalm.baseline.xml --no-progress ./vendor/bin/psalm.phar --set-baseline=.github/psalm/psalm.baseline.xml --no-progress
git checkout -m FETCH_HEAD
- name: Copy baseline
run: |
cp base/.github/psalm/psalm.baseline.xml pr/.github/psalm/psalm.baseline.xml
- name: Install dependencies for PR
run: |
cd pr
echo "::group::modify composer.json"
composer remove symfony/phpunit-bridge --no-interaction --no-update
composer require --no-update phpunit/phpunit php-http/discovery psr/event-dispatcher
echo "::endgroup::"
echo "::group::composer update"
composer update --no-progress --ansi
echo "::endgroup::"
- name: Cache Psalm
uses: actions/cache@v2
with:
path: pr/.github/psalm/cache/
key: psalm-${{ github.base_ref }}
restore-keys: psalm-
- name: Psalm - name: Psalm
run: | run: |
cd pr ./vendor/bin/psalm.phar --output-format=github --no-progress
./psalm.phar --version
./psalm.phar --output-format=github --no-progress

View File

@ -4,8 +4,11 @@ on:
push: push:
pull_request: pull_request:
jobs: defaults:
run:
shell: bash
jobs:
integration: integration:
name: Integration name: Integration
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Cache\Adapter;
use Predis\Connection\Aggregate\ClusterInterface; use Predis\Connection\Aggregate\ClusterInterface;
use Predis\Connection\Aggregate\PredisCluster; use Predis\Connection\Aggregate\PredisCluster;
use Predis\Connection\Aggregate\ReplicationInterface;
use Predis\Response\Status; use Predis\Response\Status;
use Symfony\Component\Cache\Exception\InvalidArgumentException; use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\Exception\LogicException; use Symfony\Component\Cache\Exception\LogicException;
@ -282,7 +283,14 @@ EOLUA;
return $this->redisEvictionPolicy; return $this->redisEvictionPolicy;
} }
foreach ($this->getHosts() as $host) { $hosts = $this->getHosts();
$host = reset($hosts);
if ($host instanceof \Predis\Client && $host->getConnection() instanceof ReplicationInterface) {
// Predis supports info command only on the master in replication environments
$hosts = [$host->getClientFor('master')];
}
foreach ($hosts as $host) {
$info = $host->info('Memory'); $info = $host->info('Memory');
$info = $info['Memory'] ?? $info; $info = $info['Memory'] ?? $info;

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Cache\Traits;
use Predis\Command\Redis\UNLINK; use Predis\Command\Redis\UNLINK;
use Predis\Connection\Aggregate\ClusterInterface; use Predis\Connection\Aggregate\ClusterInterface;
use Predis\Connection\Aggregate\RedisCluster; use Predis\Connection\Aggregate\RedisCluster;
use Predis\Connection\Aggregate\ReplicationInterface;
use Predis\Response\Status; use Predis\Response\Status;
use Symfony\Component\Cache\Exception\CacheException; use Symfony\Component\Cache\Exception\CacheException;
use Symfony\Component\Cache\Exception\InvalidArgumentException; use Symfony\Component\Cache\Exception\InvalidArgumentException;
@ -368,7 +369,14 @@ trait RedisTrait
$evalArgs = [[$namespace], 0]; $evalArgs = [[$namespace], 0];
} }
foreach ($this->getHosts() as $host) { $hosts = $this->getHosts();
$host = reset($hosts);
if ($host instanceof \Predis\Client && $host->getConnection() instanceof ReplicationInterface) {
// Predis supports info command only on the master in replication environments
$hosts = [$host->getClientFor('master')];
}
foreach ($hosts as $host) {
if (!isset($namespace[0])) { if (!isset($namespace[0])) {
$cleared = $host->flushDb() && $cleared; $cleared = $host->flushDb() && $cleared;
continue; continue;