From 51cc9cd13e309b5e21e53675d4def2057f33a4bf Mon Sep 17 00:00:00 2001 From: travis00001 <78240096+travis00001@users.noreply.github.com> Date: Sat, 6 Feb 2021 15:35:50 -0500 Subject: [PATCH] Support selecting Redis database ID (#3208) --- system/src/Grav/Common/Cache.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index dea370ff6..24f1d4010 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -296,6 +296,7 @@ class Cache extends Getters $redis = new \Redis(); $socket = $this->config->get('system.cache.redis.socket', false); $password = $this->config->get('system.cache.redis.password', false); + $databaseId = $this->config->get('system.cache.redis.database', 0); if ($socket) { $redis->connect($socket); @@ -310,6 +311,11 @@ class Cache extends Getters if ($password && !$redis->auth($password)) { throw new \RedisException('Redis authentication failed'); } + + // Select alternate ( !=0 ) database ID if set + if ($databaseId && !$redis->select($databaseId)) { + throw new \RedisException('Could not select alternate Redis database ID'); + } $driver = new DoctrineCache\RedisCache(); $driver->setRedis($redis);