mirror of
				https://github.com/proxiodev/RedisBungee.git
				synced 2025-10-31 07:48:02 +00:00 
			
		
		
		
	readd support for redis versions below 6, change method of the summoner
This commit is contained in:
		
							parent
							
								
									b214e3dad7
								
							
						
					
					
						commit
						b0ab5e3cb4
					
				| @ -20,9 +20,9 @@ as its last version before internal changes. | |||||||
| |:-------------:|:---------:| | |:-------------:|:---------:| | ||||||
| |     1.x.x     | ✖	 | | |     1.x.x     | ✖	 | | ||||||
| |     2.x.x     | ✖	 | | |     2.x.x     | ✖	 | | ||||||
| |     3.x.x     | ✖	 | | |     3.x.x     | ✔	 | | ||||||
| |     4.x.x     | ✖	 | | |     4.x.x     | ✔	 | | ||||||
| |     5.x.x     | ✖	 | | |     5.x.x     | ✔	 | | ||||||
| |     6.x.x     | ✔  | | |     6.x.x     | ✔  | | ||||||
| |     7.x.x     | ✔  | | |     7.x.x     | ✔  | | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import com.google.common.collect.Multimap; | |||||||
| import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; | import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner; | import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; | import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.util.RedisBungeeMode; | import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode; | ||||||
| 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 redis.clients.jedis.JedisPool; | ||||||
| @ -37,6 +37,7 @@ public class RedisBungeeAPI { | |||||||
|                 "redisbungee-" + plugin.getConfiguration().getServerId(), |                 "redisbungee-" + plugin.getConfiguration().getServerId(), | ||||||
|                 "redisbungee-data" |                 "redisbungee-data" | ||||||
|         ); |         ); | ||||||
|  |         new RedisBungee(this); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ import com.google.common.util.concurrent.UncheckedExecutionException; | |||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.util.RedisTask; | import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask; | ||||||
| import redis.clients.jedis.Jedis; | import redis.clients.jedis.Jedis; | ||||||
| import redis.clients.jedis.JedisCluster; | import redis.clients.jedis.JedisCluster; | ||||||
| 
 | 
 | ||||||
