aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/cache/driver/redis.php
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-09-05 13:56:57 -0500
committerNathan Guse <nathaniel.guse@gmail.com>2013-09-05 13:56:57 -0500
commite8ab8fe0bc7d087fe3c9b5d2a3e545f228bb3096 (patch)
tree6a053afa0a156204112b480707608cac60770ac5 /phpBB/phpbb/cache/driver/redis.php
parentabaa53b0b295358efcf591587485c01a027cd5cb (diff)
parentdd86e8d0ae0179cf50076cdb1a8020266b6432a5 (diff)
downloadforums-e8ab8fe0bc7d087fe3c9b5d2a3e545f228bb3096.tar
forums-e8ab8fe0bc7d087fe3c9b5d2a3e545f228bb3096.tar.gz
forums-e8ab8fe0bc7d087fe3c9b5d2a3e545f228bb3096.tar.bz2
forums-e8ab8fe0bc7d087fe3c9b5d2a3e545f228bb3096.tar.xz
forums-e8ab8fe0bc7d087fe3c9b5d2a3e545f228bb3096.zip
Merge branch 'develop' of github.com:phpbb/phpbb3 into ticket/8323
# By Joas Schilling (613) and others # Via Andreas Fischer (214) and others * 'develop' of github.com:phpbb/phpbb3: (2494 commits) [ticket/11825] Move schema_data.php into includes/ instead of phpbb/ [ticket/11215] Remove unnecessary comment [ticket/11755] MySQL upgrader out of date [prep-release-3.0.12] Update Changelog for 3.0.12-RC3 release. [prep-release-3.0.12] Bumping version number for 3.0.12-RC3. [ticket/11823] Set up nginx server to match PHP files with characters after .php [ticket/11812] Fix empty define [ticket/11818] Update Symfony dependencies to 2.3.* [ticket/11791] Load adm/ events from styles/adm/event/ [ticket/11215] Fix helper_url_test.php tests [ticket/11215] Add newline back to .htaccess, fix wording [ticket/11215] Update comment in .htaccess [ticket/11215] Uncomment rewrite rules in .htaccess [ticket/11215] Make controller helper url() method use correct format [ticket/11215] Add commented-out URL rewrite capability to .htaccess [ticket/11821] Fix comma usage next to "You are receiving this notification". [ticket/11769] Allow using 0 as poster name [ticket/11769] Allow '0' as username [ticket/11215] Use new URL structure for controllers [ticket/11215] Everything appears to be working... ... Conflicts: phpBB/includes/functions_privmsgs.php
Diffstat (limited to 'phpBB/phpbb/cache/driver/redis.php')
-rw-r--r--phpBB/phpbb/cache/driver/redis.php166
1 files changed, 166 insertions, 0 deletions
diff --git a/phpBB/phpbb/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php
new file mode 100644
index 0000000000..960735b673
--- /dev/null
+++ b/phpBB/phpbb/cache/driver/redis.php
@@ -0,0 +1,166 @@
+<?php
+/**
+*
+* @package acm
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @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');
+}
+
+/**
+* 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;
+
+ /**
+ * Creates a redis cache driver.
+ *
+ * The following global constants affect operation:
+ *
+ * PHPBB_ACM_REDIS_HOST
+ * PHPBB_ACM_REDIS_PORT
+ * PHPBB_ACM_REDIS_PASSWORD
+ * PHPBB_ACM_REDIS_DB
+ *
+ * There are no publicly documented constructor parameters.
+ */
+ function __construct()
+ {
+ // Call the parent constructor
+ parent::__construct();
+
+ $this->redis = new Redis();
+
+ $args = func_get_args();
+ if (!empty($args))
+ {
+ $ok = call_user_func_array(array($this->redis, 'connect'), $args);
+ }
+ else
+ {
+ $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT);
+ }
+
+ if (!$ok)
+ {
+ trigger_error('Could not connect to redis server');
+ }
+
+ 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 null
+ */
+ function unload()
+ {
+ parent::unload();
+
+ $this->redis->close();
+ }
+
+ /**
+ * Purge cache data
+ *
+ * @return null
+ */
+ 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;
+ }
+}
+