Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

redis.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 3.07 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\cache\driver;
 015   
 016  if (!defined('PHPBB_ACM_REDIS_PORT'))
 017  {
 018      define('PHPBB_ACM_REDIS_PORT', 6379);
 019  }
 020   
 021  if (!defined('PHPBB_ACM_REDIS_HOST'))
 022  {
 023      define('PHPBB_ACM_REDIS_HOST', 'localhost');
 024  }
 025   
 026  /**
 027  * ACM for Redis
 028  *
 029  * Compatible with the php extension phpredis available
 030  * at https://github.com/nicolasff/phpredis
 031  *
 032  */
 033  class redis extends \phpbb\cache\driver\memory
 034  {
 035      var $extension = 'redis';
 036   
 037      var $redis;
 038   
 039      /**
 040      * Creates a redis cache driver.
 041      *
 042      * The following global constants affect operation:
 043      *
 044      * PHPBB_ACM_REDIS_HOST
 045      * PHPBB_ACM_REDIS_PORT
 046      * PHPBB_ACM_REDIS_PASSWORD
 047      * PHPBB_ACM_REDIS_DB
 048      *
 049      * There are no publicly documented constructor parameters.
 050      */
 051      function __construct()
 052      {
 053          // Call the parent constructor
 054          parent::__construct();
 055   
 056          $this->redis = new \Redis();
 057   
 058          $args = func_get_args();
 059          if (!empty($args))
 060          {
 061              $ok = call_user_func_array(array($this->redis, 'connect'), $args);
 062          }
 063          else
 064          {
 065              $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT);
 066          }
 067   
 068          if (!$ok)
 069          {
 070              trigger_error('Could not connect to redis server');
 071          }
 072   
 073          if (defined('PHPBB_ACM_REDIS_PASSWORD'))
 074          {
 075              if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD))
 076              {
 077                  global $acm_type;
 078   
 079                  trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR);
 080              }
 081          }
 082   
 083          $this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
 084          $this->redis->setOption(\Redis::OPT_PREFIX, $this->key_prefix);
 085   
 086          if (defined('PHPBB_ACM_REDIS_DB'))
 087          {
 088              if (!$this->redis->select(PHPBB_ACM_REDIS_DB))
 089              {
 090                  global $acm_type;
 091   
 092                  trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR);
 093              }
 094          }
 095      }
 096   
 097      /**
 098      * {@inheritDoc}
 099      */
 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  }
 163