[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\cache\driver; 15 16 if (!defined('PHPBB_ACM_REDIS_PORT')) 17 { 18 define('PHPBB_ACM_REDIS_PORT', 6379); 19 } 20 21 if (!defined('PHPBB_ACM_REDIS_HOST')) 22 { 23 define('PHPBB_ACM_REDIS_HOST', 'localhost'); 24 } 25 26 /** 27 * ACM for Redis 28 * 29 * Compatible with the php extension phpredis available 30 * at https://github.com/nicolasff/phpredis 31 * 32 */ 33 class redis extends \phpbb\cache\driver\memory 34 { 35 var $extension = 'redis'; 36 37 var $redis; 38 39 /** 40 * Creates a redis cache driver. 41 * 42 * The following global constants affect operation: 43 * 44 * PHPBB_ACM_REDIS_HOST 45 * PHPBB_ACM_REDIS_PORT 46 * PHPBB_ACM_REDIS_PASSWORD 47 * PHPBB_ACM_REDIS_DB 48 * 49 * There are no publicly documented constructor parameters. 50 */ 51 function __construct() 52 { 53 // Call the parent constructor 54 parent::__construct(); 55 56 $this->redis = new \Redis(); 57 58 $args = func_get_args(); 59 if (!empty($args)) 60 { 61 $ok = call_user_func_array(array($this->redis, 'connect'), $args); 62 } 63 else 64 { 65 $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); 66 } 67 68 if (!$ok) 69 { 70 trigger_error('Could not connect to redis server'); 71 } 72 73 if (defined('PHPBB_ACM_REDIS_PASSWORD')) 74 { 75 if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD)) 76 { 77 global $acm_type; 78 79 trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR); 80 } 81 } 82 83 $this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP); 84 $this->redis->setOption(\Redis::OPT_PREFIX, $this->key_prefix); 85 86 if (defined('PHPBB_ACM_REDIS_DB')) 87 { 88 if (!$this->redis->select(PHPBB_ACM_REDIS_DB)) 89 { 90 global $acm_type; 91 92 trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR); 93 } 94 } 95 } 96 97 /** 98 * {@inheritDoc} 99 */ 100 function unload() 101 { 102 parent::unload(); 103 104 $this->redis->close(); 105 } 106 107 /** 108 * {@inheritDoc} 109 */ 110 function purge() 111 { 112 $this->redis->flushDB(); 113 114 parent::purge(); 115 } 116 117 /** 118 * Fetch an item from the cache 119 * 120 * @access protected 121 * @param string $var Cache key 122 * @return mixed Cached data 123 */ 124 function _read($var) 125 { 126 return $this->redis->get($var); 127 } 128 129 /** 130 * Store data in the cache 131 * 132 * For the info, see https://phpredis.github.io/phpredis/Redis.html#method_set, 133 * https://redis.io/docs/latest/commands/set/ 134 * and https://redis.io/docs/latest/commands/expire/#appendix-redis-expires 135 * 136 * @access protected 137 * @param string $var Cache key 138 * @param mixed $data Data to store 139 * @param int $ttl Time-to-live of cached data 140 * @return bool True if the operation succeeded 141 */ 142 function _write($var, $data, $ttl = 2592000) 143 { 144 return $this->redis->set($var, $data, ['EXAT' => time() + $ttl]); 145 } 146 147 /** 148 * Remove an item from the cache 149 * 150 * @access protected 151 * @param string $var Cache key 152 * @return bool True if the operation succeeded 153 */ 154 function _delete($var) 155 { 156 if ($this->redis->delete($var) > 0) 157 { 158 return true; 159 } 160 return false; 161 } 162 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |