From 5f074d347228a31d6af7b5fc54419251d66e104f Mon Sep 17 00:00:00 2001 From: mohammed jasem alaajel <34905970+ham1255@users.noreply.github.com> Date: Fri, 23 Oct 2020 20:37:43 +0400 Subject: [PATCH] fixed reload but not tested --- .../java/net/limework/core/RediSkript.java | 8 ++----- .../limework/core/managers/RedisManager.java | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/limework/core/RediSkript.java b/src/main/java/net/limework/core/RediSkript.java index 7c04f51..c25dc64 100644 --- a/src/main/java/net/limework/core/RediSkript.java +++ b/src/main/java/net/limework/core/RediSkript.java @@ -10,16 +10,12 @@ public class RediSkript extends JavaPlugin { //Redis manager private RedisManager rm; - public void startRedis(boolean reload) { - if (reload) { reloadConfig(); } - rm = new RedisManager(this); - rm.start(); - } @Override public void onEnable() { saveDefaultConfig(); if (getServer().getPluginManager().getPlugin("Skript") != null) { - startRedis(false); + rm = new RedisManager(this); + rm.start(); PluginCommand command = getServer().getPluginCommand("reloadredis"); assert command != null; diff --git a/src/main/java/net/limework/core/managers/RedisManager.java b/src/main/java/net/limework/core/managers/RedisManager.java index 39a95d8..67b7257 100644 --- a/src/main/java/net/limework/core/managers/RedisManager.java +++ b/src/main/java/net/limework/core/managers/RedisManager.java @@ -149,8 +149,28 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable { } public void reload() { - this.shutdown(); - plugin.startRedis(true); + plugin.reloadConfig(); + subscribeJedis.close(); + Configuration config = this.plugin.getConfig(); + JedisPoolConfig JConfig = new JedisPoolConfig(); + JConfig.setMaxTotal(config.getInt("Redis.MaxConnections")); + JConfig.setMaxIdle(config.getInt("Redis.MaxConnections")); + JConfig.setMinIdle(1); + JConfig.setBlockWhenExhausted(true); + this.jedisPool = new JedisPool(JConfig, + config.getString("Redis.Host"), + config.getInt("Redis.Port"), + config.getInt("Redis.TimeOut"), + config.getString("Redis.Password"), + config.getBoolean("Redis.useSSL")); + RedisService.shutdownNow(); + RedisService = Executors.newFixedThreadPool(config.getInt("Redis.Threads")); + try { + this.subscribeJedis = this.jedisPool.getResource(); + } catch (Exception ignored) { + } + this.channels = config.getStringList("Channels"); + encryption = new Encryption(config); } public JedisPool getJedisPool() {