forceStandalone() public method

public forceStandalone ( ) : Credis_Client
return Credis_Client
Esempio n. 1
0
 protected function setUp()
 {
     if ($this->config === NULL) {
         $configFile = dirname(__FILE__) . '/test_config.json';
         if (!file_exists($configFile) || !($config = file_get_contents($configFile))) {
             $this->markTestSkipped('Could not load ' . $configFile);
         }
         $this->config = json_decode($config);
     }
     $this->credis = new Credis_Client($this->config->host, $this->config->port, $this->config->timeout);
     if ($this->useStandalone) {
         $this->credis->forceStandalone();
     }
 }
Esempio n. 2
0
 /**
  * Connect with a Sentinel node. Sentinel will do the master and slave discovery
  * @param Credis_Client $client
  */
 public function __construct(Credis_Client $client)
 {
     if (!$client instanceof Credis_Client) {
         throw new CredisException('Sentinel client should be an instance of Credis_Client');
     }
     $client->forceStandalone();
     $this->_client = $client;
 }
Esempio n. 3
0
 /**
  * Connect with a Sentinel node. Sentinel will do the master and slave discovery
  *
  * @param Credis_Client $client
  * @param string $password (deprecated - use setClientPassword)
  * @throws CredisException
  */
 public function __construct(Credis_Client $client, $password = NULL)
 {
     if (!$client instanceof Credis_Client) {
         throw new CredisException('Sentinel client should be an instance of Credis_Client');
     }
     $client->forceStandalone();
     // SENTINEL command not currently supported by phpredis
     $this->_client = $client;
     $this->_password = $password;
     $this->_timeout = NULL;
     $this->_persistent = '';
     $this->_db = 0;
 }
Esempio n. 4
0
 /**
  * Public for testing/inspection purposes only.
  *
  * @param $forceStandalone
  * @return \Credis_Client
  */
 public function _redisClient($forceStandalone)
 {
     if ($forceStandalone) {
         $this->_redis->forceStandalone();
     }
     if ($this->_dbNum) {
         $this->_redis->select($this->_dbNum);
     }
     return $this->_redis;
 }
Esempio n. 5
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();
 }
Esempio n. 6
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'];
     }
 }