Ejemplo n.º 1
0
 function set_basic_sortedsets($iterations = 1000)
 {
     $time = time();
     for ($j = 0; $j < $this->set_iteration; $j++) {
         $zset = new Rediska_Key_SortedSet($this->sortedset_variable . $j);
         for ($i = 0; $i < $iterations; $i++) {
             $zset->add($i, $time);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Deletes the file from the database and disk. The file's id or path of the file must be set before this function is
  * called. If the id is unknown, but the path is known, this function will try to find the file's id first.
  * Then it will try to delete the information for the file from the database. If file with selected path or
  * id does not exist, an exception with code self::ERROR_NOTFOUND_PATH or self::ERROR_NOTFOUND_ID will be
  * thrown. If both path and file id were not set when this function is called, an exception with code
  * self::ERROR_UNDEFINED_ID will be thrown.
  */
 public function delete()
 {
     // id lookup hash
     $path = $this->path;
     $filePathHash = new Rediska_Key_Hash('file_path');
     // if the id is unknown, but the path is - use id lookup key to get the id of the file.
     if ($this->id === null && $this->path !== null) {
         if ($filePathHash->{$path} === null) {
             throw new ApplicationModelException_File('File with path ' . $this->path . ' does not exist in the database.', self::ERROR_NOTFOUND_PATH);
         }
         $this->id = (int) $filePathHash->{$path};
     }
     // if the id is known, delete the information from the database
     if ($this->id !== null) {
         if (!$this->application->rediska->exists('file_' . $this->id)) {
             throw new ApplicationModelException_File('File with id ' . $this->id . ' does not exist in the database.', self::ERROR_NOTFOUND_ID);
         }
         // delete file's information
         $fileKeyHash = new Rediska_Key_Hash('file_' . $this->id);
         if ($this->path == null) {
             $this->path = $fileKeyHash->path;
         }
         // Remove file from disk
         unlink($this->path);
         $fileKeyHash->delete();
         // remove id lookup field
         unset($filePathHash->{$path});
         // remove file from user's upload list
         $filesUuidKeySet = new Rediska_Key_SortedSet('uuid_' . $this->uploader);
         // dirty hack for saving "uuid_HASH" in redis after removing last user file
         if ($filesUuidKeySet->getLength() < 2) {
             $filesUuidKeySet->add('virtual', 0);
         }
         $filesUuidKeySet->remove('file_' . $this->id);
     } else {
         throw new ApplicationModelException_File('Not enough information was given to delete the file\'s information.', self::ERROR_UNDEFINED_ID);
     }
 }