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

redis config select database #1351

Open
wants to merge 1 commit into
base: 1.2
Choose a base branch
from
Open
Changes from all 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
12 changes: 11 additions & 1 deletion storage/cache/adapter/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
Expand All @@ -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']}:");
}
Expand Down