RedisMessenger support for SSL (#2263)

This commit is contained in:
Luck 2020-05-05 17:38:24 +01:00
parent 308356de80
commit 045c10048d
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 24 additions and 12 deletions

View File

@ -36,7 +36,7 @@ dependencies {
exclude(module: 'toml4j')
}
compile 'com.zaxxer:HikariCP:3.4.2'
compile 'redis.clients:jedis:3.2.0'
compile 'redis.clients:jedis:3.3.0'
compile 'org.mongodb:mongo-java-driver:3.12.2'
compile 'org.yaml:snakeyaml:1.23'
}

View File

@ -540,10 +540,15 @@ public final class ConfigKeys {
public static final ConfigKey<String> REDIS_ADDRESS = enduringKey(stringKey("redis.address", null));
/**
* The password in use by the redis server, or an empty string if there is no passworld
* The password in use by the redis server, or an empty string if there is no password
*/
public static final ConfigKey<String> REDIS_PASSWORD = enduringKey(stringKey("redis.password", ""));
/**
* If the redis connection should use SSL
*/
public static final ConfigKey<Boolean> REDIS_SSL = enduringKey(booleanKey("redis.ssl", false));
/**
* The URL of the bytebin instance used to upload data
*/

View File

@ -210,8 +210,8 @@ public enum Dependency {
JEDIS(
"redis.clients",
"jedis",
"3.2.0",
"+S7KUSPPUC9xDj10tANcMLC3EtPxqxv8JJiaDClgQwc=",
"3.3.0",
"HuTfz9xW/mi1fwVQ3xgPmd6qwTRMF/3fyMzw2LmOgy4=",
Relocation.of("jedis", "redis{}clients{}jedis"),
Relocation.of("commonspool2", "org{}apache{}commons{}pool2")
),

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.common.messaging;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
import me.lucko.luckperms.common.messaging.redis.RedisMessenger;
import me.lucko.luckperms.common.messaging.sql.SqlMessenger;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -121,7 +122,16 @@ public class MessagingFactory<P extends LuckPermsPlugin> {
@Override
public @NonNull Messenger obtain(@NonNull IncomingMessageConsumer incomingMessageConsumer) {
RedisMessenger redis = new RedisMessenger(getPlugin(), incomingMessageConsumer);
redis.init(getPlugin().getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getPlugin().getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
LuckPermsConfiguration config = getPlugin().getConfiguration();
String address = config.get(ConfigKeys.REDIS_ADDRESS);
String password = config.get(ConfigKeys.REDIS_PASSWORD);
if (password.isEmpty()) {
password = null;
}
boolean ssl = config.get(ConfigKeys.REDIS_SSL);
redis.init(address, password, ssl);
return redis;
}
}

View File

@ -37,6 +37,7 @@ import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisPubSub;
import redis.clients.jedis.Protocol;
/**
* An implementation of {@link Messenger} using Redis.
@ -55,16 +56,12 @@ public class RedisMessenger implements Messenger {
this.consumer = consumer;
}
public void init(String address, String password) {
public void init(String address, String password, boolean ssl) {
String[] addressSplit = address.split(":");
String host = addressSplit[0];
int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : 6379;
int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : Protocol.DEFAULT_PORT;
if (password.equals("")) {
this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port);
} else {
this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port, 0, password);
}
this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, password, ssl);
this.plugin.getBootstrap().getScheduler().executeAsync(() -> {
this.sub = new Subscription(this);