Skip to content
Snippets Groups Projects
Select Git revision
  • 4dc38db1298c9354af36dbf2b6dc592b4d06355f
  • main default protected
  • 5.5 protected
  • atlantis
  • 5.3 protected
  • 5.0 protected
  • issue-23
  • issue8-seat-logging-and-export
  • ticket-216
  • tickets-215-216-241-242
10 results

ChildrenOfStructuralElementsIndex.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    StudipRedisCache.class.php 4.44 KiB
    <?php
    /**
     * Cache implementation using redis.
     *
     * @author      Jan-Hendrik Willms <tleilax+studip@gmail.com>
     * @license     GPL2 or any later version
     * @package     studip
     * @subpackage  cache
     * @since       Stud.IP 5.0
     */
    class StudipRedisCache implements StudipCache
    {
        use StudipCacheKeyTrait;
    
        private $redis;
    
        /**
         * @return string A translateable display name for this cache class.
         */
        public static function getDisplayName(): string
        {
            return _('Redis');
        }
    
        /**
         * Construct a cache instance.
         *
         * @param string $hostname Hostname of redis server
         * @param int    $port     Port of redis server
         * @param string $auth     Optional auth token/password
         */
        public function __construct($hostname, $port, string $auth = '')
        {
            if (!extension_loaded('redis')) {
                throw new Exception('Redis extension missing.');
            }
    
            $this->redis = new Redis();
            $status = $this->redis->connect($hostname, $port, 1);
    
            if (!$status) {
                throw new Exception('Could not add cache.');
            }
    
            if ($auth !== '') {
                $this->redis->auth($auth);
            }
        }
    
        /**
         * Returns the instance of the redis server connection.
         *
         * @return Redis instance
         */
        public function getRedis()
        {
            return $this->redis;
        }
    
        /**
         * Expire item from the cache.
         *
         * Example:
         *
         *   # expires foo
         *   $cache->expire('foo');
         *
         * @param   string $arg a single key.
         */
        public function expire($arg)