Skip to content

Commit b0a8c1a

Browse files
qem19umbr
and
umbr
authored
Redis connection fix (#7)
Laravel doesnt have ability to use different redis-clients for different connections. It can be problem if you want to use sentinel-connection for app and phpredis for metrics. So, in the PR i changed redis config for Prometheus. Now, you can specify redis-client and all credentials right in event-tracker.php config --------- Co-authored-by: umbr <[email protected]>
1 parent dbcfe6d commit b0a8c1a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Diff for: config/event_tracker.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@
2828
],
2929
],
3030
'prometheus' => [
31-
'redis' => 'default',
31+
'redis' => [
32+
'client' => env('EVENT_TRACKER_REDIS_CLIENT', 'phpredis'),
33+
'credentials' => [
34+
'host' => env('EVENT_TRACKER_REDIS_HOST', 'localhost'),
35+
'username' => env('EVENT_TRACKER_REDIS_USERNAME', 'redis'),
36+
'password' => env('EVENT_TRACKER_REDIS_PASSWORD'),
37+
'port' => env('EVENT_TRACKER_REDIS_PORT', '6379'),
38+
'database' => env('EVENT_TRACKER_REDIS_DATABASE', 0),
39+
],
40+
],
3241
'labels' => [
3342
'namespace' => 'app_ns',
3443
],

Diff for: src/Repositories/PrometheusRepository/Installer.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ public function install(array $config): void
2222
}
2323

2424
$this->app->singleton(PrometheusRepositoryContract::class, function () use ($config) {
25-
/** @var RedisManager $redisManager */
26-
$redisManager = $this->app->make(RedisManager::class);
27-
$connection = $config['connections']['prometheus']['redis'];
28-
$redis = $redisManager->connection($connection)
25+
$redisConfig = $config['connections']['prometheus']['redis'];
26+
$redisManager = new RedisManager($this->app, $redisConfig['client'], $redisConfig);
27+
$redis = $redisManager->connection('credentials')
2928
->client();
3029
$redis->setOption(NativeRedis::OPT_PREFIX, '');
3130

0 commit comments

Comments
 (0)