mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-12-23 02:28:01 +00:00
readd removed methods to maintain old plugins, prepare for redis cluster mode
This commit is contained in:
parent
78ae6ff7b6
commit
b6e4badc05
@ -1,5 +1,7 @@
|
||||
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
|
||||
*
|
||||
@ -27,6 +29,10 @@ public class RedisBungee {
|
||||
return api;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public JedisPool getPool() {
|
||||
return api.getJedisPool();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,10 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.summoners.JedisSummoner;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
@ -309,9 +311,28 @@ public class RedisBungeeAPI {
|
||||
* @since 0.7.0
|
||||
*/
|
||||
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.
|
||||
|
@ -55,7 +55,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
return serverCache.get(uuid, new Callable<String>() {
|
||||
@Override
|
||||
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");
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
return proxyCache.get(uuid, new Callable<String>() {
|
||||
@Override
|
||||
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");
|
||||
}
|
||||
}
|
||||
@ -102,7 +102,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> {
|
||||
return ipCache.get(uuid, new Callable<InetAddress>() {
|
||||
@Override
|
||||
public InetAddress call() throws Exception {
|
||||
try (Jedis tmpRsc = plugin.requestJedis()) {
|
||||
try (Jedis tmpRsc = plugin.getJedisSummoner().requestJedis()) {
|
||||
String result = tmpRsc.hget("player:" + uuid, "ip");
|
||||
if (result == null)
|
||||
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>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
try (Jedis tmpRsc = plugin.requestJedis()) {
|
||||
try (Jedis tmpRsc = plugin.getJedisSummoner().requestJedis()) {
|
||||
String result = tmpRsc.hget("player:" + uuid, "online");
|
||||
return result == null ? -1 : Long.valueOf(result);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class PubSubListener implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try (Jedis rsc = plugin.requestJedis()) {
|
||||
try (Jedis rsc = plugin.getJedisSummoner().requestJedis()) {
|
||||
try {
|
||||
|
||||
jpsh = new JedisPubSubHandler(plugin);
|
||||
|
@ -2,6 +2,7 @@ package com.imaginarycode.minecraft.redisbungee.internal;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.summoners.JedisSummoner;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.util.uuid.UUIDTranslator;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
@ -34,6 +35,8 @@ public interface RedisBungeePlugin<P> extends EventsPlatform{
|
||||
|
||||
boolean isJedisAvailable();
|
||||
|
||||
JedisSummoner getJedisSummoner();
|
||||
|
||||
RedisBungeeConfiguration getConfiguration();
|
||||
|
||||
int getCount();
|
||||
|
@ -20,4 +20,6 @@ public interface JedisSummoner extends Closeable {
|
||||
|
||||
boolean isJedisAvailable();
|
||||
|
||||
JedisPool getJedisPool();
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,11 @@ public class SinglePoolJedisSummoner implements JedisSummoner {
|
||||
return !this.jedisPool.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JedisPool getJedisPool() {
|
||||
return this.jedisPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
jedisPool.close();
|
||||
|
@ -14,7 +14,7 @@ public class LuaManager {
|
||||
}
|
||||
|
||||
public Script createScript(String script) {
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
|
||||
String hash = jedis.scriptLoad(script);
|
||||
return new Script(script, hash);
|
||||
}
|
||||
@ -40,7 +40,7 @@ public class LuaManager {
|
||||
public Object eval(List<String> keys, List<String> args) {
|
||||
Object data;
|
||||
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
|
||||
try {
|
||||
data = jedis.evalsha(hashed, keys, args);
|
||||
} catch (JedisDataException e) {
|
||||
|
@ -25,7 +25,7 @@ public abstract class RedisCallable<T> implements Callable<T>, Runnable {
|
||||
}
|
||||
|
||||
private T run(boolean retry) {
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
|
||||
return call(jedis);
|
||||
} catch (JedisConnectionException e) {
|
||||
plugin.logFatal("Unable to get connection");
|
||||
|
@ -73,7 +73,7 @@ public final class UUIDTranslator {
|
||||
}
|
||||
|
||||
// Let's try Redis.
|
||||
try (Jedis jedis = plugin.requestJedis()) {
|
||||
try (Jedis jedis = plugin.getJedisSummoner().requestJedis()) {
|
||||
String stored = jedis.hget("uuid-cache", player.toLowerCase());
|
||||
if (stored != null) {
|
||||
// Found an entry value. Deserialize it.
|
||||
@ -131,7 +131,7 @@ public final class UUIDTranslator {
|
||||
}
|
||||
|
||||
// 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());
|
||||
if (stored != null) {
|
||||
// Found an entry value. Deserialize it.
|
||||
|
@ -1,5 +1,9 @@
|
||||
# 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.
|
||||
# Get Redis from http://redis.io/
|
||||
|
@ -502,6 +502,11 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JedisSummoner getJedisSummoner() {
|
||||
return this.jedisSummoner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig() throws IOException {
|
||||
if (!getDataFolder().exists() && getDataFolder().mkdir()) {
|
||||
|
@ -200,6 +200,11 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
return this.jedisSummoner.isJedisAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JedisSummoner getJedisSummoner() {
|
||||
return this.jedisSummoner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisBungeeAPI getApi() {
|
||||
return this.api;
|
||||
|
Loading…
Reference in New Issue
Block a user