Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scheme config from env vars #209

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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