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