diff --git a/common/src/main/java/net/william278/huskhomes/config/Settings.java b/common/src/main/java/net/william278/huskhomes/config/Settings.java index 4858801c..d7307b26 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Settings.java +++ b/common/src/main/java/net/william278/huskhomes/config/Settings.java @@ -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.", diff --git a/common/src/main/java/net/william278/huskhomes/network/RedisBroker.java b/common/src/main/java/net/william278/huskhomes/network/RedisBroker.java index 7ee99983..c28364a7 100644 --- a/common/src/main/java/net/william278/huskhomes/network/RedisBroker.java +++ b/common/src/main/java/net/william278/huskhomes/network/RedisBroker.java @@ -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 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