Esempio n. 1
0
 protected function _write()
 {
     if ($this->_lifetime > 0) {
         return $this->_rediska->setAndExpire($this->id(), $this->_data, $this->_lifetime);
     } else {
         return $this->_rediska->set($this->id(), $this->_data);
     }
 }
Esempio n. 2
0
 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]);
 }
Esempio n. 3
0
 protected function setUp()
 {
     $this->rediska = new Rediska(array('namespace' => 'Rediska_Tests_', 'servers' => array(array('host' => REDISKA_HOST, 'port' => REDISKA_PORT))));
     $this->rediska->set('user_ids:test', 1);
     $data = new stdClass();
     $data->login = '******';
     $data->password = '******';
     $this->rediska->set('users:1', $data);
     $this->auth = Zend_Auth::getInstance();
     $this->adapter = new Rediska_Zend_Auth_Adapter_Redis();
 }
Esempio n. 4
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);
 }
Esempio n. 5
0
 /**
  * Write session data
  *
  * @param string $id
  * @param string $data
  * @return boolean
  */
 public function write($id, $data)
 {
     $this->_set[] = $id;
     $reply = $this->_rediska->set($this->_getKeyName($id), $data);
     if ($reply) {
         $this->_rediska->expire($this->_getKeyName($id), $this->_options['lifetime']);
     }
     return $reply;
 }
Esempio n. 6
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);
 }
Esempio n. 7
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);
 }
Esempio n. 8
0
 /**
  * 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;
 }
Esempio n. 9
0
<?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";