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

Cache server-ids

This commit is contained in:
Tux 2014-04-19 15:54:30 -04:00
parent 72eb4c6a67
commit cce0368f4c

View File

@ -56,6 +56,7 @@ public final class RedisBungee extends Plugin implements Listener {
private static JedisPool pool; private static JedisPool pool;
private static RedisBungeeAPI api; private static RedisBungeeAPI api;
private static PubSubListener psl = null; private static PubSubListener psl = null;
private List<String> serverIds;
private int globalCount; private int globalCount;
/** /**
@ -72,6 +73,10 @@ public final class RedisBungee extends Plugin implements Listener {
} }
final List<String> getServerIds() { final List<String> getServerIds() {
return serverIds;
}
final List<String> getCurrentServerIds() {
Jedis jedis = pool.getResource(); Jedis jedis = pool.getResource();
try { try {
ImmutableList.Builder<String> servers = ImmutableList.builder(); ImmutableList.Builder<String> servers = ImmutableList.builder();
@ -116,7 +121,7 @@ public final class RedisBungee extends Plugin implements Listener {
if (pool != null) { if (pool != null) {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {
for (String i : rsc.smembers("servers")) { for (String i : getServerIds()) {
if (i.equals(configuration.getString("server-id"))) continue; if (i.equals(configuration.getString("server-id"))) continue;
if (rsc.exists("server:" + i + ":playerCount")) if (rsc.exists("server:" + i + ":playerCount"))
try { try {
@ -150,7 +155,7 @@ public final class RedisBungee extends Plugin implements Listener {
if (pool != null) { if (pool != null) {
Jedis rsc = pool.getResource(); Jedis rsc = pool.getResource();
try { try {
for (String i : rsc.smembers("servers")) { for (String i : getServerIds()) {
if (i.equals(configuration.getString("server-id"))) continue; if (i.equals(configuration.getString("server-id"))) continue;
Set<String> users = rsc.smembers("server:" + i + ":usersOnline"); Set<String> users = rsc.smembers("server:" + i + ":usersOnline");
if (users != null && !users.isEmpty()) if (users != null && !users.isEmpty())
@ -307,6 +312,7 @@ public final class RedisBungee extends Plugin implements Listener {
pool.returnResource(tmpRsc); pool.returnResource(tmpRsc);
} }
globalCount = getCurrentCount(); globalCount = getCurrentCount();
serverIds = getCurrentServerIds();
getProxy().getScheduler().schedule(this, new Runnable() { getProxy().getScheduler().schedule(this, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -322,6 +328,7 @@ public final class RedisBungee extends Plugin implements Listener {
pool.returnResource(rsc); pool.returnResource(rsc);
} }
globalCount = getCurrentCount(); globalCount = getCurrentCount();
serverIds = getCurrentServerIds();
} }
}, 0, 3, TimeUnit.SECONDS); }, 0, 3, TimeUnit.SECONDS);
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand()); getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand());