Skip to content

Commit

Permalink
[redis] - add db selection for redis session storage (#18266)
Browse files Browse the repository at this point in the history
* [redis] - added db selection for redis session storage

* redis storage db

* xml fix type number

redis db are integer numbers
  • Loading branch information
alikon authored and Michael Babker committed Oct 19, 2017
1 parent 08f4f83 commit b3de862
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 11 additions & 1 deletion administrator/components/com_config/model/form/application.xml
Expand Up @@ -181,7 +181,7 @@

<field
name="redis_server_db"
type="text"
type="number"
label="COM_CONFIG_FIELD_REDIS_DB_LABEL"
description="COM_CONFIG_FIELD_REDIS_DB_DESC"
default="0"
Expand Down Expand Up @@ -947,6 +947,16 @@
size="5"
/>

<field
name="session_redis_server_db"
type="number"
label="COM_CONFIG_FIELD_REDIS_DB_LABEL"
description="COM_CONFIG_FIELD_REDIS_DB_DESC"
default="0"
filter="integer"
showon="session_handler:redis"
size="4"
/>
<field
name="lifetime"
type="number"
Expand Down
10 changes: 9 additions & 1 deletion libraries/joomla/session/storage/redis.php
Expand Up @@ -36,6 +36,7 @@ public function __construct($options = array())
$this->_server = array(
'host' => $config->get('session_redis_server_host', 'localhost'),
'port' => $config->get('session_redis_server_port', 6379),
'db' => (int) $config->get('session_redis_server_db', 0)
);

parent::__construct($options);
Expand All @@ -54,7 +55,14 @@ public function register()
{
if (!headers_sent())
{
ini_set('session.save_path', "{$this->_server['host']}:{$this->_server['port']}");
$path = $this->_server['host'] . ":" . $this->_server['port'];

if (isset($this->_server['db']) && ($this->_server['db'] !== 0))
{
$path = 'tcp://' . $path . '?database=' . $this->_server['db'];
}

ini_set('session.save_path', $path);
ini_set('session.save_handler', 'redis');
}

Expand Down

0 comments on commit b3de862

Please sign in to comment.