mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 22:16:22 +00:00
Update to Jedis 4.0.1; Use Jedis pooling; Close #122
This commit is contained in:
1 parent
be6ec03e52
commit
8fb3ab8c52
4 files changed
+20
-3
No files matched your search
@@ -186,7 +186,7 @@
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.7.1</version>
|
||||
<version>4.0.1</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -127,6 +127,7 @@ public final class HuskHomes extends JavaPlugin {
|
||||
if (getSettings().getMessengerType().equalsIgnoreCase("pluginmessage")) {
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new PluginMessageReceiver());
|
||||
} else {
|
||||
RedisReceiver.initialize();
|
||||
RedisReceiver.listen();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class RedisMessage extends Message {
|
||||
|
||||
private void dispatchRedisMessage(String target) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
try (Jedis publisher = new Jedis(HuskHomes.getSettings().getRedisHost(), HuskHomes.getSettings().getRedisPort())) {
|
||||
try (Jedis publisher = RedisReceiver.getJedis()) {
|
||||
final String jedisPassword = HuskHomes.getSettings().getRedisPassword();
|
||||
if (!jedisPassword.equals("")) {
|
||||
publisher.auth(jedisPassword);
|
||||
|
||||
@@ -5,6 +5,8 @@ import me.william278.huskhomes2.data.message.CrossServerMessageHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -12,6 +14,19 @@ import java.util.Collections;
|
||||
|
||||
public class RedisReceiver {
|
||||
|
||||
private static JedisPool jedisPool;
|
||||
|
||||
public static Jedis getJedis() {
|
||||
return jedisPool.getResource();
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
jedisPool = new JedisPool(new JedisPoolConfig(),
|
||||
HuskHomes.getSettings().getRedisHost(),
|
||||
HuskHomes.getSettings().getRedisPort());
|
||||
}
|
||||
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
public static final String REDIS_CHANNEL = "HuskHomes";
|
||||
|
||||
@@ -25,8 +40,8 @@ public class RedisReceiver {
|
||||
}
|
||||
|
||||
public static void listen() {
|
||||
Jedis jedis = new Jedis(HuskHomes.getSettings().getRedisHost(), HuskHomes.getSettings().getRedisPort());
|
||||
final String jedisPassword = HuskHomes.getSettings().getRedisPassword();
|
||||
try (Jedis jedis = getJedis()) {
|
||||
if (!jedisPassword.equals("")) {
|
||||
jedis.auth(jedisPassword);
|
||||
}
|
||||
@@ -93,4 +108,5 @@ public class RedisReceiver {
|
||||
plugin.getLogger().severe("Failed to initialize the redis listener!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user