2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

Removed pipelining and other fixes.

This commit is contained in:
Tux 2014-09-11 16:38:40 -04:00
parent 75939ef661
commit bafe894298
5 changed files with 25 additions and 38 deletions

View File

@ -335,11 +335,8 @@ public final class RedisBungee extends Plugin {
tmpRsc.hdel("heartbeats", serverId); tmpRsc.hdel("heartbeats", serverId);
if (tmpRsc.scard("proxy:" + serverId + ":usersOnline") > 0) { if (tmpRsc.scard("proxy:" + serverId + ":usersOnline") > 0) {
Set<String> players = tmpRsc.smembers("proxy:" + serverId + ":usersOnline"); Set<String> players = tmpRsc.smembers("proxy:" + serverId + ":usersOnline");
Pipeline pipeline = tmpRsc.pipelined();
for (String member : players) for (String member : players)
RedisUtil.cleanUpPlayer(member, pipeline); RedisUtil.cleanUpPlayer(member, tmpRsc);
pipeline.sync();
} }
} finally { } finally {
pool.returnResource(tmpRsc); pool.returnResource(tmpRsc);

View File

@ -47,34 +47,31 @@ public class RedisBungeeConsumer implements Runnable {
private void handle(ConsumerEvent event, Jedis jedis) { private void handle(ConsumerEvent event, Jedis jedis) {
if (event instanceof PlayerLoggedInConsumerEvent) { if (event instanceof PlayerLoggedInConsumerEvent) {
PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event; PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event;
Pipeline pipeline = jedis.pipelined(); jedis.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString());
pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString()); jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0"); jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress()); plugin.getUuidTranslator().persistInfo(event1.getPlayer().getName(), event1.getPlayer().getUniqueId(), jedis);
plugin.getUuidTranslator().persistInfo(event1.getPlayer().getName(), event1.getPlayer().getUniqueId(), pipeline); jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "proxy", plugin.getServerId());
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "proxy", plugin.getServerId()); jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.JOIN, event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.JOIN,
new DataManager.LoginPayload(event1.getPlayer().getAddress().getAddress())))); new DataManager.LoginPayload(event1.getPlayer().getAddress().getAddress()))));
pipeline.sync(); jedis.sync();
} else if (event instanceof PlayerLoggedOffConsumerEvent) { } else if (event instanceof PlayerLoggedOffConsumerEvent) {
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event; PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;
Pipeline pipeline = jedis.pipelined();
long timestamp = System.currentTimeMillis(); long timestamp = System.currentTimeMillis();
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", String.valueOf(timestamp)); jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", String.valueOf(timestamp));
RedisUtil.cleanUpPlayer(event1.getPlayer().getUniqueId().toString(), pipeline); RedisUtil.cleanUpPlayer(event1.getPlayer().getUniqueId().toString(), jedis);
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>( jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.LEAVE, event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.LEAVE,
new DataManager.LogoutPayload(timestamp)))); new DataManager.LogoutPayload(timestamp))));
pipeline.sync(); jedis.sync();
} else if (event instanceof PlayerChangedServerConsumerEvent) { } else if (event instanceof PlayerChangedServerConsumerEvent) {
PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event; PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event;
Pipeline pipeline = jedis.pipelined(); jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName()); jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE, event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE,
new DataManager.ServerChangePayload(event1.getNewServer().getName())))); new DataManager.ServerChangePayload(event1.getNewServer().getName()))));
pipeline.sync(); jedis.sync();
} }
} }

View File

@ -17,6 +17,7 @@ import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.*; import net.md_5.bungee.api.event.*;
@ -30,6 +31,11 @@ import java.util.*;
@AllArgsConstructor @AllArgsConstructor
public class RedisBungeeListener implements Listener { public class RedisBungeeListener implements Listener {
private final RedisBungee plugin; private final RedisBungee plugin;
private static final BaseComponent[] ALREADY_LOGGED_IN =
new ComponentBuilder("You are already logged on to this server.").color(ChatColor.RED)
.append("\n\nIf you were disconnected forcefully, please wait up to one minute.\nIf this does not resolve your issue, please contact staff.")
.color(ChatColor.GRAY)
.create();
@EventHandler @EventHandler
public void onPlayerConnect(final PostLoginEvent event) { public void onPlayerConnect(final PostLoginEvent event) {
@ -37,15 +43,15 @@ public class RedisBungeeListener implements Listener {
try { try {
for (String server : plugin.getServerIds()) { for (String server : plugin.getServerIds()) {
if (rsc.sismember("proxy:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) { if (rsc.sismember("proxy:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
event.getPlayer().disconnect(new ComponentBuilder("You are already logged on to this server.").color( event.getPlayer().disconnect(ALREADY_LOGGED_IN);
ChatColor.RED).create());
return; return;
} }
} }
plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
} finally { } finally {
plugin.getPool().returnResource(rsc); plugin.getPool().returnResource(rsc);
} }
plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
} }
@EventHandler @EventHandler

View File

@ -7,16 +7,9 @@
package com.imaginarycode.minecraft.redisbungee; package com.imaginarycode.minecraft.redisbungee;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
class RedisUtil { class RedisUtil {
public static void cleanUpPlayer(String player, Jedis rsc) { public static void cleanUpPlayer(String player, Jedis rsc) {
Pipeline pipeline = rsc.pipelined();
cleanUpPlayer(player, pipeline);
pipeline.sync();
}
public static void cleanUpPlayer(String player, Pipeline rsc) {
rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player); rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
rsc.hdel("player:" + player, "server"); rsc.hdel("player:" + player, "server");
rsc.hdel("player:" + player, "ip"); rsc.hdel("player:" + player, "ip");

View File

@ -181,13 +181,7 @@ public final class UUIDTranslator {
} }
} }
protected final void persistInfo(String name, UUID uuid, Jedis jedis) { public final void persistInfo(String name, UUID uuid, Jedis jedis) {
addToMaps(name, uuid);
jedis.hset("uuid-cache", name.toLowerCase(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));
jedis.hset("uuid-cache", uuid.toString(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));
}
public final void persistInfo(String name, UUID uuid, Pipeline jedis) {
addToMaps(name, uuid); addToMaps(name, uuid);
jedis.hset("uuid-cache", name.toLowerCase(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid))); jedis.hset("uuid-cache", name.toLowerCase(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));
jedis.hset("uuid-cache", uuid.toString(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid))); jedis.hset("uuid-cache", uuid.toString(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));