Last active
September 7, 2023 13:42
-
-
Save dmason30/6fa4a08ac2bd84b180504d6759a90e62 to your computer and use it in GitHub Desktop.
Laravel Redis retry connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Facade; | |
return [ | |
'providers' => [ | |
/* | |
* Laravel Framework Service Providers... | |
*/ | |
// \Illuminate\Redis\RedisServiceProvider::class, | |
\App\Providers\RedisServiceProvider::class, | |
/* | |
* Application Service Providers... | |
*/ | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Extensions\Illuminate\Redis; | |
use Illuminate\Redis\RedisManager as LaravelRedisManager; | |
class RedisManager extends LaravelRedisManager | |
{ | |
public function resolve($name = null) | |
{ | |
return retry(3, fn () => parent::resolve($name), 400); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use App\Extensions\Illuminate\Redis\RedisManager; | |
use Illuminate\Redis\RedisServiceProvider as LaravelRedisServiceProviderAlias; | |
use Illuminate\Support\Arr; | |
class RedisServiceProvider extends LaravelRedisServiceProviderAlias | |
{ | |
public function register(): void | |
{ | |
parent::register(); | |
$this->app->singleton('redis', function ($app) { | |
$config = $app->make('config')->get('database.redis', []); | |
return new RedisManager($app, Arr::pull($config, 'client', 'phpredis'), $config); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment