Skip to content

Commit 978d82b

Browse files
authored
Implementing failover retries (#50)
* setup retry logic * move retry logic, only retry exceptions that are connection related * restructure and rename logic * refactor, improve tests and add monitor/restart to the testing cluster * use laravel/pint for codestyle fixer * add debug command to the testing cluster * ignore name resolution errors on disconnecting * allow the initial connection to be retried aswell * move retry logic to the RetryService * try to trigger github actions * fix styling and enable debug command on redis * drop php8.2 in tests * fix workflow tests, rename RetryService to Manager, improve testability * wrap retries for testability, add initial connection test * format RetryManager * add RetryContext for config sharing, test on server/run_id instead of port
1 parent 73d4c0b commit 978d82b

15 files changed

+628
-402
lines changed

.github/workflows/tests.yml

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,40 @@ on:
99

1010
jobs:
1111
test-all:
12-
name: Test PHP ${{ matrix.php-version }}
12+
name: Test PHP ${{ matrix.php-version }}, Redis ${{ matrix.redis-version }}
1313

1414
runs-on: ${{ matrix.operating-system }}
1515

1616
strategy:
1717
matrix:
1818
operating-system: [ubuntu-latest]
19-
php-version: ['8.1', '8.2', '8.3', '8.4']
19+
php-version: ['8.2', '8.3', '8.4']
20+
redis-version: ['7.4.5', '8.0.3']
2021
include:
2122
- operating-system: 'ubuntu-latest'
2223
php-version: '8.4'
24+
redis-version: '8.0.3'
2325
run-sonarqube-analysis: true
2426

25-
services:
26-
redis:
27-
image: bitnami/redis:7.4-debian-12
28-
ports:
29-
- 6379:6379
30-
env:
31-
ALLOW_EMPTY_PASSWORD: 'yes'
32-
options: >-
33-
--health-cmd "redis-cli -p 6379 ping"
34-
--health-start-period 5s
35-
--health-interval 10s
36-
--health-timeout 5s
37-
--health-retries 5
38-
redis-sentinel:
39-
image: bitnami/redis-sentinel:7.4-debian-12
40-
ports:
41-
- 26379:26379
42-
env:
43-
REDIS_MASTER_HOST: redis
44-
REDIS_MASTER_SET: mymaster
45-
REDIS_SENTINEL_QUORUM: 1
46-
options: >-
47-
--health-cmd "redis-cli -p 26379 ping"
48-
--health-start-period 5s
49-
--health-interval 10s
50-
--health-timeout 5s
51-
--health-retries 5
52-
5327
steps:
5428
- uses: actions/checkout@v4
5529
with:
5630
fetch-depth: 0
5731

32+
- name: Install Redis
33+
run: |
34+
wget http://download.redis.io/releases/redis-${{ matrix.redis-version }}.tar.gz
35+
tar xzf redis-${{ matrix.redis-version }}.tar.gz
36+
cd redis-${{ matrix.redis-version }}
37+
make
38+
sudo make install
39+
40+
- name: Make Redis cluster script executable
41+
run: chmod +x ./start-redis-cluster.sh
42+
43+
- name: Start Redis cluster
44+
run: ./start-redis-cluster.sh &
45+
5846
- name: Setup PHPUnit
5947
uses: shivammathur/setup-php@v2
6048
with:
@@ -87,7 +75,7 @@ jobs:
8775
env:
8876
REDIS_SENTINEL_HOST: 127.0.0.1
8977
REDIS_SENTINEL_PORT: 26379
90-
REDIS_SENTINEL_SERVICE: mymaster
78+
REDIS_SENTINEL_SERVICE: service1
9179

9280
- name: Prepare paths for SonarQube analysis
9381
if: ${{ matrix.run-sonarqube-analysis && !github.event.pull_request.head.repo.fork }}

.php-cs-fixer.php

Lines changed: 0 additions & 177 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ To use the Redis Sentinel driver, the `redis` section in `config/database.php` n
5555
'sentinel_read_timeout' => (float) env('REDIS_SENTINEL_READ_TIMEOUT', 0),
5656
'sentinel_username' => env('REDIS_SENTINEL_USERNAME'),
5757
'sentinel_password' => env('REDIS_SENTINEL_PASSWORD'),
58+
59+
'connector_retry_attempts' => env('REDIS_CONNECTOR_RETRY_ATTEMPTS'),
60+
'connector_retry_delay' => env('REDIS_CONNECTOR_RETRY_DELAY'),
61+
5862
'password' => env('REDIS_PASSWORD'),
5963
'database' => (int) env('REDIS_DB', 0),
6064
]

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.1",
18+
"php": "^8.2",
1919
"ext-redis": "*",
2020
"illuminate/contracts": "^8.0|^9.0|^10.0|^11.0|^12.0",
2121
"illuminate/redis": "^8.0|^9.0|^10.0|^11.0|^12.0",
2222
"illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0"
2323
},
2424
"require-dev": {
25-
"friendsofphp/php-cs-fixer": "^3.0",
25+
"laravel/pint": "^1.22",
2626
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0"
2727
},
2828
"scripts": {
2929
"test": [
3030
"@test:cs",
3131
"@test:unit"
3232
],
33-
"test:cs": "PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix --dry-run --diff --ansi",
33+
"test:cs": "vendor/bin/pint -v",
3434
"test:unit": "vendor/bin/phpunit --testdox --log-junit=phpunit.report-junit.xml --coverage-clover=phpunit.coverage-clover.xml --coverage-text",
35-
"fix:cs": "PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix --diff --ansi"
35+
"fix:cs": "vendor/bin/pint -v"
3636
},
3737
"autoload": {
3838
"psr-4": {

pint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "laravel"
3+
}

0 commit comments

Comments
 (0)