From 2157a4bc20616a816aa3ed3e4ee2ce726623cba3 Mon Sep 17 00:00:00 2001 From: Ehsan Sabet Date: Thu, 11 Nov 2021 13:06:17 +0330 Subject: [PATCH] redis config select database --- storage/cache/adapter/Redis.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/storage/cache/adapter/Redis.php b/storage/cache/adapter/Redis.php index c50d1e6b9f..6e3fb67f7b 100644 --- a/storage/cache/adapter/Redis.php +++ b/storage/cache/adapter/Redis.php @@ -62,6 +62,11 @@ class Redis extends \lithium\storage\cache\Adapter { */ const DEFAULT_PORT = 6379; + /** + * The default database used to current connection. + */ + const DEFAULT_DATABASE = 0; + /** * Redis object instance used by this adapter. * @@ -97,7 +102,8 @@ public function __construct(array $config = []) { 'scope' => null, 'expiry' => '+1 hour', 'host' => static::DEFAULT_HOST . ':' . static::DEFAULT_PORT, - 'persistent' => false + 'persistent' => false, + 'database' => static::DEFAULT_DATABASE ]; parent::__construct($config + $defaults); } @@ -124,6 +130,10 @@ protected function _init() { $this->connection->{$method}($host['host'], $host['port']); } + if ($this->_config['database']) { + $this->connection->select($this->_config['database']); + } + if ($this->_config['scope']) { $this->connection->setOption(RedisCore::OPT_PREFIX, "{$this->_config['scope']}:"); }