5 * @copyright (c) 2011 phpBB Group
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 if (!defined('IN_PHPBB'))
18 // Include the abstract base
19 if (!class_exists('acm_memory'))
21 require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
24 if (!defined('PHPBB_ACM_REDIS_PORT'))
26 define('PHPBB_ACM_REDIS_PORT', 6379);
29 if (!defined('PHPBB_ACM_REDIS_HOST'))
31 define('PHPBB_ACM_REDIS_HOST', 'localhost');
37 * Compatible with the php extension phpredis available
38 * at https://github.com/nicolasff/phpredis
42 class acm extends acm_memory
44 var $extension = 'redis';
50 // Call the parent constructor
53 $this->redis = new Redis();
54 $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT);
56 if (defined('PHPBB_ACM_REDIS_PASSWORD'))
58 if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD))
62 trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR);
66 $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
67 $this->redis->setOption(Redis::OPT_PREFIX, $this->key_prefix);
69 if (defined('PHPBB_ACM_REDIS_DB'))
71 if (!$this->redis->select(PHPBB_ACM_REDIS_DB))
75 trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR);
81 * Unload the cache resources
89 $this->redis->close();
99 $this->redis->flushDB();
105 * Fetch an item from the cache
108 * @param string $var Cache key
109 * @return mixed Cached data
113 return $this->redis->get($var);
117 * Store data in the cache
120 * @param string $var Cache key
121 * @param mixed $data Data to store
122 * @param int $ttl Time-to-live of cached data
123 * @return bool True if the operation succeeded
125 function _write($var, $data, $ttl = 2592000)
127 return $this->redis->setex($var, $ttl, $data);
131 * Remove an item from the cache
134 * @param string $var Cache key
135 * @return bool True if the operation succeeded
137 function _delete($var)
139 if ($this->redis->delete($var) > 0)