Beispiel #1
0
 public function testExpireByTimestamp()
 {
     $this->key->getRediska()->set($this->key->getName(), 1);
     $this->key->expire(time() + 1, true);
     sleep(2);
     $reply = $this->key->getRediska()->get($this->key->getName());
     $this->assertNull($reply);
 }
Beispiel #2
0
 public function setnx($keyName, $expire, $value = '')
 {
     $command = new \Rediska_Command_Set($this->client, 'Set', array($keyName, $value, false));
     try {
         if (!$command->execute()) {
             return false;
         }
         $key = new \Rediska_Key($keyName);
         $key->expire($expire);
     } catch (\Rediska_Exception $e) {
         throw new \VisitCounter\Exception\RedisException($e->getMessage(), 0, $e);
     }
     return true;
 }
 static function getAll()
 {
     $key = new Rediska_Key("allEnglish");
     //var_dump($key->getValue());
     if ($allenglish = $key->getValue()) {
         //echo "from redis";
         return $allenglish;
     } else {
         $mysqli = DB::getConn();
         $sql = "select * from english";
         $result = DB::getResult($sql, $mysqli);
         $arr = array();
         while ($array = $result->fetch_assoc()) {
             $arr[] = $array;
         }
         $key->setValue($arr);
         $key->expire(60 * 60);
         DB::close($mysqli, null, $result);
         //echo "from db";
         return $arr;
     }
 }
Beispiel #4
0
 public function __call($method, $args)
 {
     $value = $this->_key->getValue();
     if (is_null($value)) {
         if (is_null($this->_object)) {
             $callback = $method;
         } else {
             $callback = array($this->_object, $method);
         }
         $value = call_user_func_array($callback, $args);
         $this->_key->setValue($value);
         if ($this->_expire !== null) {
             $this->_key->expire($this->_expire, $this->_expireIsTimestamp);
         }
     }
     return $value;
 }