mirror of
https://github.com/cytopia/devilbox.git
synced 2025-01-29 15:44:04 +00:00
Replace Redis password option with Redis startup options to make it more dynamic
This commit is contained in:
parent
d4deff1340
commit
32592b03dc
@ -127,12 +127,26 @@ function loadClass($class) {
|
||||
break;
|
||||
|
||||
case 'Redis':
|
||||
|
||||
// Check if redis is using a password
|
||||
$REDIS_ROOT_PASSWORD = '';
|
||||
|
||||
$_REDIS_ARGS = loadClass('Helper')->getEnv('REDIS_ARGS');
|
||||
$_REDIS_PASS = preg_split("/--requirepass\s+/", $_REDIS_ARGS);
|
||||
if (is_array($_REDIS_PASS) && count($_REDIS_PASS)) {
|
||||
// In case the option is specified multiple times, use the last effective one.
|
||||
$_REDIS_PASS = $_REDIS_PASS[count($_REDIS_PASS)-1];
|
||||
if (strlen($_REDIS_PASS) > 0) {
|
||||
$REDIS_ROOT_PASSWORD = $_REDIS_PASS;
|
||||
}
|
||||
}
|
||||
|
||||
loadFile($class, $cnt_dir);
|
||||
if(loadClass('Helper')->getEnv('REDIS_ROOT_PASSWORD') == ''){
|
||||
if ($REDIS_ROOT_PASSWORD == '') {
|
||||
$_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME']);
|
||||
}else{
|
||||
} else {
|
||||
$_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME'], array(
|
||||
'pass' => loadClass('Helper')->getEnv('REDIS_ROOT_PASSWORD'),
|
||||
'pass' => $REDIS_ROOT_PASSWORD,
|
||||
));
|
||||
}
|
||||
break;
|
||||
@ -149,7 +163,7 @@ function loadClass($class) {
|
||||
|
||||
// Get optional docker classes
|
||||
default:
|
||||
// Redis
|
||||
// Unknown class
|
||||
exit('Class does not exist: '.$class);
|
||||
}
|
||||
return $_LOADED_LIBS[$class];
|
||||
|
@ -44,7 +44,7 @@ class Redis extends BaseClass implements BaseInterface
|
||||
$this->setConnectErrno(1);
|
||||
//loadClass('Logger')->error($this->_connect_error);
|
||||
} else {
|
||||
if(array_key_exists('pass', $data)){
|
||||
if (array_key_exists('pass', $data)) {
|
||||
$redis->auth($data['pass']);
|
||||
}
|
||||
$redis->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')');
|
||||
|
@ -402,12 +402,11 @@ services:
|
||||
# ------------------------------------------------------------
|
||||
redis:
|
||||
image: redis:${REDIS_SERVER:-3.2}
|
||||
|
||||
# REDIS CUSTOM PASSWORD SETUP
|
||||
#comment out the following 3 lines if you want to set a custom redis password, also set the redis pass variable in .env
|
||||
#command: redis-server --requirepass ${REDIS_ROOT_PASSWORD}
|
||||
#environment:
|
||||
# - ALLOW_EMPTY_PASSWORD=yes
|
||||
|
||||
# Apply custom arguments to redis startup
|
||||
command: redis-server ${REDIS_ARGS:- }
|
||||
environment:
|
||||
- REDIS_ARGS=${REDIS_ARGS:- }
|
||||
|
||||
ports:
|
||||
# [local-machine:]local-port:docker-port
|
||||
|
16
env-example
16
env-example
@ -576,10 +576,22 @@ HOST_PORT_PGSQL=5432
|
||||
###
|
||||
HOST_PORT_REDIS=6379
|
||||
|
||||
|
||||
###
|
||||
### Comment out to set the redis custom password also, in docker-compose.yml comment out the REDIS CUSTOM PASSWORD SETUP section
|
||||
### Custom startup arguments
|
||||
###
|
||||
#REDIS_ROOT_PASSWORD=root
|
||||
### Apply custom startup arguments to redis
|
||||
###
|
||||
### Example: Password protection
|
||||
### Add password protection to the Redis server by specifying it should
|
||||
### require a password.
|
||||
### Note: Do not add quotes or spaces to the password
|
||||
###
|
||||
### REDIS_ARGS=--requirepass my-redis-root-password
|
||||
###
|
||||
###
|
||||
REDIS_ARGS=
|
||||
#REDIS_ARGS=--requirepass my-redis-root-password
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user