mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-12-23 10:38:01 +00:00
Reintroduce pipelining support.
This commit is contained in:
parent
8b5eacec40
commit
8e6447c8e0
@ -45,6 +45,7 @@ import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
@ -74,14 +75,16 @@ public class RedisBungeeListener implements Listener {
|
||||
plugin.getService().submit(new RedisCallable<Void>(plugin) {
|
||||
@Override
|
||||
protected Void call(Jedis jedis) {
|
||||
jedis.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event.getPlayer().getUniqueId().toString());
|
||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "online", "0");
|
||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "ip", event.getPlayer().getAddress().getAddress().getHostAddress());
|
||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), jedis);
|
||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "proxy", RedisBungee.getConfiguration().getServerId());
|
||||
jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", event.getPlayer().getUniqueId().toString());
|
||||
pipeline.hset("player:" + event.getPlayer().getUniqueId().toString(), "online", "0");
|
||||
pipeline.hset("player:" + event.getPlayer().getUniqueId().toString(), "ip", event.getPlayer().getAddress().getAddress().getHostAddress());
|
||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), pipeline);
|
||||
pipeline.hset("player:" + event.getPlayer().getUniqueId().toString(), "proxy", RedisBungee.getConfiguration().getServerId());
|
||||
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
|
||||
event.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.JOIN,
|
||||
new DataManager.LoginPayload(event.getPlayer().getAddress().getAddress()))));
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@ -92,12 +95,14 @@ public class RedisBungeeListener implements Listener {
|
||||
plugin.getService().submit(new RedisCallable<Void>(plugin) {
|
||||
@Override
|
||||
protected Void call(Jedis jedis) {
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
long timestamp = System.currentTimeMillis();
|
||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "online", String.valueOf(timestamp));
|
||||
RedisUtil.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), jedis);
|
||||
jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
|
||||
pipeline.hset("player:" + event.getPlayer().getUniqueId().toString(), "online", String.valueOf(timestamp));
|
||||
RedisUtil.cleanUpPlayer(event.getPlayer().getUniqueId().toString(), pipeline);
|
||||
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
|
||||
event.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.LEAVE,
|
||||
new DataManager.LogoutPayload(timestamp))));
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@ -108,10 +113,12 @@ public class RedisBungeeListener implements Listener {
|
||||
plugin.getService().submit(new RedisCallable<Void>(plugin) {
|
||||
@Override
|
||||
protected Void call(Jedis jedis) {
|
||||
jedis.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
||||
jedis.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.hset("player:" + event.getPlayer().getUniqueId().toString(), "server", event.getServer().getInfo().getName());
|
||||
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
|
||||
event.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE,
|
||||
new DataManager.ServerChangePayload(event.getServer().getInfo().getName()))));
|
||||
pipeline.sync();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -27,6 +27,7 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
class RedisUtil {
|
||||
public static void cleanUpPlayer(String player, Jedis rsc) {
|
||||
@ -36,6 +37,13 @@ class RedisUtil {
|
||||
rsc.hdel("player:" + player, "proxy");
|
||||
}
|
||||
|
||||
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
||||
rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
|
||||
rsc.hdel("player:" + player, "server");
|
||||
rsc.hdel("player:" + player, "ip");
|
||||
rsc.hdel("player:" + player, "proxy");
|
||||
}
|
||||
|
||||
public static boolean canUseLua(String redisVersion) {
|
||||
// Need to use >=2.6 to use Lua optimizations.
|
||||
String[] args = redisVersion.split("\\.");
|
||||
|
@ -34,6 +34,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
@ -198,6 +199,12 @@ public final class UUIDTranslator {
|
||||
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);
|
||||
jedis.hset("uuid-cache", name.toLowerCase(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));
|
||||
jedis.hset("uuid-cache", uuid.toString(), RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)));
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
private class CachedUUIDEntry {
|
||||
|
Loading…
Reference in New Issue
Block a user