aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/cache/driver/redis.php
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2011-05-08 03:21:19 -0400
committerOleg Pudeyev <oleg@bsdpower.com>2011-05-08 03:21:19 -0400
commitab44fe5e394fe7b69c57266e2934200a3ee9bbc5 (patch)
treee6021c19fa15800787b1a7459fb8ad40cf2d8391 /phpBB/includes/cache/driver/redis.php
parent9c6660a2253149baff0094b943823de6758b35a6 (diff)
parentc0336988155736583c6fc4398980bd2a4e4036b6 (diff)
downloadforums-ab44fe5e394fe7b69c57266e2934200a3ee9bbc5.tar
forums-ab44fe5e394fe7b69c57266e2934200a3ee9bbc5.tar.gz
forums-ab44fe5e394fe7b69c57266e2934200a3ee9bbc5.tar.bz2
forums-ab44fe5e394fe7b69c57266e2934200a3ee9bbc5.tar.xz
forums-ab44fe5e394fe7b69c57266e2934200a3ee9bbc5.zip
Merge branch 'develop' into feature/prune-users
* develop: (170 commits) [ticket/10145] Always recompile all templates when DEBUG_EXTRA is defined. [feature/attachment-management-no-reassignment] Handle privacy and some more. [ticket/10148] Turn TEMPLATE_BITFIELD into an instance variable. [ticket/10147] Corrected a typo in includes/functions_template.php. [ticket/10141] Save a hash lookup when value is not in cache. [ticket/10143] Added tests for storing a previously deleted value in db cache. [ticket/10105] Update AIM express link. [ticket/10105] Update AIM application download link. [ticket/10137] Remove unintended space at end of PHP_URL_FOPEN_SUPPORT_EXPLAIN. [ticket/10141] Split double-assignment into conditional and unconditional part. [ticket/10141] Use a cache in $auth->_fill_acl() for better performance. [ticket/9961] Create log entries when users are activated. [ticket/10139] Make signatures of set_atomic() consistent by using $new_value. [ticket/10139] Rename $cache to $use_cache to avoid confusion with cache object [ticket/10006] Remove unneeded if statements [ticket/10006] Remove return values [ticket/10006] More testing [ticket/10006] Tweak the tests a bit [ticket/10006] Add phpbb_config::delete [ticket/7941] Added @return to generate_board_url docstring. ...
Diffstat (limited to 'phpBB/includes/cache/driver/redis.php')
-rwxr-xr-xphpBB/includes/cache/driver/redis.php150
1 files changed, 150 insertions, 0 deletions
diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php
new file mode 100755
index 0000000000..f0997c3cad
--- /dev/null
+++ b/phpBB/includes/cache/driver/redis.php
@@ -0,0 +1,150 @@
+<?php
+/**
+*
+* @package acm
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+if (!defined('PHPBB_ACM_REDIS_PORT'))
+{
+ define('PHPBB_ACM_REDIS_PORT', 6379);
+}
+
+if (!defined('PHPBB_ACM_REDIS_HOST'))
+{
+ define('PHPBB_ACM_REDIS_HOST', 'localhost');
+}
+
+if (!defined('PHPBB_ACM_REDIS'))
+{
+ //can define multiple servers with host1/port1,host2/port2 format
+ define('PHPBB_ACM_REDIS', PHPBB_ACM_REDIS_HOST . '/' . PHPBB_ACM_REDIS_PORT);
+}
+
+/**
+* ACM for Redis
+*
+* Compatible with the php extension phpredis available
+* at https://github.com/nicolasff/phpredis
+*
+* @package acm
+*/
+class phpbb_cache_driver_redis extends phpbb_cache_driver_memory
+{
+ var $extension = 'redis';
+
+ var $redis;
+
+ function __construct()
+ {
+ // Call the parent constructor
+ parent::__construct();
+
+ $this->redis = new Redis();
+ foreach (explode(',', PHPBB_ACM_REDIS) as $server)
+ {
+ $parts = explode('/', $server);
+ $this->redis->connect(trim($parts[0]), trim($parts[1]));
+ }
+
+ if (defined('PHPBB_ACM_REDIS_PASSWORD'))
+ {
+ if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD))
+ {
+ global $acm_type;
+
+ trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR);
+ }
+ }
+
+ $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
+ $this->redis->setOption(Redis::OPT_PREFIX, $this->key_prefix);
+
+ if (defined('PHPBB_ACM_REDIS_DB'))
+ {
+ if (!$this->redis->select(PHPBB_ACM_REDIS_DB))
+ {
+ global $acm_type;
+
+ trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR);
+ }
+ }
+ }
+
+ /**
+ * Unload the cache resources
+ *
+ * @return void
+ */
+ function unload()
+ {
+ parent::unload();
+
+ $this->redis->close();
+ }
+
+ /**
+ * Purge cache data
+ *
+ * @return void
+ */
+ function purge()
+ {
+ $this->redis->flushDB();
+
+ parent::purge();
+ }
+
+ /**
+ * Fetch an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return mixed Cached data
+ */
+ function _read($var)
+ {
+ return $this->redis->get($var);
+ }
+
+ /**
+ * Store data in the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @param mixed $data Data to store
+ * @param int $ttl Time-to-live of cached data
+ * @return bool True if the operation succeeded
+ */
+ function _write($var, $data, $ttl = 2592000)
+ {
+ return $this->redis->setex($var, $ttl, $data);
+ }
+
+ /**
+ * Remove an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return bool True if the operation succeeded
+ */
+ function _delete($var)
+ {
+ if ($this->redis->delete($var) > 0)
+ {
+ return true;
+ }
+ return false;
+ }
+}
+