protected function _read($id = NULL) { $this->_data = $this->_rediska->get($this->id($id)); if (!is_array($this->_data)) { $this->_data = array(); } return NULL; }
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); }
/** * Retrieve a cached value entry by id. * @param string id of cache to entry * @param string default value to return if cache miss * @return mixed * @throws Kohana_Cache_Exception */ public function get($id, $default = NULL) { $key = $this->_sanitize_id($id); if (!$this->_rediska->exists($key)) { $value = $default; } else { $value = $this->_rediska->get($key); } // Return the value return $value; }
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); }
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); }
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()); }
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]); }
/** * 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; }
/** * 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; }
/** * Test if a cache record exists for the passed id * * @param string $id cache id * @return mixed Returns either the cached data or false */ protected function _doFetch($id, $testCacheValidity = true) { return ($get = $this->_rediska->get($id)) ? $get : false; }
/** * @see sfCache */ public function getLastModified($key) { return $this->_rediska->get($this->getKey($key, 'lastmodified')); }
<?php set_include_path(implode(PATH_SEPARATOR, array(realpath('../library'), get_include_path()))); // STREAM print 'Benchmark stream: '; require_once 'Rediska.php'; $startTime = microtime(true); $rediska = new Rediska(array('servers' => array(array('host' => '127.0.0.1', 'port' => 6379)))); $value = str_repeat('a', 1000000); for ($i = 0; $i <= 1000; $i++) { $rediska->set('test', $value); $rediska->get('test'); $rediska->delete('test'); } $elapsedTime = microtime(true) - $startTime; print sprintf('%.4f', $elapsedTime) . "\n"; // SOCKET print 'Benchmark socket: '; $startTime = microtime(true); $rediska = new Rediska(array('servers' => array(array('host' => '127.0.0.1', 'port' => 6379, 'useSocket' => true)))); for ($i = 0; $i <= 1000; $i++) { $rediska->set('test', $value); $rediska->get('test'); $rediska->delete('test'); } $elapsedTime = microtime(true) - $startTime; print sprintf('%.4f', $elapsedTime) . "\n";