/** * Session set constructor */ public function __construct() { if (!self::$_saveHandler) { throw new Rediska_Key_Exception('You must initialize Rediska_Zend_Session_SaveHandler_Redis before'); } $keyName = self::getSaveHandler()->getOption('keyPrefix') . 'sessions'; $options = array('rediska' => self::getSaveHandler()->getRediska()); parent::__construct($keyName, $options); }
/** * Saves user's information into the database. If user's id is not known, it will try to create a new user. * If user's id is known, it will try to edit information in database to make it identical to information in * this class. If you want to change user's login, load user's information before doing so. If the user with * selected id does not exist, it will throw an exception with code self::ERROR_NOTFOUND_ID. If the function * tries to create a user with taken login, an exception with code self::ERROR_TAKEN_LOGIN will be thrown. * If the user tries to take somebody else's UUID, an exception with code self::ERROR_TAKEN_UUID will be * thrown. */ public function save() { // id lookup key $userLoginKey = new Rediska_Key('user_login_' . $this->login); // id is known - we are going to edit user's information if ($this->id !== null) { // user with selected id must exist if (!$this->application->rediska->exists('user_' . $this->id)) { throw new ApplicationModelException_User('User with id ' . $this->id . ' does not exist in the database.', self::ERROR_NOTFOUND_ID); } } else { // new login must not be taken by someone else if ($userLoginKey->getValue() !== null) { throw new ApplicationModelException_User('User with login ' . $this->login . ' already exists in the database.', self::ERROR_TAKEN_LOGIN); } } // make sure that the user does not want to take somebody else's uuid foreach ($this->uuids as $time => $uuid) { $userUuidKey = new Rediska_Key('user_uuid_' . $uuid); if ($userUuidKey->getValue() !== null && $userUuidKey->getValue() != $this->id) { throw new ApplicationModelException_User('UUID ' . $uuid . ' is taken by somebody else.', self::ERROR_TAKEN_UUID); } } // if we are creating a new user - get the new id for him if ($this->id === null) { $this->id = $this->incrementRedisCounter('users_count'); } // if user's login needs to be changed (for new users, this will not be active) if ($this->loginOld !== null && $this->loginOld != $this->login) { // new login must not be taken by someone else if ($userLoginKey->getValue() !== null) { throw new ApplicationModelException_User('User with login ' . $this->login . ' already exists in the database.', self::ERROR_TAKEN_LOGIN); } // remove old id lookup key $userLoginOldKey = new Rediska_Key('user_login_' . $this->loginOld); $userLoginOldKey->delete(); } // save user's login and password hash $userKeyHash = new Rediska_Key_Hash('user_' . $this->id); $userKeyHash->login = $this->login; $this->loginOld = $this->login; $userKeyHash->password = $this->passwordHash; // save id lookup key $userLoginKey->setValue($this->id); // for every old uuid of the user: $uuidsKeySet = new Rediska_Key_SortedSet('user_' . $this->id . '_uuids'); foreach ($uuidsKeySet as $uuid) { // cut off uuid_ prefix $uuid = substr($uuid, strlen('uuid_')); // remove old id lookup key $userUuidOldKey = new Rediska_Key('user_uuid_' . $uuid); $userUuidOldKey->delete(); // remove uuid from the list $uuidsKeySet->remove('uuid_' . $uuid); } // for every new uuid for this user: foreach ($this->uuids as $time => $uuid) { // create a new id lookup key $userUuidKey = new Rediska_Key('user_uuid_' . $uuid); $userUuidKey->setValue($this->id); // add it to the list $uuidsKeySet[$time] = 'uuid_' . $uuid; } }
function get_basic_sortedsets($iterations = 1000) { $result = array(); for ($j = 0; $j < $this->set_iteration; $j++) { $set = new Rediska_Key_SortedSet($this->sortedset_variable . $j); $result[$j] = $set->getByRank(); } return $result; }
/** * Returns ids and timestamps of all files which have a specified uploader's UUID. Throws an exception with code * self::ERROR_INVALID_UPLOADER if the UUID is invalid. If there are no files for selected UUID, an empty * array will be returned. */ public static function getIdsForUploader(&$application, $uuid) { // uuid must be valid if (!ApplicationModel_User::validateUuid($uuid)) { throw new ApplicationModelException_File('Uploader UUID is invalid.', self::ERROR_INVALID_UPLOADER); } $fileIds = array(); $filesKeySet = new Rediska_Key_SortedSet('uuid_' . $uuid); $fileIdsSet = $filesKeySet->getByRank(true, 0, 20, true); return $fileIdsSet; }