예제 #1
0
파일: Log.php 프로젝트: utachkin/Rediska
 public function testWrite()
 {
     $this->log->err('123');
     $this->log->info('123');
     $count = $this->rediska->getListLength('log');
     $this->assertEquals(2, $count);
 }
예제 #2
0
 public function __call($name, $args)
 {
     if (strtolower($name) == 'on' && isset($args[0])) {
         $this->_rediska->on($args[0]);
         $this->_oneTimeConnection = $this->_specifiedConnection->getConnection();
         return $this;
     }
     if ($this->_oneTimeConnection) {
         $connection = $this->_oneTimeConnection;
         $this->_oneTimeConnection = null;
     } else {
         $connection = $this->_defaultConnection;
     }
     if ($connection !== null) {
         $this->_specifiedConnection->setConnection($connection);
     } else {
         $this->_specifiedConnection->resetConnection();
     }
     $command = $this->_rediska->getCommand($name, $args);
     if (!$command->isAtomic()) {
         throw new Rediska_Exception("Command '{$name}' doesn't work properly (not atomic) in pipeline on multiple servers");
     }
     $this->_commands[] = $command;
     $this->_specifiedConnection->resetConnection();
     return $this;
 }
예제 #3
0
파일: TestCase.php 프로젝트: J3FF3/Rediska
 protected function tearDown()
 {
     $this->rediska->flushDb(true);
     foreach ($this->rediska->getConnections() as $connection) {
         $connection->disconnect();
     }
     $this->rediska = null;
 }
예제 #4
0
파일: Queue.php 프로젝트: utachkin/Rediska
 public function testDeleteMessage()
 {
     $queue = $this->queue->createQueue('test');
     $queue->send(array(1, 2, 3));
     foreach ($queue->receive() as $message) {
         $queue->deleteMessage($message);
     }
     $values = $this->rediska->getList('Zend_Queue_queue_test');
     $this->assertEquals(array(), $values);
 }
예제 #5
0
 public function __call($name, $args)
 {
     if (strtolower($name) == 'pipeline') {
         return $this->_rediska->pipeline();
     } else {
         $command = $this->_rediska->getCommand($name, $args);
         $command->write();
         return $command->read();
     }
 }
예제 #6
0
 public function testNewInstance()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application4.ini');
     $manager = $application->bootstrap()->getBootstrap()->getResource('cachemanager');
     $manager->getCache('test')->save('1', 'test');
     $rediska = new Rediska(array('redisVersion' => '2.0', 'addToManager' => false));
     $one = $rediska->get('test');
     $this->assertEquals('1', $one[0]);
     $this->assertEquals(array(), Rediska_Manager::getAll());
 }
예제 #7
0
 protected function _addServerOrSkipTest($host, $port)
 {
     $socket = @fsockopen($host, $port);
     if (is_resource($socket)) {
         @fclose($socket);
         $this->rediska->addServer($host, $port, array('persistent' => true));
     } else {
         $this->markTestSkipped("You must start server {$host}:{$port} before run test");
     }
 }
예제 #8
0
파일: Cache.php 프로젝트: utachkin/Rediska
 public function testTouch()
 {
     $this->rediska->set('test', array('aaa', time(), 100));
     $this->rediska->expire('test', 100);
     $reply = $this->cache->touch('test', 200);
     $this->assertTrue($reply);
     $lifetime = $this->rediska->getLifetime('test');
     $this->assertTrue($lifetime > 290);
     $values = $this->rediska->get('test');
     $this->assertEquals(300, $values[2]);
 }
예제 #9
0
 public function testNewInstance()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application4.ini');
     $log = $application->bootstrap()->getBootstrap()->getResource('log');
     $log->err('123');
     $log->info('123');
     $rediska = new Rediska(array('redisVersion' => '2.0', 'addToManager' => false));
     $count = $rediska->getListLength('log');
     $this->assertEquals(2, $count);
     $this->assertEquals(array(), Rediska_Manager::getAll());
 }
예제 #10
0
 /**
  * @group resource
  * @group auto_serialize
  */
 public function testNewInstanceWithAutoSerialization()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application5.ini');
     /* @var Zend_Cache_Manager $manager */
     $manager = $application->bootstrap()->getBootstrap()->getResource('cachemanager');
     $manager->getCache('test')->save('321', 'test');
     $options = $manager->getCache('test')->getBackend()->getOption('storage');
     $rediska = new Rediska(array('redisVersion' => '2.0', 'addToManager' => false));
     $one = $rediska->getHashValues($options['prefix_key'] . 'test');
     $this->assertEquals('321', $one[0]);
     $this->assertEquals(array(), Rediska_Manager::getAll());
 }
