Authenticate when creating the RedisPool

This commit is contained in:
William committed 2022-01-20 18:17:37 +00:00
1 parent d3b0f38b46
commit 83cd61689a
2 files changed
+13 -11

No files matched your search

@@ -26,12 +26,9 @@ public class RedisMessage extends Message {
private void dispatchRedisMessage(String target) { private void dispatchRedisMessage(String target) {
Bukkit.getScheduler().runTask(plugin, () -> { Bukkit.getScheduler().runTask(plugin, () -> {
try (Jedis publisher = RedisReceiver.getJedis()) { try (Jedis publisher = RedisReceiver.getJedis()) {
final String jedisPassword = HuskHomes.getSettings().getRedisPassword(); publisher.publish(RedisReceiver.REDIS_CHANNEL,
if (!jedisPassword.equals("")) { getClusterId() + ":" + getPluginMessageString(getMessageType()) + ":"
publisher.auth(jedisPassword); + target + REDIS_MESSAGE_HEADER_SEPARATOR + getMessageData());
}
publisher.connect();
publisher.publish(RedisReceiver.REDIS_CHANNEL, getClusterId() + ":" + getPluginMessageString(getMessageType()) + ":" + target + REDIS_MESSAGE_HEADER_SEPARATOR + getMessageData());
} }
}); });
} }
@@ -23,9 +23,18 @@ public class RedisReceiver {
// Initialize a JedisPool that can be drawn from on demand // Initialize a JedisPool that can be drawn from on demand
public static void initialize() { public static void initialize() {
if (HuskHomes.getSettings().getRedisPassword().isEmpty()) {
jedisPool = new JedisPool(new JedisPoolConfig(), jedisPool = new JedisPool(new JedisPoolConfig(),
HuskHomes.getSettings().getRedisHost(), HuskHomes.getSettings().getRedisHost(),
HuskHomes.getSettings().getRedisPort()); HuskHomes.getSettings().getRedisPort(),
0);
} else {
jedisPool = new JedisPool(new JedisPoolConfig(),
HuskHomes.getSettings().getRedisHost(),
HuskHomes.getSettings().getRedisPort(),
0,
HuskHomes.getSettings().getRedisPassword());
}
} }
// Close the connection // Close the connection
@@ -47,12 +56,8 @@ public class RedisReceiver {
} }
public static void listen() { public static void listen() {
final String jedisPassword = HuskHomes.getSettings().getRedisPassword();
new Thread(() -> { new Thread(() -> {
try (Jedis jedis = getJedis()) { try (Jedis jedis = getJedis()) {
if (!jedisPassword.equals("")) {
jedis.auth(jedisPassword);
}
jedis.subscribe(new JedisPubSub() { jedis.subscribe(new JedisPubSub() {
@Override @Override
public void onMessage(String channel, String message) { public void onMessage(String channel, String message) {