Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Redis Cluster support #335

Draft
wants to merge 9 commits into
base: 1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/workflows/coding-standards.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/compile-assets.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/facade.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/issues.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/pull-requests.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/static-analysis.yml

This file was deleted.

184 changes: 53 additions & 131 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,10 @@ on:
- cron: '0 0 * * *'

jobs:
mysql:
sqlite:
runs-on: ubuntu-22.04

services:
mysql:
image: mysql:5.7
env:
MYSQL_RANDOM_ROOT_PASSWORD: yes
MYSQL_DATABASE: pulse
MYSQL_USER: pulse
MYSQL_PASSWORD: password
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
ports:
Expand All @@ -33,11 +23,11 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2, 8.3]
laravel: [10, 11]
stability: [prefer-lowest, prefer-stable]
php: [8.3]
laravel: [11]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - MySQL 5.7
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - SQLite

steps:
- name: Checkout code
Expand All @@ -60,137 +50,64 @@ jobs:
composer update --prefer-dist --no-interaction --no-progress --${{ matrix.stability }}

- name: Execute tests
run: vendor/bin/pest
run: vendor/bin/pest -vvv
env:
DB_CONNECTION: mysql
DB_DATABASE: pulse
DB_USERNAME: pulse
DB_PASSWORD: password
DB_COLLATION: utf8mb4_unicode_ci
DB_CONNECTION: sqlite

mariadb:
redis-cluster:
runs-on: ubuntu-22.04

services:
mysql:
image: mariadb:10
redis-node-0:
image: bitnami/redis-cluster
env:
MYSQL_RANDOM_ROOT_PASSWORD: yes
MYSQL_DATABASE: pulse
MYSQL_USER: pulse
MYSQL_PASSWORD: password
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
ports:
- 6379:6379
options: --entrypoint redis-server

strategy:
fail-fast: true
matrix:
php: [8.3]
laravel: [11]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - MariaDB 10

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, redis, pcntl, zip
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5

- name: Install redis-cli
run: sudo apt-get install -qq redis-tools
redis-node-1:
image: bitnami/redis-cluster
env:
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5

- name: Install dependencies
run: |
composer update --prefer-dist --no-interaction --no-progress --${{ matrix.stability }}
redis-node-2:
image: bitnami/redis-cluster
env:
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5

- name: Execute tests
run: vendor/bin/pest
redis-node-3:
image: bitnami/redis-cluster
env:
DB_CONNECTION: mariadb
DB_DATABASE: pulse
DB_USERNAME: pulse
DB_PASSWORD: password
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5

pgsql:
runs-on: ubuntu-22.04
redis-node-4:
image: bitnami/redis-cluster
env:
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5

services:
postgresql:
image: postgres:14
redis-node-5:
image: bitnami/redis-cluster
env:
POSTGRES_DB: pulse
POSTGRES_USER: pulse
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
ALLOW_EMPTY_PASSWORD: yes
REDIS_NODES: redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5
REDIS_CLUSTER_REPLICAS: 1
REDIS_CLUSTER_CREATOR: yes
ports:
- 6379:6379
options: --entrypoint redis-server

strategy:
fail-fast: true
matrix:
php: [8.3]
laravel: [11]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - PostgreSQL 14

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, redis, pcntl, zip
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none

- name: Install redis-cli
run: sudo apt-get install -qq redis-tools

- name: Install dependencies
run: |
composer require "illuminate/contracts=^${{ matrix.laravel }}" --dev --no-update
composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/pest
mysql:
image: mysql:5.7
env:
DB_CONNECTION: pgsql
DB_DATABASE: pulse
DB_USERNAME: pulse
DB_PASSWORD: password

sqlite:
runs-on: ubuntu-22.04

services:
redis:
image: redis
MYSQL_RANDOM_ROOT_PASSWORD: yes
MYSQL_DATABASE: pulse
MYSQL_USER: pulse
MYSQL_PASSWORD: password
ports:
- 6379:6379
options: --entrypoint redis-server
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: true
Expand All @@ -199,7 +116,7 @@ jobs:
laravel: [11]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - SQLite
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }} - Redis Cluster (with MySQL 5.7)

steps:
- name: Checkout code
Expand All @@ -222,6 +139,11 @@ jobs:
composer update --prefer-dist --no-interaction --no-progress --${{ matrix.stability }}

- name: Execute tests
run: vendor/bin/pest
run: vendor/bin/pest -vvv
env:
DB_CONNECTION: sqlite
DB_CONNECTION: mysql
DB_DATABASE: pulse
DB_USERNAME: pulse
DB_PASSWORD: password
DB_COLLATION: utf8mb4_unicode_ci
PULSE_REDIS_CONNECTION: cluster-test
9 changes: 0 additions & 9 deletions .github/workflows/update-changelog.yml

This file was deleted.

6 changes: 4 additions & 2 deletions src/Support/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Predis\Pipeline\Pipeline;
use Predis\Response\ServerException as PredisServerException;
use Redis as PhpRedis;
use RedisCluster as PhpRedisCluster;

/**
* @internal
Expand Down Expand Up @@ -113,7 +114,7 @@ protected function handle(array $args): mixed
{
try {
return tap($this->run($args), function ($result) use ($args) {
if ($result === false && $this->client() instanceof PhpRedis) {
if ($result === false && ($this->client() instanceof PhpRedis || $this->client() instanceof PhpRedisCluster)) {
throw RedisServerException::whileRunningCommand(implode(' ', $args), $this->client()->getLastError() ?? 'An unknown error occurred.');
}
});
Expand All @@ -131,6 +132,7 @@ protected function run(array $args): mixed
{
return match (true) {
$this->client() instanceof PhpRedis => $this->client()->rawCommand(...$args),
$this->client() instanceof PhpRedisCluster => $this->client()->rawCommand(['172.18.0.2', 6379], ...$args),
$this->client() instanceof Predis,
$this->client() instanceof Pipeline => $this->client()->executeCommand(RawCommand::create(...$args)),
};
Expand All @@ -139,7 +141,7 @@ protected function run(array $args): mixed
/**
* Retrieve the Redis client.
*/
protected function client(): PhpRedis|Predis|Pipeline
protected function client(): PhpRedis|Predis|Pipeline|PhpRedisCluster
{
return $this->client ?? $this->connection->client();
}
Expand Down
Loading
Loading