Exemplo n.º 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();
	}
Exemplo n.º 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;
	}
Exemplo n.º 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;
	}