Skip to content

Commit

Permalink
allow to provide redis_host / port
Browse files Browse the repository at this point in the history
  • Loading branch information
clementtalleu committed Sep 13, 2024
1 parent 6056270 commit a3b79e6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ Or add the library to your `composer.json` file:

Then run `composer update` to install the library.


### Redis configuration

if you want to inject a particular configuration for Redis, you can add the following environment variables to your .env file (all optional)

REDIS_HOST: localhost
REDIS_PORT: 6379
REDIS_USER:
REDIS_PASSWORD:
8 changes: 8 additions & 0 deletions src/Client/PredisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function __construct(protected ?Predis $redis = null)
$redisConfig['port'] = $_SERVER['REDIS_PORT'];
}

if (array_key_exists('REDIS_USER', $_SERVER)) {
$redisConfig['parameters']['username'] = $_SERVER['REDIS_USER'];
}

if (array_key_exists('REDIS_PASSWORD', $_SERVER)) {
$redisConfig['parameters']['password'] = $_SERVER['REDIS_PASSWORD'];
}

$this->redis = $redis ?? new Predis($redisConfig !== [] ? $redisConfig : null);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Client/RedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public function __construct(protected ?\Redis $redis = null)
}

if (array_key_exists('REDIS_PORT', $_SERVER)) {
$redisConfig['port'] = $_SERVER['REDIS_PORT'];
$redisConfig['port'] = (int) $_SERVER['REDIS_PORT'];
}

if (array_key_exists('REDIS_USER', $_SERVER) && array_key_exists('REDIS_PASSWORD', $_SERVER)) {
$redisConfig['auth'] =[$_SERVER['REDIS_USER'], $_SERVER['REDIS_PASSWORD']];
}

$this->redis = $redis ?? new \Redis($redisConfig !== [] ? $redisConfig : null);
Expand Down

0 comments on commit a3b79e6

Please sign in to comment.