setMaxConnectRetries() public method

public setMaxConnectRetries ( integer $retries ) : Credis_Client
$retries integer
return Credis_Client
Example #1
0
 public function testGettersAndSetters()
 {
     $this->assertEquals($this->credis->getHost(), $this->config[0]->host);
     $this->assertEquals($this->credis->getPort(), $this->config[0]->port);
     $this->assertEquals($this->credis->getSelectedDb(), 0);
     $this->assertTrue($this->credis->select(2));
     $this->assertEquals($this->credis->getSelectedDb(), 2);
     $this->assertTrue($this->credis->isConnected());
     $this->credis->close();
     $this->assertFalse($this->credis->isConnected());
     $this->credis = new Credis_Client($this->config[0]->host, $this->config[0]->port, null, 'persistenceId');
     $this->assertEquals('persistenceId', $this->credis->getPersistence());
     $this->credis = new Credis_Client('localhost', 12345);
     $this->credis->setMaxConnectRetries(1);
     $this->setExpectedException('CredisException', 'Connection to Redis failed after 2 failures.');
     $this->credis->connect();
 }
Example #2
0
 /**
  * Contruct Zend_Cache Redis backend
  * @param array $options
  * @return \Cm_Cache_Backend_Redis
  */
 public function __construct($options = array())
 {
     if (empty($options['server'])) {
         Zend_Cache::throwException('Redis \'server\' not specified.');
     }
     if (empty($options['port']) && substr($options['server'], 0, 1) != '/') {
         Zend_Cache::throwException('Redis \'port\' not specified.');
     }
     $port = isset($options['port']) ? $options['port'] : NULL;
     $timeout = isset($options['timeout']) ? $options['timeout'] : self::DEFAULT_CONNECT_TIMEOUT;
     $persistent = isset($options['persistent']) ? $options['persistent'] : '';
     $this->_redis = new Credis_Client($options['server'], $port, $timeout, $persistent);
     if (isset($options['force_standalone']) && $options['force_standalone']) {
         $this->_redis->forceStandalone();
     }
     $connectRetries = isset($options['connect_retries']) ? (int) $options['connect_retries'] : self::DEFAULT_CONNECT_RETRIES;
     $this->_redis->setMaxConnectRetries($connectRetries);
     if (!empty($options['read_timeout']) && $options['read_timeout'] > 0) {
         $this->_redis->setReadTimeout((double) $options['read_timeout']);
     }
     if (!empty($options['password'])) {
         $this->_redis->auth($options['password']) or Zend_Cache::throwException('Unable to authenticate with the redis server.');
     }
     // Always select database on startup in case persistent connection is re-used by other code
     if (empty($options['database'])) {
         $options['database'] = 0;
     }
     $this->_redis->select((int) $options['database']) or Zend_Cache::throwException('The redis database could not be selected.');
     if (isset($options['notMatchingTags'])) {
         $this->_notMatchingTags = (bool) $options['notMatchingTags'];
     }
     if (isset($options['compress_tags'])) {
         $this->_compressTags = (int) $options['compress_tags'];
     }
     if (isset($options['compress_data'])) {
         $this->_compressData = (int) $options['compress_data'];
     }
     if (isset($options['lifetimelimit'])) {
         $this->_lifetimelimit = (int) min($options['lifetimelimit'], self::MAX_LIFETIME);
     }
     if (isset($options['compress_threshold'])) {
         $this->_compressThreshold = (int) $options['compress_threshold'];
     }
     if (isset($options['automatic_cleaning_factor'])) {
         $this->_options['automatic_cleaning_factor'] = (int) $options['automatic_cleaning_factor'];
     } else {
         $this->_options['automatic_cleaning_factor'] = 0;
     }
     if (isset($options['compression_lib'])) {
         $this->_compressionLib = $options['compression_lib'];
     } else {
         if (function_exists('snappy_compress')) {
             $this->_compressionLib = 'snappy';
         } else {
             if (function_exists('lzf_compress')) {
                 $this->_compressionLib = 'lzf';
             } else {
                 $this->_compressionLib = 'gzip';
             }
         }
     }
     $this->_compressPrefix = substr($this->_compressionLib, 0, 2) . self::COMPRESS_PREFIX;
     if (isset($options['use_lua'])) {
         $this->_useLua = (bool) $options['use_lua'];
     }
 }