readd removed methods to maintain old plugins, prepare for redis cluster mode

This commit is contained in:
mohammed jasem alaajel 2022-07-16 02:58:48 +04:00
parent 78ae6ff7b6
commit b6e4badc05
14 changed files with 63 additions and 12 deletions

View File

@ -1,5 +1,7 @@
package com.imaginarycode.minecraft.redisbungee; package com.imaginarycode.minecraft.redisbungee;
import redis.clients.jedis.JedisPool;
/** /**
* This used to be old plugin instance of redis-bungee, but now it's used to get the api for old plugins * This used to be old plugin instance of redis-bungee, but now it's used to get the api for old plugins
* *
@ -27,6 +29,10 @@ public class RedisBungee {
return api; return api;
} }
@Deprecated
public JedisPool getPool() {
return api.getJedisPool();
}
} }

View File

@ -5,8 +5,10 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin; import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
import com.imaginarycode.minecraft.redisbungee.internal.summoners.JedisSummoner;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.*; import java.util.*;
@ -309,9 +311,28 @@ public class RedisBungeeAPI {
* @since 0.7.0 * @since 0.7.0
*/ */
public Jedis requestJedis() { public Jedis requestJedis() {
return this.plugin.requestJedis(); return this.plugin.getJedisSummoner().requestJedis();
} }
/**
* This gets Redis Bungee {@link JedisPool}
* @return {@link JedisPool}
* @since 0.6.5
*/
public JedisPool getJedisPool() {
return this.plugin.getJedisSummoner().getJedisPool();
}
/**
* This gets Redis Bungee {@link JedisPool}
* @return {@link JedisPool}
* @since 0.6.5
*/
public JedisSummoner getJedisSummoner() {
return this.plugin.getJedisSummoner();
}
/** /**
* *
* @return the API instance. * @return the API instance.

View File

@ -55,7 +55,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return serverCache.get(uuid, new Callable<String>() { return serverCache.get(uuid, new Callable<String>() {
@Override @Override
public String call() throws Exception { public String call() throws Exception {
try (Jedis tmpRsc = plugin.requestJedis()) { try (Jedis tmpRsc = plugin.getJedisSummoner().requestJedis()) {
return Objects.requireNonNull(tmpRsc.hget("player:" + uuid, "server"), "user not found"); return Objects.requireNonNull(tmpRsc.hget("player:" + uuid, "server"), "user not found");
} }
} }
@ -79,7 +79,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return proxyCache.get(uuid, new Callable<String>() { return proxyCache.get(uuid, new Callable<String>() {
@Override @Override
public String call() throws Exception { public String call() throws Exception {
try (Jedis tmpRsc = plugin.requestJedis()) { try (Jedis tmpRsc = plugin.getJedisSummoner().requestJedis()) {
return Objects.requireNonNull(tmpRsc.hget("player:" + uuid, "proxy"), "user not found"); return Objects.requireNonNull(tmpRsc.hget("player:" + uuid, "proxy"), "user not found");
} }
} }
@ -102,7 +102,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return ipCache.get(uuid, new Callable<InetAddress>() { return ipCache.get(uuid, new Callable<InetAddress>() {
@Override @Override
public InetAddress call() throws Exception { public InetAddress call() throws Exception {
try (Jedis tmpRsc = plugin.requestJedis()) { try (Jedis tmpRsc = plugin.getJedisSummoner().requestJedis()) {
String result = tmpRsc.hget("player:" + uuid, "ip"); String result = tmpRsc.hget("player:" + uuid, "ip");
if (result == null) if (result == null)
throw new NullPointerException("user not found"); throw new NullPointerException("user not found");
@ -128,7 +128,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
return lastOnlineCache.get(uuid, new Callable<Long>() { return lastOnlineCache.get(uuid, new Callable<Long>() {
@Override @Override
public Long call() throws Exception { public Long call() throws Exception {
try (Jedis tmpRsc = plugin.requestJedis()) { try (Jedis tmpRsc = plugin.getJedisSummoner().requestJedis()) {
String result = tmpRsc.hget("player:" + uuid, "online"); String result = tmpRsc.hget("player:" + uuid, "online");
return result == null ? -1 : Long.valueOf(result); return result == null ? -1 : Long.valueOf(result);
} }

View File

@ -21,7 +21,7 @@ public class PubSubListener implements Runnable {
@Override @Override
public void run() { public void run() {
try (Jedis rsc = plugin.requestJedis()) { try (Jedis rsc = plugin.getJedisSummoner().requestJedis()) {
try { try {
jpsh = new JedisPubSubHandler(plugin); jpsh = new JedisPubSubHandler(plugin);

View File

@ -2,6 +2,7 @@ package com.imaginarycode.minecraft.redisbungee.internal;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
import com.imaginarycode.minecraft.redisbungee.internal.summoners.JedisSummoner;
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.UUIDTranslator; import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.UUIDTranslator;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
@ -34,6 +35,8 @@ public interface RedisBungeePlugin<P> extends EventsPlatform{
boolean isJedisAvailable(); boolean isJedisAvailable();
JedisSummoner getJedisSummoner();
RedisBungeeConfiguration getConfiguration(); RedisBungeeConfiguration getConfiguration();
int getCount(); int getCount();

View File

@ -20,4 +20,6 @@ public interface JedisSummoner extends Closeable {
boolean isJedisAvailable(); boolean isJedisAvailable();
JedisPool getJedisPool();
} }

View File

@ -22,6 +22,11 @@ public class SinglePoolJedisSummoner implements JedisSummoner {
return !this.jedisPool.isClosed(); return !this.jedisPool.isClosed();
} }
@Override
public JedisPool getJedisPool() {
return this.jedisPool;
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
jedisPool.close(); jedisPool.close();

View File

@ -14,7 +14,7 @@ public class LuaManager {
} }
public Script createScript(String script) { public Script createScript(String script) {
try (Jedis jedis = plugin.requestJedis()) { try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
String hash = jedis.scriptLoad(script); String hash = jedis.scriptLoad(script);
return new Script(script, hash); return new Script(script, hash);
} }
@ -40,7 +40,7 @@ public class LuaManager {
public Object eval(List<String> keys, List<String> args) { public Object eval(List<String> keys, List<String> args) {
Object data; Object data;
try (Jedis jedis = plugin.requestJedis()) { try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
try { try {
data = jedis.evalsha(hashed, keys, args); data = jedis.evalsha(hashed, keys, args);
} catch (JedisDataException e) { } catch (JedisDataException e) {

View File

@ -25,7 +25,7 @@ public abstract class RedisCallable<T> implements Callable<T>, Runnable {
} }
private T run(boolean retry) { private T run(boolean retry) {
try (Jedis jedis = plugin.requestJedis()) { try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
return call(jedis); return call(jedis);
} catch (JedisConnectionException e) { } catch (JedisConnectionException e) {
plugin.logFatal("Unable to get connection"); plugin.logFatal("Unable to get connection");

View File

@ -73,7 +73,7 @@ public final class UUIDTranslator {
} }
// Let's try Redis. // Let's try Redis.
try (Jedis jedis = plugin.requestJedis()) { try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
String stored = jedis.hget("uuid-cache", player.toLowerCase()); String stored = jedis.hget("uuid-cache", player.toLowerCase());
if (stored != null) { if (stored != null) {
// Found an entry value. Deserialize it. // Found an entry value. Deserialize it.
@ -131,7 +131,7 @@ public final class UUIDTranslator {
} }
// Okay, it wasn't locally cached. Let's try Redis. // Okay, it wasn't locally cached. Let's try Redis.
try (Jedis jedis = plugin.requestJedis()) { try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
String stored = jedis.hget("uuid-cache", player.toString()); String stored = jedis.hget("uuid-cache", player.toString());
if (stored != null) { if (stored != null) {
// Found an entry value. Deserialize it. // Found an entry value. Deserialize it.

View File

@ -1,5 +1,9 @@
# RedisBungee configuration file. # RedisBungee configuration file.
# PLEASE READ THE WIKI: https://github.com/Limework/RedisBungee/wiki # PLEASE READ THE WIKI: https://github.com/ProxioDev/RedisBungee/wiki
# Cluster Mode its in different config file redis-cluster.yml
# enabling this option will ignore redis config of this file
cluster-mode: false
# The Redis server you use. # The Redis server you use.
# Get Redis from http://redis.io/ # Get Redis from http://redis.io/

View File

@ -502,6 +502,11 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
} }
} }
@Override
public JedisSummoner getJedisSummoner() {
return this.jedisSummoner;
}
@Override @Override
public void loadConfig() throws IOException { public void loadConfig() throws IOException {
if (!getDataFolder().exists() && getDataFolder().mkdir()) { if (!getDataFolder().exists() && getDataFolder().mkdir()) {

View File

@ -200,6 +200,11 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
return this.jedisSummoner.isJedisAvailable(); return this.jedisSummoner.isJedisAvailable();
} }
@Override
public JedisSummoner getJedisSummoner() {
return this.jedisSummoner;
}
@Override @Override
public RedisBungeeAPI getApi() { public RedisBungeeAPI getApi() {
return this.api; return this.api;