예제 #11
0
 public static function factory(Rediska $rediska, $response)
 {
     if (!empty($response)) {
         $name = $response[0];
         if ($rediska->getOption('namespace') != '' && strpos($name, $rediska->getOption('namespace')) === 0) {
             $name = substr($name, strlen($rediska->getOption('namespace')));
         }
         $value = $rediska->getSerializer()->unserialize($response[1]);
         return new self(array('name' => $name, 'value' => $value));
     } else {
         return null;
     }
 }
예제 #12
0
 public static function combine(Rediska $rediska, $valuesAndScores)
 {
     $isValue = true;
     $valuesWithScores = array();
     foreach ($valuesAndScores as $valueOrScore) {
         if ($isValue) {
             $value = $rediska->getSerializer()->unserialize($valueOrScore);
         } else {
             $score = $valueOrScore;
             $valuesWithScores[] = new self(array('value' => $value, 'score' => $score));
         }
         $isValue = !$isValue;
     }
     return $valuesWithScores;
 }
예제 #13
0
 /**
  * Throw if transaction not supported by Redis
  */
 protected function _throwIfNotSupported($title, $version)
 {
     $redisVersion = $this->_rediska->getOption('redisVersion');
     if (version_compare($version, $this->_rediska->getOption('redisVersion')) == 1) {
         throw new Rediska_Transaction_Exception("{$title} requires {$version}+ version of Redis server. Current version is {$redisVersion}. To change it specify 'redisVersion' option.");
     }
 }
예제 #14
0
 public function testOffsetGet()
 {
     $this->rediska->addToSortedSet('test', 123, 1);
     $this->rediska->addToSortedSet('test', 456, 2);
     $this->assertEquals(123, $this->set[1]);
     $this->assertEquals(456, $this->set[2]);
 }
예제 #15
0
 /**
  * Delete a queue and all of it's messages
  *
  * Returns false if the queue is not found, true if the queue exists
  *
  * @param  string  $name queue name
  * @return boolean
  */
 public function delete($name)
 {
     if ($this->_queues->remove($name)) {
         if (isset($this->_queueObjects[$name])) {
             unset($this->_queueObjects[$name]);
         }
         return $this->_rediska->delete($this->_getKeyName("queue_{$name}"));
     }
 }
예제 #16
0
파일: Abstract.php 프로젝트: eason007/e-fw
 /**
  * Throw exception if command not supported by this version of Redis
  *
  * @param string $version
  */
 protected function _throwExceptionIfNotSupported($version = null)
 {
     if (null === $version) {
         $version = $this->_version;
     }
     $redisVersion = $this->_rediska->getOption('redisVersion');
     if (version_compare($version, $redisVersion) == 1) {
         throw new Rediska_Command_Exception("Command '{$this->_name}' requires {$version}+ version of Redis server. Current version is {$redisVersion}. To change it specify 'redisVersion' option.");
     }
 }
 /**
  * We manually remove keys as the redis glob style * == sfCache ** style
  *
  * @see sfCache
  */
 public function removePattern($pattern)
 {
     $pattern = $this->getKey($pattern);
     $regexp = self::patternToRegexp($pattern);
     $keys = $this->_rediska->getKeysByPattern($pattern);
     foreach ($keys as $key) {
         if (preg_match($regexp, $key)) {
             $this->remove(substr($key, strlen($this->getOption('prefix'))));
         }
     }
 }
예제 #18
0
 public static function getMultiple($ids = array())
 {
     if (!empty($ids)) {
         foreach ($ids as &$id) {
             $id = self::_getKey($id);
         }
         $rediska = Rediska::getDefaultInstance();
         return $rediska->get($ids);
     }
     return array();
 }
예제 #19
0
 /**
  * Writer constructor
  * 
  * @param string            $keyName Log key name
  * @param Zend_Config|array $options Rediska options
  */
 public function __construct($keyName, $options = array())
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     }
     $defaultInstance = Rediska::getDefaultInstance();
     if (empty($options) && $defaultInstance) {
         $rediska = $defaultInstance;
     } else {
         $rediska = new Rediska($options);
     }
     $this->_list = new Rediska_Key_List($keyName);
     $this->_list->setRediska($rediska);
 }
예제 #20
0
파일: Redis.php 프로젝트: utachkin/Rediska
 /**
  * Garbage Collection
  *
  * @param int $maxlifetime
  * @return true
  */
 public function gc($maxlifetime)
 {
     $sessions = $this->_set->toArray();
     foreach ($sessions as &$session) {
         $session = $this->_getKeyName($session);
     }
     // TODO: May by use TTL? Need benchmark.
     $lifeSession = $this->_rediska->get($sessions);
     foreach ($sessions as $session) {
         if (!isset($lifeSession[$session])) {
             $sessionWithoutPrefix = substr($session, strlen($this->_options['keyprefix']));
             $this->_set->remove($sessionWithoutPrefix);
         }
     }
     return true;
 }
