Skip to content

Commit fbc389e

Browse files
committed
refactor: improve on Redis implementation
Signed-off-by: otengkwame <developerkwame@gmail.com>
1 parent 166363e commit fbc389e

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

CodeIgniter/Framework/libraries/Cache/drivers/Cache_redis.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class CI_Cache_redis extends CI_Driver
5959
'host' => '127.0.0.1',
6060
'password' => null,
6161
'port' => 6379,
62-
'timeout' => 0
62+
'timeout' => 0.0,
63+
'database' => 0
6364
];
6465

6566
/**

CodeIgniter/Framework/libraries/Session/drivers/Session_redis_driver.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,19 @@ public function __construct(&$params)
155155
$this->_config['save_path'] = $save_path;
156156

157157
if ($this->_config['match_ip'] === true) {
158-
$this->_key_prefix .= $_SERVER['REMOTE_ADDR'] . ':';
158+
if (isset($matches['options'])) {
159+
$save_path['password'] = preg_match('#auth=([^\s&]+)#', $matches['options'], $match) ? $match[1] : NULL;
160+
$save_path['database'] = preg_match('#database=(\d+)#', $matches['options'], $match) ? (int) $match[1] : NULL;
161+
$save_path['timeout'] = preg_match('#timeout=(\d+\.\d+)#', $matches['options'], $match) ? (float) $match[1] : 0.0;
162+
163+
preg_match('#prefix=([^\s&]+)#', $matches['options'], $match) && $this->_key_prefix = $match[1];
164+
}
165+
166+
$this->_config['save_path'] = $save_path;
167+
168+
if ($this->_config['match_ip'] === true) {
169+
$this->_key_prefix .= $_SERVER['REMOTE_ADDR'] . ':';
170+
}
159171
}
160172
}
161173
}

0 commit comments

Comments
 (0)