public function hmget($hashName, array $fields) { $key = new \Rediska_Key_Hash($hashName); try { $result = $key->get($fields); } catch (\Rediska_Exception $e) { throw new \VisitCounter\Exception\RedisException($e->getMessage(), 0, $e); } return array_combine($fields, $result); }
function get_basic_hashes($iterations = 15000) { $result = array(); for ($i = 0; $i < $iterations; $i++) { $hash = new Rediska_Key_Hash($this->hash_variable . $i); $result[] = $hash->getValues(); } return $result; }
public function testCount() { $this->rediska->setToHash('test', array('a' => 1, 'b' => 2)); $this->assertEquals(2, $this->hash->count()); $this->assertEquals(2, count($this->hash)); }
/** * 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); } }
public function getUlist($ulistKey) { $MSet = new Rediska_Key_Hash($ulistKey); $MSet->setRediska($this->Rediska); return $MSet->toArray(); }