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