Пример #1
0
	void OnSerializableDelete(Serialize::Object *obj) override
	{
		std::vector<Anope::string> args;

		redis->StartTransaction();

		for (Serialize::FieldBase *field : obj->GetSerializableType()->GetFields())
		{
			Anope::string value = field->SerializeToString(obj);

			args = { "SREM", "lookup:" + obj->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + value, stringify(obj->id) };
			redis->SendCommand(nullptr, args);

			args = { "DEL", "values:" + stringify(obj->id) + ":" + field->serialize_name };
			redis->SendCommand(nullptr, args);

			args = { "SREM", "keys:" + stringify(obj->id), field->serialize_name };
			redis->SendCommand(nullptr, args);
		}

		args = { "SREM", "ids:" + obj->GetSerializableType()->GetName(), stringify(obj->id) };
		redis->SendCommand(nullptr, args);

		redis->CommitTransaction();
	}
Пример #2
0
	EventReturn OnSerializeSet(Serialize::Object *object, Serialize::FieldBase *field, const Anope::string &value) override
	{
		std::vector<Anope::string> args;

		redis->StartTransaction();

		const Anope::string &old = field->SerializeToString(object);
		args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + old, stringify(object->id) };
		redis->SendCommand(nullptr, args);

		// add object to type set
		args = { "SADD", "ids:" + object->GetSerializableType()->GetName(), stringify(object->id) };
		redis->SendCommand(nullptr, args);

		// add key to key set
		args = { "SADD", "keys:" + stringify(object->id), field->serialize_name };
		redis->SendCommand(nullptr, args);

		// set value
		args = { "SET", "values:" + stringify(object->id) + ":" + field->serialize_name, value };
		redis->SendCommand(nullptr, args);

		// lookup
		args = { "SADD", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + value, stringify(object->id) };
		redis->SendCommand(nullptr, args);

		redis->CommitTransaction();

		return EVENT_CONTINUE;
	}
Пример #3
0
	EventReturn OnSerializeUnset(Serialize::Object *object, Serialize::FieldBase *field) override
	{
		std::vector<Anope::string> args;

		redis->StartTransaction();

		const Anope::string &old = field->SerializeToString(object);
		args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + old, stringify(object->id) };
		redis->SendCommand(nullptr, args);

		// remove field from set
		args = { "SREM", "keys:" + stringify(object->id), field->serialize_name };
		redis->SendCommand(nullptr, args);

		redis->CommitTransaction();

		return EVENT_CONTINUE;
	}
Пример #4
0
	EventReturn OnSerializableGetId(Serialize::ID &id) override
	{
		std::vector<Anope::string> args = { "INCR", "id" };

		auto f = [&](const Reply &r)
		{
			id = r.i;
		};

		FInterface inter(this, f);
		redis->SendCommand(&inter, args);
		while (redis->BlockAndProcess());
		return EVENT_ALLOW;
	}
Пример #5
0
	void OnSerializeTypeCreate(Serialize::TypeBase *sb)
	{
		std::vector<Anope::string> args = { "SMEMBERS", "ids:" + sb->GetName() };

		redis->SendCommand(new TypeLoader(this, sb), args);
	}