Esempio n. 1
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. 2
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. 3
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. 4
0
 protected function _write()
 {
     return $this->_rediska->expire($this->id(), $this->_lifetime());
 }