Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F233972
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/program/lib/Roundcube/cache/redis.php b/program/lib/Roundcube/cache/redis.php
index af625f2a4..a359ec21d 100644
--- a/program/lib/Roundcube/cache/redis.php
+++ b/program/lib/Roundcube/cache/redis.php
@@ -1,261 +1,258 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| Copyright (C) Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Caching engine - Redis |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
/**
* Interface class for accessing Redis cache
*
* @package Framework
* @subpackage Cache
* @author Thomas Bruederli <roundcube@gmail.com>
* @author Aleksander Machniak <alec@alec.pl>
*/
class rcube_cache_redis extends rcube_cache
{
/**
* Instance of Redis object
*
* @var Redis
*/
protected static $redis;
/**
* Object constructor.
*
* @param int $userid User identifier
* @param string $prefix Key name prefix
* @param string $ttl Expiration time of memcache/apc items
* @param bool $packed Enables/disabled data serialization.
* It's possible to disable data serialization if you're sure
* stored data will be always a safe string
*/
public function __construct($userid, $prefix = '', $ttl = 0, $packed = true)
{
parent::__construct($userid, $prefix, $ttl, $packed);
$rcube = rcube::get_instance();
$this->type = 'redis';
$this->debug = $rcube->config->get('redis_debug');
self::engine();
}
/**
* Get global handle for redis access
*
* @return object Redis
*/
public static function engine()
{
if (self::$redis !== null) {
return self::$redis;
}
if (!class_exists('Redis')) {
self::$redis = false;
rcube::raise_error(array(
'code' => 604,
'type' => 'redis',
'line' => __LINE__,
'file' => __FILE__,
'message' => "Failed to find Redis. Make sure php-redis is included"
),
true, true);
}
$rcube = rcube::get_instance();
$hosts = $rcube->config->get('redis_hosts');
// host config is wrong
if (!is_array($hosts) || empty($hosts)) {
rcube::raise_error(array(
'code' => 604,
'type' => 'redis',
'line' => __LINE__,
'file' => __FILE__,
'message' => "Redis host not configured"
),
true, true);
}
// only allow 1 host for now until we support clustering
if (count($hosts) > 1) {
rcube::raise_error(array(
'code' => 604,
'type' => 'redis',
'line' => __LINE__,
'file' => __FILE__,
'message' => "Redis cluster not yet supported"
),
true, true);
}
self::$redis = new Redis;
foreach ($hosts as $redis_host) {
// explode individual fields
list($host, $port, $database, $password) = array_pad(explode(':', $redis_host, 4), 4, null);
if (substr($redis_host, 0, 7) === 'unix://') {
$host = substr($port, 2);
$port = null;
}
else {
// set default values if not set
$host = $host ?: '127.0.0.1';
$port = $port ?: 6379;
}
try {
if (self::$redis->connect($host, $port) === false) {
rcube::raise_error(array(
'code' => 604,
'type' => 'redis',
'line' => __LINE__,
'file' => __FILE__,
'message' => "Could not connect to Redis server. Please check host and port"
),
true, true);
}
if ($password !== null && self::$redis->auth($password) === false) {
rcube::raise_error(array(
'code' => 604,
'type' => 'redis',
'line' => __LINE__,
'file' => __FILE__,
'message' => "Could not authenticate with Redis server. Please check password."
),
true, true);
}
if ($database !== null && self::$redis->select($database) === false) {
rcube::raise_error(array(
'code' => 604,
'type' => 'redis',
'line' => __LINE__,
'file' => __FILE__,
'message' => "Could not select Redis database. Please check database setting."
),
true, true);
}
}
catch (Exception $e) {
rcube::raise_error($e, true, true);
}
}
if (self::$redis->ping() !== "+PONG") {
self::$redis = false;
}
return self::$redis;
}
/**
* Remove cache records older than ttl
*/
public function expunge()
{
// No need for GC, entries are expunged automatically
}
/**
* Remove expired records
*/
public static function gc()
{
// No need for GC, entries are expunged automatically
}
/**
* Reads cache entry.
*
* @param string $key Cache internal key name
*
* @return mixed Cached value
*/
protected function get_item($key)
{
if (!self::$redis) {
return false;
}
$data = self::$redis->get($key);
if ($this->debug) {
$this->debug('get', $key, $data);
}
return $data;
}
/**
* Adds entry into Redis.
*
* @param string $key Cache internal key name
* @param mixed $data Serialized cache data
*
* @param boolean True on success, False on failure
*/
protected function add_item($key, $data)
{
if (!self::$redis) {
return false;
}
$result = self::$redis->setEx($key, $this->ttl, $data);
if ($this->debug) {
$this->debug('set', $key, $data, $result);
}
return $result;
}
/**
* Deletes entry from Redis.
*
* @param string $key Cache internal key name
*
* @param boolean True on success, False on failure
*/
protected function delete_item($key)
{
if (!self::$redis) {
return false;
}
- if (method_exists(self::$redis, 'del')) {
- $result = self::$redis->del($key);
- } else {
- $result = self::$redis->delete($key);
- }
+ $fname = method_exists(self::$redis, 'del') ? 'del' : 'delete';
+ $result = self::$redis->$fname($key);
if ($this->debug) {
$this->debug('delete', $key, null, $result);
}
return $result;
}
}
diff --git a/program/lib/Roundcube/session/redis.php b/program/lib/Roundcube/session/redis.php
index 227b6ed98..7671519d8 100644
--- a/program/lib/Roundcube/session/redis.php
+++ b/program/lib/Roundcube/session/redis.php
@@ -1,185 +1,186 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Provide redis supported session management |
+-----------------------------------------------------------------------+
| Author: Cor Bosman <cor@roundcu.be> |
+-----------------------------------------------------------------------+
*/
/**
* Class to provide redis session storage
*
* @package Framework
* @subpackage Core
* @author Cor Bosman <cor@roundcu.be>
* @author Aleksander Machniak <alec@alec.pl>
*/
class rcube_session_redis extends rcube_session {
private $redis;
private $debug;
/**
* Object constructor
*
* @param rcube_config $config Configuration
*/
public function __construct($config)
{
parent::__construct($config);
$this->redis = rcube::get_instance()->get_redis();
$this->debug = $config->get('redis_debug');
// register sessions handler
$this->register_session_handler();
}
/**
* Opens the session
*
* @param string $save_path Session save path
* @param string $session_name Session name
*
* @return bool True on success, False on failure
*/
public function open($save_path, $session_name)
{
return true;
}
/**
* Close the session
*
* @return bool True on success, False on failure
*/
public function close()
{
return true;
}
/**
* Destroy the session
*
* @param string $key Session identifier
*
* @return bool True on success, False on failure
*/
public function destroy($key)
{
if ($key) {
- $result = $this->redis->del($key);
+ $fname = method_exists($this->redis, 'del') ? 'del' : 'delete';
+ $result = $this->redis->$fname($key);
if ($this->debug) {
$this->debug('delete', $key, null, $result);
}
}
return true;
}
/**
* Read data from redis store
*
* @param string $key Session identifier
*
* @return string Serialized data string
*/
public function read($key)
{
if ($value = $this->redis->get($key)) {
$arr = unserialize($value);
$this->changed = $arr['changed'];
$this->ip = $arr['ip'];
$this->vars = $arr['vars'];
$this->key = $key;
}
if ($this->debug) {
$this->debug('get', $key, $value);
}
return $this->vars ?: '';
}
/**
* Write data to redis store
*
* @param string $key Session identifier
* @param string $newvars New session data string
* @param string $oldvars Old session data string
*
* @return bool True on success, False on failure
*/
public function update($key, $newvars, $oldvars)
{
$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);
if ($this->debug) {
$this->debug('set', $key, $data, $result);
}
return $result;
}
return true;
}
/**
* Write data to redis store
*
* @param string $key Session identifier
* @param array $vars Session data
*
* @return bool True on success, False on failure
*/
public function write($key, $vars)
{
if ($this->ignore_write) {
return true;
}
$data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $vars));
$result = $this->redis->setex($key, $this->lifetime + 60, $data);
if ($this->debug) {
$this->debug('set', $key, $data, $result);
}
return $result;
}
/**
* Write memcache debug info to the log
*
* @param string $type Operation type
* @param string $key Session identifier
* @param string $data Data to log
* @param bool $result Opearation result
*/
protected function debug($type, $key, $data = null, $result = null)
{
$line = strtoupper($type) . ' ' . $key;
if ($data !== null) {
$line .= ' ' . $data;
}
rcube::debug('redis', $line, $result);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 5, 2:16 AM (8 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
175741
Default Alt Text
(13 KB)
Attached To
Mode
R3 roundcubemail
Attached
Detach File
Event Timeline
Log In to Comment