예제 #21
0
 /**
  * Magic method for add command to pipeline
  *
  * @param string $name Command name
  * @param array  $args Arguments
  * @return Rediska_Pipeline
  */
 public function __call($name, $args)
 {
     if (strtolower($name) == 'on' && isset($args[0])) {
         $this->_rediska->on($args[0]);
         $this->_oneTimeConnection = $this->_specifiedConnection->getConnection();
         return $this;
     }
     // TODO: Implement transaction and config
     if (in_array(strtolower($name), array('transaction', 'config'))) {
         throw new Rediska_Exception("{$name} in pipeline not implemented yet.");
     }
     if (in_array(strtolower($name), array('monitor', 'subscribe'))) {
         throw new Rediska_Transaction_Exception("You can't use '{$name}' in pipeline");
     }
     return $this->_addCommand($name, $args);
 }
예제 #22
0
 public function testSelectDb()
 {
     $rediska = new Rediska(array('servers' => array(array('host' => REDISKA_HOST, 'port' => REDISKA_PORT, 'db' => 2))));
     $rediska->set('a', 123);
     $rediska->selectDb(1);
     $reply = $rediska->get('a');
     $this->assertNull($reply);
     $rediska->selectDb(2);
     $reply = $rediska->get('a');
     $this->assertEquals(123, $reply);
 }
예제 #23
0
 public function testGC()
 {
     $this->rediska->set('s_123', 'aaa');
     $this->rediska->addToSet('s_sessions', '123');
     $reply = $this->saveHandler->gc(0);
     $this->assertTrue($reply);
     $values = $this->rediska->getSet('s_sessions');
     $this->assertEquals(array('123'), $values);
     $value = $this->rediska->get('s_123');
     $this->assertEquals('aaa', $value);
     $this->rediska->delete('s_123');
     $reply = $this->saveHandler->gc(0);
     $this->assertTrue($reply);
     $values = $this->rediska->getSet('s_sessions');
     $this->assertEquals(array(), $values);
 }
예제 #24
0
 public function testSelect()
 {
     $config = $GLOBALS['rediskaConfigs'][0];
     $config['servers'][0]['db'] = 2;
     $rediska = new Rediska($config);
     $rediska->set('a', 123);
     $rediska->selectDb(1);
     $reply = $rediska->get('a');
     $this->assertNull($reply);
     $rediska->selectDb(2);
     $reply = $rediska->get('a');
     $this->assertEquals(123, $reply);
 }
예제 #25
0
파일: Redis.php 프로젝트: utachkin/Rediska
 /**
  * Give (if possible) an extra lifetime to the given cache id
  *
  * @param string $id cache id
  * @param int $extraLifetime
  * @return boolean true if ok
  */
 public function touch($id, $extraLifetime)
 {
     $tmp = $this->_rediska->get($id);
     if (is_array($tmp)) {
         $data = $tmp[0];
         $mtime = $tmp[1];
         if (!isset($tmp[2])) {
             // because this record is only with 1.7 release
             // if old cache records are still there...
             return false;
         }
         $lifetime = $tmp[2];
         $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
         if ($newLifetime <= 0) {
             return false;
         }
         $result = $this->_rediska->set($id, array($data, time(), $newLifetime));
         if ($result) {
             $this->_rediska->expire($id, $newLifetime);
         }
         return $result;
     }
     return false;
 }
예제 #26
0
 protected function _destroy()
 {
     Cookie::delete($this->_cookie_name);
     return $this->_rediska->delete($this->id());
 }
예제 #27
0
파일: Manager.php 프로젝트: eason007/e-fw
 /**
  * Remove Rediska
  *
  * @param Rediska $rediska Rediska instance or options
  * @return boolean
  */
 public static function remove($rediska)
 {
     if ($rediska instanceof Rediska) {
         $name = $rediska->getName();
     } else {
         if (is_string($rediska)) {
             $name = $rediska;
         } else {
             throw new Rediska_Exception('Rediska must be a instance or name');
         }
     }
     if (!isset(self::$_instances[$name])) {
         throw new Rediska_Exception("Rediska instance '{$name}' not present");
     }
     unset(self::$_instances[$name]);
     return true;
 }
예제 #28
0
 /**
  * Setup Rediska instance
  */
 protected function _setupRediskaDefaultInstance()
 {
     if (is_null($this->_rediska)) {
         $this->_rediska = Rediska::getDefaultInstance();
         if (is_null($this->_rediska)) {
             $this->_rediska = new Rediska();
         }
     }
 }
 /**
  * Fetch an array of all keys stored in cache
  *
  * @return array Returns the array of cache keys
  */
 protected function _getCacheKeys()
 {
     return $this->_rediska->getKeysByPattern('*');
 }
예제 #30
0
파일: Set.php 프로젝트: utachkin/Rediska
 public function testOffsetSet()
 {
     $this->set[] = 123;
     $reply = $this->rediska->existsInSet('test', 123);
     $this->assertTrue($reply);
 }