public function testDelete() { $this->key->getRediska()->set($this->key->getName(), 1); $reply = $this->key->getRediska()->exists($this->key->getName()); $this->assertTrue($reply); $this->key->delete(); $reply = $this->key->getRediska()->exists($this->key->getName()); $this->assertFalse($reply); }
public function testGetOrSetValue() { $provider = new BasicKeyDataProvider(); $value = $this->key->getOrSetValue($provider)->data; $this->assertEquals(123, $value); $reply = $this->key->isExists(); $this->assertTrue($reply); $this->assertEquals(123, $this->key->getValue()); $value = $this->key->getOrSetValue($provider)->getOtherDataForTest(); $this->assertEquals(123, $value); $this->key->delete(); $value = $this->key->getOrSetValue($provider)->getData(); $this->assertEquals(123, $value); $reply = $this->key->isExists(); $this->assertTrue($reply); $this->assertEquals(123, $this->key->getValue()); $getOrSetValueObject = $this->key->getOrSetValue($provider); $this->assertEquals(123, "{$getOrSetValueObject}"); }
public function testGetOrSetValue() { require_once REDISKA_TESTS_PATH . '/classes/BasicKeyDataProvider.php'; $provider = new BasicKeyDataProvider(); $value = $this->key->getOrSetValue($provider)->data; $this->assertEquals(123, $value); $reply = $this->key->isExists(); $this->assertTrue($reply); $this->assertEquals(123, $this->key->getValue()); $value = $this->key->getOrSetValue($provider)->getOtherDataForTest(); $this->assertEquals(123, $value); $this->key->delete(); $value = $this->key->getOrSetValue($provider)->getData(); $this->assertEquals(123, $value); $reply = $this->key->isExists(); $this->assertTrue($reply); $this->assertEquals(123, $this->key->getValue()); $getOrSetValueObject = $this->key->getOrSetValue($provider); $this->assertEquals(123, "{$getOrSetValueObject}"); }
/** * 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; } }
public function delete($key) { $key = new Rediska_Key($this->prefix . $key); return $key->delete(); }
public function delete($key) { $Key = new Rediska_Key($key); $Key->setRediska($this->Rediska); return $Key->delete(); }