|
|
|
@ -42,6 +42,14 @@ class rcube_session_redis extends rcube_session {
|
|
|
|
|
$this->redis = rcube::get_instance()->get_redis();
|
|
|
|
|
$this->debug = $config->get('redis_debug');
|
|
|
|
|
|
|
|
|
|
if (!$this->redis) {
|
|
|
|
|
rcube::raise_error(array(
|
|
|
|
|
'code' => 604, 'type' => 'redis',
|
|
|
|
|
'line' => __LINE__, 'file' => __FILE__,
|
|
|
|
|
'message' => "Failed to connect to redis. Please check configuration"),
|
|
|
|
|
true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// register sessions handler
|
|
|
|
|
$this->register_session_handler();
|
|
|
|
|
}
|
|
|
|
@ -79,8 +87,13 @@ class rcube_session_redis extends rcube_session {
|
|
|
|
|
public function destroy($key)
|
|
|
|
|
{
|
|
|
|
|
if ($key) {
|
|
|
|
|
$fname = method_exists($this->redis, 'del') ? 'del' : 'delete';
|
|
|
|
|
$result = $this->redis->$fname($key);
|
|
|
|
|
try {
|
|
|
|
|
$fname = method_exists($this->redis, 'del') ? 'del' : 'delete';
|
|
|
|
|
$result = $this->redis->$fname($key);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
rcube::raise_error($e, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->debug) {
|
|
|
|
|
$this->debug('delete', $key, null, $result);
|
|
|
|
@ -99,7 +112,18 @@ class rcube_session_redis extends rcube_session {
|
|
|
|
|
*/
|
|
|
|
|
public function read($key)
|
|
|
|
|
{
|
|
|
|
|
if ($value = $this->redis->get($key)) {
|
|
|
|
|
try {
|
|
|
|
|
$value = $this->redis->get($key);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
rcube::raise_error($e, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->debug) {
|
|
|
|
|
$this->debug('get', $key, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($value) {
|
|
|
|
|
$arr = unserialize($value);
|
|
|
|
|
$this->changed = $arr['changed'];
|
|
|
|
|
$this->ip = $arr['ip'];
|
|
|
|
@ -107,10 +131,6 @@ class rcube_session_redis extends rcube_session {
|
|
|
|
|
$this->key = $key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->debug) {
|
|
|
|
|
$this->debug('get', $key, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->vars ?: '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -128,8 +148,14 @@ class rcube_session_redis extends rcube_session {
|
|
|
|
|
$ts = microtime(true);
|
|
|
|
|
|
|
|
|
|
if ($newvars !== $oldvars || $ts - $this->changed > $this->lifetime / 3) {
|
|
|
|
|
$data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars));
|
|
|
|
|
$result = $this->redis->setex($key, $this->lifetime + 60, $data);
|
|
|
|
|
$data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars));
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$result = $this->redis->setex($key, $this->lifetime + 60, $data);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
rcube::raise_error($e, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->debug) {
|
|
|
|
|
$this->debug('set', $key, $data, $result);
|
|
|
|
@ -155,8 +181,13 @@ class rcube_session_redis extends rcube_session {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $vars));
|
|
|
|
|
$result = $this->redis->setex($key, $this->lifetime + 60, $data);
|
|
|
|
|
try {
|
|
|
|
|
$data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $vars));
|
|
|
|
|
$result = $this->redis->setex($key, $this->lifetime + 60, $data);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
rcube::raise_error($e, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->debug) {
|
|
|
|
|
$this->debug('set', $key, $data, $result);
|
|
|
|
|