create redis server driver

@return CacheSessionHandler
969794
protected function createRedisDriver()
    {
        $serverArray    = $this->config['servers'];
        $persistent     = boolval($this->config['persistent']);
        $prefix         = trim($this->config['prefix']);
        $expireTime     = intval($this->config['lifetime']);

        if ($persistent) {
            foreach ($serverArray as $k => $v) {
                $v['persistent']    = true;
                $serverArray[$k]    = $v;
            }
        }

        $redisServer    = new RedisServer($serverArray);
        $redisStore     = new RedisStore($redisServer, $prefix);
        return new CacheSessionHandler($redisStore, $expireTime);
    }
1147057
public function start() {
        // NOTE: memcached before 2.2.0 expires session locks automatically after max_execution_time,
        //       this leads to major difference compared to other session drivers that timeout
        //       and stop the second request execution instead.

        $default = ini_get('max_execution_time');
        set_time_limit($this->acquiretimeout);

        $isnewsession = empty($_COOKIE[session_name()]);
        $starttimer = microtime(true);

        $result = parent::start();

        // If session_start returned TRUE, but it took as long
        // as the timeout value, and the $_SESSION returned is
        // empty when should not have been (isnewsession false)
        // then assume it did timeout and is invalid.
        // Add 1 second to elapsed time to account for inexact
        // timings in php_memcached_session.c.
        // @TODO Remove this check when php-memcached is fixed
        // to return false after key lock acquisition timeout.
        if (!$isnewsession && $result && count($_SESSION) == 0
            && (microtime(true) - $starttimer + 1) >= floatval($this->acquiretimeout)) {
            $result = false;
        }

        set_time_limit($default);
        return $result;
    }
599706
public function factory()
    {
        $redis = new \Redis();
        $host = $this->getConfig()->getValue(self::CONFIG_HOST);
        $port = $this->getConfig()->getValue(self::CONFIG_PORT);
        $timeout = $this->getConfig()->getValue(self::CONFIG_TIMEOUT);

        if ($this->getConfig()->getValueFlag(self::CONFIG_PERSISTENT)) {
            $redis->pconnect($host, $port, $timeout);
        } else {
            $redis->connect($host, $port, $timeout);
        }

        if ($this->getConfig()->hasValue(self::CONFIG_DATABASE)) {
            $redis->select($this->getConfig()->getValue(self::CONFIG_DATABASE));
        }

        return $redis;
    }
391221
private function getDriver(): \BearFramework\App\ICacheDriver
    {
        if ($this->driver !== null) {
            return $this->driver;
        }
        throw new \Exception('No cache driver specified! Use useAppDataDriver() or setDriver() to specify one.');
    }
1005410
protected function createClient(array $servers)
    {
        $clients = [];
        foreach ($servers as $key => $server) {
            $clients[$key] = new \Redis();
            $clients[$key]->pconnect($server['host'], $server['port'], 0, $key . $server['database']);

            if (!empty($server['password'])) {
                $clients[$key]->auth($server['password']);
            }

            if (!empty($server['database'])) {
                $clients[$key]->select($server['database']);
            }
        }

        return $clients;
    }
351977
protected function createMemcacheDriver()
    {
        $serverArray    = $this->config['servers'];
        $persistent     = boolval($this->config['persistent']);
        $name           = trim($this->config['server_name']);
        $prefix         = trim($this->config['prefix']);
        $expireTime     = intval($this->config['lifetime']);

        if ($persistent && (strlen($name) > 0)) {
            $memcached  = new Memcached($name);
        } else {
            $memcached  = new Memcached();
        }

        if (!sizeof($memcached->getServerList())) {
            $memcached->addServers($serverArray);
        }

        $store = new MemcachedStore($memcached, $prefix);
        return new CacheSessionHandler($store, $expireTime);
    }
1248886
public static function redis()
    {
        // Detect when the PID of the current process has changed (from a fork, etc)
        // and force a reconnect to redis.
        $pid = getmypid();
        if (self::$pid !== $pid) {
            self::$redis = null;
            self::$pid = $pid;
        }

        if (!is_null(self::$redis)) {
            return self::$redis;
        }

        $server = self::$redisServer;
        if (empty($server)) {
            $server = 'localhost:6379';
        }

        if (is_array($server)) {
            require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
            self::$redis = new Resque_RedisCluster($server);
        } else {
            if (strpos($server, 'unix:') === false) {
                list($host, $port) = explode(':', $server);
            } else {
                $host = $server;
                $port = null;
            }
            require_once dirname(__FILE__) . '/Resque/Redis.php';
            $redisInstance = new Resque_Redis($host, $port, self::$password);
            $redisInstance->prefix(self::$namespace);
            self::$redis = $redisInstance;
        }

        if (!empty(self::$redisDatabase)) {
            self::$redis->select(self::$redisDatabase);
        }

        return self::$redis;
    }
496227
protected function createCacheHandler($driver)
    {
        $minutes = $this->app['config']['session.lifetime'];

        return new CacheBasedSessionHandler($this->app['cache']->driver($driver), $minutes);
    }
