diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a7ba8de3..ad1f06868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [](#improved) * Forced `natsort` on plugins to ensure consistent plugin load ordering across platforms [#1614](https://github.com/getgrav/grav/issues/1614) * Use new `multilevel` field to handle Asset Collections [#1201](https://github.com/getgrav/grav-plugin-admin/issues/1201) + * Added support for redis `password` option [#1620](https://github.com/getgrav/grav/issues/1620) # v1.3.2 ## 08/16/2017 diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index ee093cf4a..33c98547e 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -616,6 +616,12 @@ form: help: PLUGIN_ADMIN.REDIS_PORT_HELP placeholder: "6379" + cache.redis.password: + type: text + size: small + label: PLUGIN_ADMIN.REDIS_PASSWORD + + twig: type: section diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index 6746ab359..254f6fdd0 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -240,6 +240,7 @@ class Cache extends Getters case 'redis': $redis = new \Redis(); $socket = $this->config->get('system.cache.redis.socket', false); + $password = $this->config->get('system.cache.redis.password', false); if ($socket) { $redis->connect($socket); @@ -248,6 +249,11 @@ class Cache extends Getters $this->config->get('system.cache.redis.port', 6379)); } + // Authenticate with password if set + if ($password && !$redis->auth($password)) { + throw new \RedisException('Redis authentication failed'); + } + $driver = new DoctrineCache\RedisCache(); $driver->setRedis($redis); break;