| @ -55,7 +55,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> { | |||||||
|         try { |         try { | ||||||
|             return serverCache.get(uuid, new RedisTask<String>(plugin.getApi()) { |             return serverCache.get(uuid, new RedisTask<String>(plugin.getApi()) { | ||||||
|                 @Override |                 @Override | ||||||
|                 public String singleJedisTask(Jedis jedis) { |                 public String jedisTask(Jedis jedis) { | ||||||
|                     return Objects.requireNonNull(jedis.hget("player:" + uuid, "server"), "user not found"); |                     return Objects.requireNonNull(jedis.hget("player:" + uuid, "server"), "user not found"); | ||||||
| 
 | 
 | ||||||
|                 } |                 } | ||||||
| @ -84,7 +84,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> { | |||||||
|         try { |         try { | ||||||
|             return proxyCache.get(uuid, new RedisTask<String>(plugin.getApi()) { |             return proxyCache.get(uuid, new RedisTask<String>(plugin.getApi()) { | ||||||
|                 @Override |                 @Override | ||||||
|                 public String singleJedisTask(Jedis jedis) { |                 public String jedisTask(Jedis jedis) { | ||||||
|                     return Objects.requireNonNull(jedis.hget("player:" + uuid, "proxy"), "user not found"); |                     return Objects.requireNonNull(jedis.hget("player:" + uuid, "proxy"), "user not found"); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
| @ -110,7 +110,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> { | |||||||
|         try { |         try { | ||||||
|             return ipCache.get(uuid, new RedisTask<InetAddress>(plugin.getApi()) { |             return ipCache.get(uuid, new RedisTask<InetAddress>(plugin.getApi()) { | ||||||
|                 @Override |                 @Override | ||||||
|                 public InetAddress singleJedisTask(Jedis jedis) { |                 public InetAddress jedisTask(Jedis jedis) { | ||||||
|                     String result = jedis.hget("player:" + uuid, "ip"); |                     String result = jedis.hget("player:" + uuid, "ip"); | ||||||
|                     if (result == null) |                     if (result == null) | ||||||
|                         throw new NullPointerException("user not found"); |                         throw new NullPointerException("user not found"); | ||||||
| @ -142,7 +142,7 @@ public abstract class AbstractDataManager<P, PL, PD, PS> { | |||||||
|         try { |         try { | ||||||
|             return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin.getApi()) { |             return lastOnlineCache.get(uuid, new RedisTask<Long>(plugin.getApi()) { | ||||||
|                 @Override |                 @Override | ||||||
|                 public Long singleJedisTask(Jedis jedis) { |                 public Long jedisTask(Jedis jedis) { | ||||||
|                     String result = jedis.hget("player:" + uuid, "online"); |                     String result = jedis.hget("player:" + uuid, "online"); | ||||||
|                     return result == null ? -1 : Long.parseLong(result); |                     return result == null ? -1 : Long.parseLong(result); | ||||||
|                 } |                 } | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| package com.imaginarycode.minecraft.redisbungee.api; | package com.imaginarycode.minecraft.redisbungee.api; | ||||||
| 
 | 
 | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.util.RedisTask; | import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask; | ||||||
| import redis.clients.jedis.Jedis; | import redis.clients.jedis.Jedis; | ||||||
| import redis.clients.jedis.JedisCluster; | import redis.clients.jedis.JedisCluster; | ||||||
| import redis.clients.jedis.exceptions.JedisConnectionException; | import redis.clients.jedis.exceptions.JedisConnectionException; | ||||||
| @ -24,7 +24,7 @@ public class PubSubListener implements Runnable { | |||||||
|     public void run() { |     public void run() { | ||||||
|         RedisTask<Void> subTask = new RedisTask<Void>(plugin.getApi()) { |         RedisTask<Void> subTask = new RedisTask<Void>(plugin.getApi()) { | ||||||
|             @Override |             @Override | ||||||
|             public Void singleJedisTask(Jedis jedis) { |             public Void jedisTask(Jedis jedis) { | ||||||
|                 try { |                 try { | ||||||
|                     jpsh = new JedisPubSubHandler(plugin); |                     jpsh = new JedisPubSubHandler(plugin); | ||||||
|                     addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId()); |                     addedChannels.add("redisbungee-" + plugin.getConfiguration().getServerId()); | ||||||
|  | |||||||
| @ -0,0 +1,5 @@ | |||||||
|  | package com.imaginarycode.minecraft.redisbungee.api; | ||||||
|  | 
 | ||||||
|  | public enum RedisBungeeMode { | ||||||
|  |     SINGLE, CLUSTER | ||||||
|  | } | ||||||
| @ -3,7 +3,6 @@ package com.imaginarycode.minecraft.redisbungee.api; | |||||||
| 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.api.summoners.Summoner; | import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.util.RedisBungeeMode; |  | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator; | import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator; | ||||||
| 
 | 
 | ||||||
| import java.net.InetAddress; | import java.net.InetAddress; | ||||||
| @ -99,4 +98,6 @@ public interface RedisBungeePlugin<P> extends EventsPlatform{ | |||||||
| 
 | 
 | ||||||
|     RedisBungeeMode getRedisBungeeMode(); |     RedisBungeeMode getRedisBungeeMode(); | ||||||
| 
 | 
 | ||||||
|  |     Long getRedisClusterTime(); | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -11,6 +11,10 @@ public class JedisSummoner implements Summoner<Jedis> { | |||||||
| 
 | 
 | ||||||
|     public JedisSummoner(JedisPool jedisPool) { |     public JedisSummoner(JedisPool jedisPool) { | ||||||
|         this.jedisPool = jedisPool; |         this.jedisPool = jedisPool; | ||||||
|  |         try (Jedis jedis = this.jedisPool.getResource()) { | ||||||
|  |             // Test the connection to make sure configuration is right | ||||||
|  |             jedis.ping(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | |||||||
| @ -1,10 +1,11 @@ | |||||||
| package com.imaginarycode.minecraft.redisbungee.api.util; | package com.imaginarycode.minecraft.redisbungee.api.tasks; | ||||||
| 
 | 
 | ||||||
| import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; | import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; | import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner; | import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner; | import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; | import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; | ||||||
|  | import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode; | ||||||
| import redis.clients.jedis.Jedis; | import redis.clients.jedis.Jedis; | ||||||
| import redis.clients.jedis.JedisCluster; | import redis.clients.jedis.JedisCluster; | ||||||
| 
 | 
 | ||||||
| @ -14,7 +15,7 @@ public abstract class RedisTask<V> implements Runnable, Callable<V> { | |||||||
| 
 | 
 | ||||||
|     private final Summoner<?> summoner; |     private final Summoner<?> summoner; | ||||||
|     private final RedisBungeeAPI api; |     private final RedisBungeeAPI api; | ||||||
| 
 |     private Jedis jedis; | ||||||
|     private RedisBungeePlugin<?> plugin; |     private RedisBungeePlugin<?> plugin; | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
| @ -33,7 +34,23 @@ public abstract class RedisTask<V> implements Runnable, Callable<V> { | |||||||
|         this.summoner = api.getSummoner(); |         this.summoner = api.getSummoner(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public abstract V singleJedisTask(Jedis jedis); |     // way to reuse jedis inside another RedisTask object | ||||||
|  |     public RedisTask(RedisBungeeAPI api, Jedis jedis) { | ||||||
|  |         this.api = api; | ||||||
|  |         this.summoner = api.getSummoner(); | ||||||
|  |         this.jedis = jedis; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // way to reuse jedis inside another RedisTask object | ||||||
|  |     public RedisTask(RedisBungeePlugin<?> plugin, Jedis jedis) { | ||||||
|  |         this.plugin = plugin; | ||||||
|  |         this.api = plugin.getApi(); | ||||||
|  |         this.summoner = api.getSummoner(); | ||||||
|  |         this.jedis = jedis; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     public abstract V jedisTask(Jedis jedis); | ||||||
| 
 | 
 | ||||||
|     public abstract V clusterJedisTask(JedisCluster jedisCluster); |     public abstract V clusterJedisTask(JedisCluster jedisCluster); | ||||||
| 
 | 
 | ||||||
| @ -44,12 +61,16 @@ public abstract class RedisTask<V> implements Runnable, Callable<V> { | |||||||
| 
 | 
 | ||||||
|     public V execute(){ |     public V execute(){ | ||||||
|         if (api.getMode() == RedisBungeeMode.SINGLE) { |         if (api.getMode() == RedisBungeeMode.SINGLE) { | ||||||
|  |             if (this.jedis != null){ | ||||||
|  |                 return this.jedisTask(this.jedis); | ||||||
|  |             } | ||||||
|             JedisSummoner jedisSummoner = (JedisSummoner) summoner; |             JedisSummoner jedisSummoner = (JedisSummoner) summoner; | ||||||
|             try (Jedis jedis = jedisSummoner.obtainResource()) { |             try (Jedis newJedis = jedisSummoner.obtainResource()) { | ||||||
|                 return this.singleJedisTask(jedis); |                 return this.jedisTask(newJedis); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         } else if (api.getMode() == RedisBungeeMode.CLUSTER) { |         } else if (api.getMode() == RedisBungeeMode.CLUSTER) { | ||||||
|  |             // Jedis cluster does not need new instance since its single instance anyways. | ||||||
|             ClusterJedisSummoner clusterJedisSummoner = (ClusterJedisSummoner) summoner; |             ClusterJedisSummoner clusterJedisSummoner = (ClusterJedisSummoner) summoner; | ||||||
|             return this.clusterJedisTask(clusterJedisSummoner.obtainResource()); |             return this.clusterJedisTask(clusterJedisSummoner.obtainResource()); | ||||||
|         } |         } | ||||||
| @ -1,5 +0,0 @@ | |||||||
| package com.imaginarycode.minecraft.redisbungee.api.util; |  | ||||||
| 
 |  | ||||||
| public enum RedisBungeeMode { |  | ||||||
|     SINGLE, CLUSTER |  | ||||||
| } |  | ||||||
| @ -1,8 +1,9 @@ | |||||||
| package com.imaginarycode.minecraft.redisbungee.api; | package com.imaginarycode.minecraft.redisbungee.api.util; | ||||||
| 
 | 
 | ||||||
| import com.google.common.annotations.VisibleForTesting; | import com.google.common.annotations.VisibleForTesting; | ||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; | import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; | ||||||
|  | import com.imaginarycode.minecraft.redisbungee.api.AbstractDataManager; | ||||||
| import redis.clients.jedis.Jedis; | import redis.clients.jedis.Jedis; | ||||||
| import redis.clients.jedis.JedisCluster; | import redis.clients.jedis.JedisCluster; | ||||||
| import redis.clients.jedis.Pipeline; | import redis.clients.jedis.Pipeline; | ||||||
| @ -43,19 +44,19 @@ public class RedisUtil { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static boolean isRedisVersionRight(String redisVersion) { |     public static boolean isRedisVersionRight(String redisVersion) { | ||||||
|         // Need to use >=6.2 to use Lua optimizations. |  | ||||||
|         String[] args = redisVersion.split("\\."); |         String[] args = redisVersion.split("\\."); | ||||||
|         if (args.length < 2) { |         if (args.length < 2) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|         int major = Integer.parseInt(args[0]); |         int major = Integer.parseInt(args[0]); | ||||||
|         int minor = Integer.parseInt(args[1]); |         int minor = Integer.parseInt(args[1]); | ||||||
|         return major >= 6 && minor >= 0; |         return major >= 3 && minor >= 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Ham1255: i am keeping this if some plugin uses this *IF* |     // Ham1255: i am keeping this if some plugin uses this *IF* | ||||||
|     @Deprecated |     @Deprecated | ||||||
|     public static boolean canUseLua(String redisVersion) { |     public static boolean canUseLua(String redisVersion) { | ||||||
|  |         // Need to use >=3 to use Lua optimizations. | ||||||
|         return isRedisVersionRight(redisVersion); |         return isRedisVersionRight(redisVersion); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -1,4 +1,4 @@ | |||||||
| package com.imaginarycode.minecraft.redisbungee.api.util; | package com.imaginarycode.minecraft.redisbungee.api.util.io; | ||||||
| 
 | 
 | ||||||
| import com.google.common.io.ByteStreams; | import com.google.common.io.ByteStreams; | ||||||
| 
 | 
 | ||||||
| @ -1,6 +1,7 @@ | |||||||
| package com.imaginarycode.minecraft.redisbungee.api.util; | package com.imaginarycode.minecraft.redisbungee.api.util.lua; | ||||||
| 
 | 
 | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; | import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; | ||||||
|  | import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask; | ||||||
| import redis.clients.jedis.Jedis; | import redis.clients.jedis.Jedis; | ||||||
| import redis.clients.jedis.JedisCluster; | import redis.clients.jedis.JedisCluster; | ||||||
| import redis.clients.jedis.exceptions.JedisDataException; | import redis.clients.jedis.exceptions.JedisDataException; | ||||||
| @ -19,7 +20,7 @@ public class LuaManager { | |||||||
|     public Script createScript(String script) { |     public Script createScript(String script) { | ||||||
|         RedisTask<Script> scriptRedisTask = new RedisTask<Script>(plugin.getApi()) { |         RedisTask<Script> scriptRedisTask = new RedisTask<Script>(plugin.getApi()) { | ||||||
|             @Override |             @Override | ||||||
|             public Script singleJedisTask(Jedis jedis) { |             public Script jedisTask(Jedis jedis) { | ||||||
|                 String hash = jedis.scriptLoad(script); |                 String hash = jedis.scriptLoad(script); | ||||||
|                 return new Script(script, hash); |                 return new Script(script, hash); | ||||||
|             } |             } | ||||||
| @ -53,7 +54,7 @@ public class LuaManager { | |||||||
|         public Object eval(List<String> keys, List<String> args) { |         public Object eval(List<String> keys, List<String> args) { | ||||||
|             RedisTask<Object> objectRedisTask = new RedisTask<Object>(plugin.getApi()) { |             RedisTask<Object> objectRedisTask = new RedisTask<Object>(plugin.getApi()) { | ||||||
|                 @Override |                 @Override | ||||||
|                 public Object singleJedisTask(Jedis jedis) { |                 public Object jedisTask(Jedis jedis) { | ||||||
|                     Object data; |                     Object data; | ||||||
|                     try { |                     try { | ||||||
|                         data = jedis.evalsha(hashed, keys, args); |                         data = jedis.evalsha(hashed, keys, args); | ||||||
| @ -6,7 +6,7 @@ import com.google.common.collect.Iterables; | |||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; | import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin; | ||||||
| 
 | 
 | ||||||
| import com.imaginarycode.minecraft.redisbungee.api.util.RedisTask; | import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask; | ||||||
| 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.JedisCluster; | import redis.clients.jedis.JedisCluster; | ||||||
| @ -74,7 +74,7 @@ public final class UUIDTranslator { | |||||||
|         } |         } | ||||||
|         RedisTask<UUID> redisTask = new RedisTask<UUID>(plugin.getApi()) { |         RedisTask<UUID> redisTask = new RedisTask<UUID>(plugin.getApi()) { | ||||||
|             @Override |             @Override | ||||||
|             public UUID singleJedisTask(Jedis jedis) { |             public UUID jedisTask(Jedis jedis) { | ||||||
|                 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. | ||||||
| @ -178,7 +178,7 @@ public final class UUIDTranslator { | |||||||
| 
 | 
 | ||||||
|         RedisTask<String> redisTask = new RedisTask<String>(plugin.getApi()) { |         RedisTask<String> redisTask = new RedisTask<String>(plugin.getApi()) { | ||||||
|             @Override |             @Override | ||||||
|             public String singleJedisTask(Jedis jedis) { |             public String jedisTask(Jedis jedis) { | ||||||
|                 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. | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user