Skip to content

Commit

Permalink
Allow scheme config from env vars (#209)
Browse files Browse the repository at this point in the history
* Allow scheme config from env vars

* Fix condition

* Add new config to readme file

* Update includes/common.inc.php

---------

Co-authored-by: Erik Dubbelboer <[email protected]>
  • Loading branch information
arielectron and erikdubbelboer authored Aug 18, 2024
1 parent 3dcd016 commit 4f15444
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Environment variables summary
* ``REDIS_1_HOST`` - define host of the Redis server
* ``REDIS_1_NAME`` - define name of the Redis server
* ``REDIS_1_PORT`` - define port of the Redis server
* ``REDIS_1_SCHEME`` - define scheme of the Redis server (tcp or tls)
* ``REDIS_1_AUTH`` - define password of the Redis server
* ``REDIS_1_AUTH_FILE`` - define file containing the password of the Redis server
* ``REDIS_1_DATABASES`` - You can modify you config to prevent phpRedisAdmin from using CONFIG command
Expand Down
8 changes: 6 additions & 2 deletions includes/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,15 @@
$config['showEmptyNamespaceAsKey'] = false;
}

if (!isset($config['scheme']) || empty($config['scheme'])) {
$config['scheme'] = 'tcp';
}

// Setup a connection to Redis.
if(isset($server['scheme']) && $server['scheme'] === 'unix' && $server['path']) {
if ($server['scheme'] === 'unix' && $server['path']) {
$redis = new Predis\Client(array('scheme' => 'unix', 'path' => $server['path']));
} else {
$redis = !$server['port'] ? new Predis\Client($server['host']) : new Predis\Client('tcp://'.$server['host'].':'.$server['port']);
$redis = !$server['port'] ? new Predis\Client($server['host']) : new Predis\Client($server['scheme'].'://'.$server['host'].':'.$server['port']);
}

try {
Expand Down
8 changes: 7 additions & 1 deletion includes/config.environment.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$server_name = getenv($prefix . 'NAME');
$server_host = getenv($prefix . 'HOST');
$server_port = getenv($prefix . 'PORT');
$server_scheme = getenv($prefix . 'SCHEME');
if (getenv($prefix . 'AUTH_FILE') !== false) {
$server_auth = file_get_contents(getenv($prefix . 'AUTH_FILE'));
} else {
Expand All @@ -55,17 +56,22 @@
$server_auth = "";
}

if (empty($server_port)) {
if (empty($server_port) && strpos($server_host, ':') === false) {
$server_port = 6379;
}

if (empty($server_scheme)) {
$server_scheme = 'tcp';
}

$config['servers'][] = array(
'name' => $server_name,
'host' => $server_host,
'port' => $server_port,
'filter' => $config['filter'],
'scansize' => $config['scansize'],
'scanmax' => $config['scanmax'],
'scheme' => $server_scheme,
);

if (!empty($server_auth)) {
Expand Down

0 comments on commit 4f15444

Please sign in to comment.