public function __construct($configName)
 {
     parent::__construct($configName);
     $this->memcache->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
     $this->memcache->setOption(Memcached::OPT_NO_BLOCK, true);
     $this->memcache->setOption(Memcached::OPT_AUTO_EJECT_HOSTS, true);
     $this->memcache->setOption(Memcached::OPT_CONNECT_TIMEOUT, 2000);
     $this->memcache->setOption(Memcached::OPT_POLL_TIMEOUT, 2000);
     $this->memcache->setOption(Memcached::OPT_RETRY_TIMEOUT, 2);
     $this->memcache->setSaslAuthData(getenv('MEMCACHIER_USERNAME'), getenv('MEMCACHIER_PASSWORD'));
 }
Пример #2
0
 /**
  * Tests the read only setting for the storage
  *
  * @return void
  */
 public function testReadOnly()
 {
     $defaultStorage = new MemcachedStorage('test2');
     $readWriteStorage = new MemcachedStorage('test');
     $readOnlyStorage = new MemcachedStorage('test5');
     $this->assertFalse($defaultStorage->isReadOnly(), 'A storage should report it is not read only if no read only setting is defined');
     $this->assertFalse($readWriteStorage->isReadOnly(), 'The read-write storage should report it is not read only');
     $this->assertTrue($readOnlyStorage->isReadOnly(), 'The read only storage should report it is read only');
     $this->memcacheMock->data['test'] = array('value' => 'test', 'ttl' => time() + 600);
     $data = $readOnlyStorage->get('test');
     $this->assertNotEmpty($data, 'The retrieved data should not be empty');
     try {
         $readOnlyStorage->set('test', 'test2');
         $this->fail('No StorageException thrown for trying to write to a read only storage');
     } catch (StorageException $exception) {
         $this->assertContains('read only storage', $exception->getMessage());
     }
     $this->assertSame($data, $readOnlyStorage->get('test'), 'The data should not be changed in the storage');
 }