mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 14:38:53 +00:00
feat: add more config options for Redis (#889)
* feat: added config options for Redis database and timeout * fix: add a comment to the database entry * style: use the same code style everywhere
This commit is contained in:
1 parent
af08134900
commit
669ae49417
2 files changed
+25
-5
No files matched your search
@@ -31,6 +31,7 @@ import net.william278.huskhomes.network.Broker;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.util.TransactionResolver;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import redis.clients.jedis.Protocol;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -283,8 +284,12 @@ public final class Settings {
|
||||
public static class RedisSettings {
|
||||
private String host = "localhost";
|
||||
private int port = 6379;
|
||||
@Comment("Only change this if you know what you are doing. The default value is 0.")
|
||||
private int database = 0;
|
||||
@Comment("Password for your Redis server. Leave blank if you're not using a password.")
|
||||
private String password = "";
|
||||
@Comment("Timeout for connecting to the Redis server (in milliseconds)")
|
||||
private int timeout = Protocol.DEFAULT_TIMEOUT;
|
||||
private boolean useSsl = false;
|
||||
|
||||
@Comment({"Settings for if you're using Redis Sentinels.",
|
||||
|
||||
@@ -75,6 +75,8 @@ public class RedisBroker extends PluginMessageBroker {
|
||||
final String password = settings.getPassword();
|
||||
final String host = settings.getHost();
|
||||
final int port = settings.getPort();
|
||||
final int database = settings.getDatabase();
|
||||
final int timeout = settings.getTimeout();
|
||||
final boolean useSSL = settings.isUseSsl();
|
||||
|
||||
// Create the jedis pool
|
||||
@@ -88,14 +90,27 @@ public class RedisBroker extends PluginMessageBroker {
|
||||
Set<String> redisSentinelNodes = new HashSet<>(sentinel.getNodes());
|
||||
if (!redisSentinelNodes.isEmpty()) {
|
||||
final String sentinelPassword = sentinel.getPassword();
|
||||
return new JedisSentinelPool(sentinel.getMasterName(), redisSentinelNodes, password.isEmpty()
|
||||
? null : password, sentinelPassword.isEmpty() ? null : sentinelPassword);
|
||||
return new JedisSentinelPool(
|
||||
sentinel.getMasterName(),
|
||||
redisSentinelNodes,
|
||||
config,
|
||||
timeout,
|
||||
password.isEmpty() ? null : password,
|
||||
sentinelPassword.isEmpty() ? null : sentinelPassword,
|
||||
database
|
||||
);
|
||||
}
|
||||
|
||||
// Otherwise, use the standard Jedis pool
|
||||
return password.isEmpty()
|
||||
? new JedisPool(config, host, port, 0, useSSL)
|
||||
: new JedisPool(config, host, port, 0, password, useSSL);
|
||||
return new JedisPool(
|
||||
config,
|
||||
host,
|
||||
port,
|
||||
timeout,
|
||||
password.isEmpty() ? null : password,
|
||||
database,
|
||||
useSSL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user