mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
Use Redis pipelining for more efficiency on high-load setups. Also updated Jedis dependency.
This commit is contained in:
parent
6e90c0949b
commit
460414b3e6
3
pom.xml
3
pom.xml
@ -130,7 +130,8 @@
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.4.2</version>
|
||||
<version>2.5.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
|
@ -21,10 +21,7 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.*;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
@ -409,8 +406,12 @@ public final class RedisBungee extends Plugin {
|
||||
try {
|
||||
tmpRsc.hdel("playerCounts", serverId);
|
||||
if (tmpRsc.scard("server:" + serverId + ":usersOnline") > 0) {
|
||||
for (String member : tmpRsc.smembers("server:" + serverId + ":usersOnline"))
|
||||
RedisUtil.cleanUpPlayer(member, tmpRsc);
|
||||
Set<String> players = tmpRsc.smembers("server:" + serverId + ":usersOnline");
|
||||
Pipeline pipeline = tmpRsc.pipelined();
|
||||
for (String member : players)
|
||||
RedisUtil.cleanUpPlayer(member, pipeline);
|
||||
|
||||
pipeline.sync();
|
||||
}
|
||||
tmpRsc.hdel("heartbeats", serverId);
|
||||
} finally {
|
||||
|
@ -12,6 +12,7 @@ import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedInCons
|
||||
import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedOffConsumerEvent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@ -46,17 +47,22 @@ public class RedisBungeeConsumer implements Runnable {
|
||||
private void handle(ConsumerEvent event, Jedis jedis) {
|
||||
if (event instanceof PlayerLoggedInConsumerEvent) {
|
||||
PlayerLoggedInConsumerEvent event1 = (PlayerLoggedInConsumerEvent) event;
|
||||
jedis.sadd("server:" + RedisBungee.getApi().getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString());
|
||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
|
||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
|
||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "name", event1.getPlayer().getName());
|
||||
jedis.hset("uuids", event1.getPlayer().getName().toLowerCase(), event1.getPlayer().getUniqueId().toString());
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.sadd("server:" + RedisBungee.getApi().getServerId() + ":usersOnline", event1.getPlayer().getUniqueId().toString());
|
||||
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", "0");
|
||||
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "ip", event1.getPlayer().getAddress().getAddress().getHostAddress());
|
||||
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "name", event1.getPlayer().getName());
|
||||
pipeline.hset("uuids", event1.getPlayer().getName().toLowerCase(), event1.getPlayer().getUniqueId().toString());
|
||||
pipeline.sync();
|
||||
} else if (event instanceof PlayerLoggedOffConsumerEvent) {
|
||||
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", String.valueOf(System.currentTimeMillis()));
|
||||
RedisUtil.cleanUpPlayer(event1.getPlayer().getUniqueId().toString(), jedis);
|
||||
RedisUtil.cleanUpPlayer(event1.getPlayer().getUniqueId().toString(), pipeline);
|
||||
pipeline.sync();
|
||||
} else if (event instanceof PlayerChangedServerConsumerEvent) {
|
||||
PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event;
|
||||
// No use in pipelining this
|
||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,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) {
|
||||
@ -14,4 +15,10 @@ class RedisUtil {
|
||||
rsc.hdel("player:" + player, "server");
|
||||
rsc.hdel("player:" + player, "ip");
|
||||
}
|
||||
|
||||
public static void cleanUpPlayer(String player, Pipeline rsc) {
|
||||
rsc.srem("server:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
|
||||
rsc.hdel("player:" + player, "server");
|
||||
rsc.hdel("player:" + player, "ip");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user