Beispiel #1
0
 /**
  * @param Handler\ConfigInterface $config
  * @param Handler\LoggerInterface $logger
  * @param Handler\ProfilerInterface|null $profiler
  */
 public function __construct(\Cm\RedisSession\Handler\ConfigInterface $config, \Cm\RedisSession\Handler\LoggerInterface $logger, \Cm\RedisSession\Handler\ProfilerInterface $profiler = null)
 {
     $this->_config = $config;
     $this->logger = $logger;
     $this->profiler = $profiler;
     $this->_logLevel = (int) ($config->descend('log_level') ?: self::DEFAULT_LOG_LEVEL);
     if ($this->_logLevel >= \Zend_Log::DEBUG) {
         $timeStart = microtime(true);
     }
     // Database config
     $host = "{$config->descend('host')}" ?: '127.0.0.1';
     $port = (int) $config->descend('port') ?: 6379;
     $pass = (string) ($config->descend('password') ?: '');
     $timeout = (double) ($config->descend('timeout') ?: self::DEFAULT_TIMEOUT);
     $persistent = (string) ($config->descend('persistent') ?: '');
     $this->_dbNum = (int) ($config->descend('db') ?: 0);
     // General config
     $this->_compressionThreshold = (int) ($config->descend('compression_threshold') ?: self::DEFAULT_COMPRESSION_THRESHOLD);
     $this->_compressionLib = (string) ($config->descend('compression_lib') ?: self::DEFAULT_COMPRESSION_LIB);
     $this->_maxConcurrency = (int) ($config->descend('max_concurrency') ?: self::DEFAULT_MAX_CONCURRENCY);
     $this->_maxLifetime = (int) ($config->descend('max_lifetime') ?: self::DEFAULT_MAX_LIFETIME);
     $this->_minLifetime = (int) ($config->descend('min_lifetime') ?: self::DEFAULT_MIN_LIFETIME);
     $this->_useLocking = defined('CM_REDISSESSION_LOCKING_ENABLED') ? CM_REDISSESSION_LOCKING_ENABLED : !(strlen("{$config->descend('disable_locking')}") ? (bool) "{$config->descend('disable_locking')}" : self::DEFAULT_DISABLE_LOCKING);
     // Use sleep time multiplier so break time is in seconds
     $this->_failAfter = (int) round(1000000 / self::SLEEP_TIME * self::FAIL_AFTER);
     // Connect and authenticate
     $this->_redis = new \Credis_Client($host, $port, $timeout, $persistent);
     if (!empty($pass)) {
         $this->_redis->auth($pass) or \Zend_Cache::throwException('Unable to authenticate with the redis server.');
     }
     $this->_redis->setCloseOnDestruct(FALSE);
     // Destructor order cannot be predicted
     if ($this->_logLevel >= \Zend_Log::DEBUG) {
         $this->_log(sprintf("%s initialized for connection to %s:%s after %.5f seconds", get_class($this), $host, $port, microtime(true) - $timeStart));
     }
 }