connect() public method

public connect ( ) : Credis_Client
return Credis_Client
 /**
  * Check DB connection
  *
  * @return bool
  */
 public function hasConnection()
 {
     if (!$this->_useRedis) {
         return parent::hasConnection();
     }
     try {
         $this->_redis->connect();
         if ($this->_logLevel >= 7) {
             Mage::log(sprintf("%s: Connected to Redis", $this->_getPid()), Zend_Log::DEBUG, self::LOG_FILE);
             // reset timer
             $this->_timeStart = microtime(true);
         }
         return TRUE;
     } catch (Exception $e) {
         Mage::logException($e);
         $this->_redis = NULL;
         if ($this->_logLevel >= 0) {
             Mage::log(sprintf("%s: Unable to connect to Redis; falling back to MySQL handler", $this->_getPid()), Zend_Log::EMERG, self::LOG_FILE);
         }
         // Fall-back to MySQL handler. If this fails, the file handler will be used.
         $this->_useRedis = FALSE;
         parent::__construct();
         return parent::hasConnection();
     }
 }
 public function _load($session_id)
 {
     $host = (string) (Mage::getConfig()->getNode(self::XML_PATH_HOST) ?: '127.0.0.1');
     $port = (int) (Mage::getConfig()->getNode(self::XML_PATH_PORT) ?: '6379');
     $pass = (string) (Mage::getConfig()->getNode(self::XML_PATH_PASS) ?: '');
     $timeout = (double) (Mage::getConfig()->getNode(self::XML_PATH_TIMEOUT) ?: '2.5');
     $_redis = new Credis_Client($host, $port, $timeout);
     if (!empty($pass)) {
         $_redis->auth($pass);
     }
     $_redis->connect();
     // connect to redis
     // replace sess_session_id with session id you want to read.
     $sessionData = $_redis->hGet('sess_' . $session_id, 'data');
     // only data field is relevant to us, uncompress the data
     return $sessionData ? $this->_decodeData($sessionData) : false;
 }
Beispiel #3
0
 /**
  * Check DB connection
  *
  * @return bool
  */
 public function hasConnection()
 {
     try {
         $this->_redis->connect();
         if ($this->_logLevel >= \Zend_Log::DEBUG) {
             $this->_log("Connected to Redis");
         }
         return TRUE;
     } catch (\Exception $e) {
         $this->logger->logException($e);
         $this->_redis = NULL;
         $this->_log('Unable to connect to Redis');
     }
 }
Beispiel #4
0
 public function testForceStandAloneAfterEstablishedConnection()
 {
     $this->credis->connect();
     $this->setExpectedException('CredisException', 'Cannot force Credis_Client to use standalone PHP driver after a connection has already been established.');
     $this->credis->forceStandalone();
 }
Beispiel #5
0
 /**
  * Check DB connection
  *
  * @return bool
  */
 public function hasConnection()
 {
     if (!$this->_useRedis) {
         return parent::hasConnection();
     }
     try {
         $this->_redis->connect();
         if ($this->_logLevel >= Zend_Log::DEBUG) {
             $this->_log("Connected to Redis");
         }
         return TRUE;
     } catch (Exception $e) {
         Mage::logException($e);
         $this->_redis = NULL;
         Mage::log('Unable to connect to Redis; falling back to MySQL handler', Zend_Log::EMERG);
         // Fall-back to MySQL handler. If this fails, the file handler will be used.
         $this->_useRedis = FALSE;
         parent::__construct();
         return parent::hasConnection();
     }
 }
Beispiel #6
0
 /**
  * Check Redis connection
  *
  * @return bool
  */
 protected function hasConnection()
 {
     try {
         $this->_redis->connect();
         $this->_log("Connected to Redis");
         return true;
     } catch (\Exception $e) {
         $this->logger->logException($e);
         $this->_log('Unable to connect to Redis');
         return false;
     }
 }