2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-10-31 18:48:01 +00:00

Tweaks, more pipelining.

This commit is contained in:
Tux 2014-06-17 15:47:52 -04:00
parent 511202044c
commit 688246b8fe

View File

@ -332,8 +332,10 @@ public final class RedisBungee extends Plugin {
public void run() { public void run() {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {
rsc.hset("playerCounts", serverId, String.valueOf(getProxy().getOnlineCount())); Pipeline pipeline = rsc.pipelined();
rsc.hset("heartbeats", serverId, String.valueOf(System.currentTimeMillis())); pipeline.hset("playerCounts", serverId, String.valueOf(getProxy().getOnlineCount()));
pipeline.hset("heartbeats", serverId, String.valueOf(System.currentTimeMillis()));
pipeline.sync();
} catch (JedisConnectionException e) { } catch (JedisConnectionException e) {
// Redis server has disappeared! // Redis server has disappeared!
getLogger().log(Level.SEVERE, "Unable to update proxy counts - did your Redis server go away?", e); getLogger().log(Level.SEVERE, "Unable to update proxy counts - did your Redis server go away?", e);
@ -405,6 +407,7 @@ public final class RedisBungee extends Plugin {
Jedis tmpRsc = pool.getResource(); Jedis tmpRsc = pool.getResource();
try { try {
tmpRsc.hdel("playerCounts", serverId); tmpRsc.hdel("playerCounts", serverId);
tmpRsc.hdel("heartbeats", serverId);
if (tmpRsc.scard("server:" + serverId + ":usersOnline") > 0) { if (tmpRsc.scard("server:" + serverId + ":usersOnline") > 0) {
Set<String> players = tmpRsc.smembers("server:" + serverId + ":usersOnline"); Set<String> players = tmpRsc.smembers("server:" + serverId + ":usersOnline");
Pipeline pipeline = tmpRsc.pipelined(); Pipeline pipeline = tmpRsc.pipelined();
@ -413,7 +416,6 @@ public final class RedisBungee extends Plugin {
pipeline.sync(); pipeline.sync();
} }
tmpRsc.hdel("heartbeats", serverId);
} finally { } finally {
pool.returnResource(tmpRsc); pool.returnResource(tmpRsc);
} }
@ -443,17 +445,16 @@ public final class RedisBungee extends Plugin {
String redisPassword = configuration.getString("redis-password"); String redisPassword = configuration.getString("redis-password");
serverId = configuration.getString("server-id"); serverId = configuration.getString("server-id");
if (redisPassword != null && (redisPassword.equals("") || redisPassword.equals("none"))) { if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
redisPassword = null; redisPassword = null;
} }
// Configuration sanity checks. // Configuration sanity checks.
if (serverId == null || serverId.equals("")) { if (serverId == null || serverId.isEmpty()) {
throw new RuntimeException("server-id is not specified in the configuration or is empty"); throw new RuntimeException("server-id is not specified in the configuration or is empty");
} }
if (redisServer != null) { if (redisServer != null && !redisServer.isEmpty()) {
if (!redisServer.equals("")) {
JedisPoolConfig config = new JedisPoolConfig(); JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(configuration.getInt("max-redis-connections", -1)); config.setMaxTotal(configuration.getInt("max-redis-connections", -1));
pool = new JedisPool(config, redisServer, redisPort, 0, redisPassword); pool = new JedisPool(config, redisServer, redisPort, 0, redisPassword);
@ -491,7 +492,6 @@ public final class RedisBungee extends Plugin {
pool.returnResource(rsc); pool.returnResource(rsc);
} }
} }
}
} else { } else {
throw new RuntimeException("No redis server specified!"); throw new RuntimeException("No redis server specified!");
} }