mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +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.position.World;
|
||||||
import net.william278.huskhomes.util.TransactionResolver;
|
import net.william278.huskhomes.util.TransactionResolver;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -283,8 +284,12 @@ public final class Settings {
|
|||||||
public static class RedisSettings {
|
public static class RedisSettings {
|
||||||
private String host = "localhost";
|
private String host = "localhost";
|
||||||
private int port = 6379;
|
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.")
|
@Comment("Password for your Redis server. Leave blank if you're not using a password.")
|
||||||
private String password = "";
|
private String password = "";
|
||||||
|
@Comment("Timeout for connecting to the Redis server (in milliseconds)")
|
||||||
|
private int timeout = Protocol.DEFAULT_TIMEOUT;
|
||||||
private boolean useSsl = false;
|
private boolean useSsl = false;
|
||||||
|
|
||||||
@Comment({"Settings for if you're using Redis Sentinels.",
|
@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 password = settings.getPassword();
|
||||||
final String host = settings.getHost();
|
final String host = settings.getHost();
|
||||||
final int port = settings.getPort();
|
final int port = settings.getPort();
|
||||||
|
final int database = settings.getDatabase();
|
||||||
|
final int timeout = settings.getTimeout();
|
||||||
final boolean useSSL = settings.isUseSsl();
|
final boolean useSSL = settings.isUseSsl();
|
||||||
|
|
||||||
// Create the jedis pool
|
// Create the jedis pool
|
||||||
@@ -88,14 +90,27 @@ public class RedisBroker extends PluginMessageBroker {
|
|||||||
Set<String> redisSentinelNodes = new HashSet<>(sentinel.getNodes());
|
Set<String> redisSentinelNodes = new HashSet<>(sentinel.getNodes());
|
||||||
if (!redisSentinelNodes.isEmpty()) {
|
if (!redisSentinelNodes.isEmpty()) {
|
||||||
final String sentinelPassword = sentinel.getPassword();
|
final String sentinelPassword = sentinel.getPassword();
|
||||||
return new JedisSentinelPool(sentinel.getMasterName(), redisSentinelNodes, password.isEmpty()
|
return new JedisSentinelPool(
|
||||||
? null : password, sentinelPassword.isEmpty() ? null : sentinelPassword);
|
sentinel.getMasterName(),
|
||||||
|
redisSentinelNodes,
|
||||||
|
config,
|
||||||
|
timeout,
|
||||||
|
password.isEmpty() ? null : password,
|
||||||
|
sentinelPassword.isEmpty() ? null : sentinelPassword,
|
||||||
|
database
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, use the standard Jedis pool
|
// Otherwise, use the standard Jedis pool
|
||||||
return password.isEmpty()
|
return new JedisPool(
|
||||||
? new JedisPool(config, host, port, 0, useSSL)
|
config,
|
||||||
: new JedisPool(config, host, port, 0, password, useSSL);
|
host,
|
||||||
|
port,
|
||||||
|
timeout,
|
||||||
|
password.isEmpty() ? null : password,
|
||||||
|
database,
|
||||||
|
useSSL
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user