1358784
public function initialize()
    {
        $driver = $this->_class;

        if (empty($driver)) {
            throw new Exception\InvalidArgumentException(
                "The session driver is invalid."
            );
        }

        // Load user defined driver
        if (class_exists($driver)) {
            $driverObj = new $driver($this->_options);
            if (is_a($driverObj, '\Slick\Session\Driver\DriverInterface')) {
                return $driverObj;
            } else {
                throw new Exception\InvalidArgumentException(
                    "The session type '{$driver}' doesn't inherited from "
                    ."Slick\Session\Driver\DriverInterface."
                );
            }
        }

        // Load module predefined drivers
        switch ($driver) {
            case 'server':
                $driverObj = new Driver\Server($this->_options);
                break;

            default:
                throw new Exception\InvalidArgumentException(
                    "The session type '{$driver}' isn't implemented."
                );
        }
       
        return $driverObj;
    }
113021
protected function createSessionDriver()
    {
        $determiner = new Determiners\Session(
            $this->app['config']['localize-middleware']['session']
        );

        $determiner->setFallback($this->app['config']['app']['fallback_locale']);

        return $determiner;
    }
915267
protected function createCacheHandler($driver)
    {
        $store = $this->app['config']->get('session.store') ?: $driver;

        $minutes = $this->app['config']['session.lifetime'];

        return new CacheBasedSessionHandler(clone $this->app['cache']->store($store), $minutes);
    }
1315795
protected function createCacheHandler( $driver )
	{
		return new CacheBasedSessionHandler( clone CacheManager::i()->driver( $driver ), Config::get( $this->configPrefix . '.lifetime' ) );
	}
1213919
private function connection__redis() {
		$this->connection = new \Redis();
		# @note: This emits warning on failure instead of throwing
		# exception, hence the @ sign.
		if (!@$this->connection->connect(
			$this->redishost, $this->redisport,
			$this->redistimeout
		))
			// @codeCoverageIgnoreStart
			return $this->connection_open_fail();
			// @codeCoverageIgnoreEnd
		if ($this->redispassword || $this->redisdatabase) {
			try {
				if ($this->redispassword)
					$this->connection->auth($this->redispassword);
				if ($this->redisdatabase)
					$this->connection->select($this->redisdatabase);
			} catch(\RedisException $e) {
				return $this->connection_open_fail($e->getMessage());
			}
		}
		try {
			$this->connection->ping();
		} catch(\RedisException $e) {
			return $this->connection_open_fail($e->getMessage());
		}
		return $this->connection_open_ok();
	}
491751
public function store($name = null)
    {
        if (is_null($name)) {
            $name = $this->defaultStore;
        }

        if (isset($this->caches[$name])) {
            return $this->caches[$name];
        }

        $config = config('cache.stores.' . $name);
        if ($config === null) {
            throw new InvalidArgumentException('Cache store "' . $name . '" is not defined.');
        }

        if (!isset($config['driver'])) {
            throw new InvalidArgumentException('Cache driver for store "' . $name . '" is not specified.');
        }

        switch ($config['driver']) {
            case 'APCu':
                $provider = new ApcuCache;
                break;
            case 'Array':
                $provider = new ArrayCache;
                break;
            case 'File':
                $provider = new FilesystemCache($config['path']);
                break;
            case 'Memcached':
                $memcached = new Memcached();
                $memcached->addServer($config['host'], $config['port'], $config['weight']);
                $provider = new MemcachedCache();
                $provider->setMemcached($memcached);
                break;
            case 'Redis':
                $redis = new Redis;
                $redis->connect($config['host'], $config['port'], $config['timeout']);
                $provider = new RedisCache;
                $provider->setRedis($redis);
                break;
            default:
                throw new InvalidArgumentException('Cache driver "' . $config['driver'] . '" is not supported.');
        }

        return $this->caches[$name] = new Cache($provider);
    }
1059546
private static function cache()
    {
        if (is_null(self::$memcached) && class_exists('Memcached')) {
            $servers = [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 100]];

            self::$memcached = new Memcached();

            foreach ($servers as $server) {
                self::$memcached->addServer(
                    $server['host'], $server['port'], $server['weight']
                );
            }

            if (self::$memcached->getVersion() === false) {
                throw new \RuntimeException("Could not establish Memcached connection.");
            }
        }

        return self::$memcached;
    }
1208323
public static function build()
    {
        switch (true) {
            // @codeCoverageIgnoreStart
            case extension_loaded('apc'):
                $cacheDriver = new ApcuCache;
                break;

            case extension_loaded('xcache'):
                $cacheDriver = new XcacheCache;
                break;

            case extension_loaded('memcache'):
                $memcache = new \Memcache;
                $memcache->connect('127.0.0.1');

                $cacheDriver = new MemcacheCache;
                $cacheDriver->setMemcache($memcache);
                break;

            case extension_loaded('redis'):
                $redis = new \Redis();
                $redis->connect('127.0.0.1');

                $cacheDriver = new RedisCache;
                $cacheDriver->setRedis($redis);
                break;
            // @codeCoverageIgnoreEnd

            default:
                $cacheDriver = new ArrayCache;
        }

        return $cacheDriver;
    }
461016
public static function driver() {
        $key = get_called_class();
        if($driver = Pool::get($key)) {
            return $driver;
        }

        $args = func_get_args();
        $config = static::config();
        $config and array_unshift($args,$config);
        $class =  call_user_func_array(
            'static::create',
            $args
        );

        return Pool::set($key,$class);
    }