mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2025-04-18 16:47:06 +00:00
Added sentinel support UNTESTED
This commit is contained in:
parent
70451123a5
commit
1eba10b8d6
@ -24,6 +24,7 @@ import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import redis.clients.jedis.*;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.util.Pool;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
@ -51,7 +52,7 @@ public final class RedisBungee extends Plugin {
|
||||
private PubSubListener psl = null;
|
||||
|
||||
@Getter
|
||||
private JedisPool pool;
|
||||
private Pool<Jedis> pool;
|
||||
|
||||
@Getter
|
||||
private UUIDTranslator uuidTranslator;
|
||||
@ -422,10 +423,23 @@ public final class RedisBungee extends Plugin {
|
||||
}
|
||||
|
||||
final Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||
|
||||
final String redisServer = configuration.getString("redis-server", "localhost");
|
||||
final int redisPort = configuration.getInt("redis-port", 6379);
|
||||
final boolean useSSL = configuration.getBoolean("useSSL");
|
||||
final boolean useSSL = configuration.getBoolean("useSSL", false);
|
||||
|
||||
final boolean useSentinel = configuration.getBoolean("use-sentinel", false);
|
||||
|
||||
final Set<HostAndPort> sentinels = new HashSet<>();
|
||||
configuration.getList("sentinels").forEach(obj -> {
|
||||
String[] co = ((String)obj).split(":");
|
||||
sentinels.add(new HostAndPort(co[0],Integer.parseInt(co[1])));
|
||||
});
|
||||
final boolean useSSLSentinels = configuration.getBoolean("use-SSL-sentinels", false);
|
||||
String redisSentinelPassword = configuration.getString("sentinel-password", "none");
|
||||
final String masterName = configuration.getString("master-name");
|
||||
String redisMasterPassword = configuration.getString("master-password", "none");
|
||||
|
||||
|
||||
String redisPassword = configuration.getString("redis-password");
|
||||
String serverId = configuration.getString("server-id");
|
||||
final String randomUUID = UUID.randomUUID().toString();
|
||||
@ -433,6 +447,13 @@ public final class RedisBungee extends Plugin {
|
||||
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
||||
redisPassword = null;
|
||||
}
|
||||
if (redisMasterPassword != null && (redisMasterPassword.isEmpty() || redisMasterPassword.equals("none"))) {
|
||||
redisMasterPassword = null;
|
||||
}
|
||||
|
||||
if (redisSentinelPassword != null && (redisSentinelPassword.isEmpty() || redisSentinelPassword.equals("none"))) {
|
||||
redisSentinelPassword = null;
|
||||
}
|
||||
|
||||
// Configuration sanity checks.
|
||||
if (serverId == null || serverId.isEmpty()) {
|
||||
@ -452,12 +473,20 @@ public final class RedisBungee extends Plugin {
|
||||
|
||||
if (redisServer != null && !redisServer.isEmpty()) {
|
||||
final String finalRedisPassword = redisPassword;
|
||||
FutureTask<JedisPool> task = new FutureTask<>(new Callable<JedisPool>() {
|
||||
String finalRedisMasterPassword = redisMasterPassword;
|
||||
String finalRedisSentinelPassword = redisSentinelPassword;
|
||||
FutureTask<Pool<Jedis>> task = new FutureTask<>(new Callable<Pool<Jedis>>() {
|
||||
@Override
|
||||
public JedisPool call() throws Exception {
|
||||
public Pool<Jedis> call() throws Exception {
|
||||
// Create the pool...
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setMaxTotal(configuration.getInt("max-redis-connections", 8));
|
||||
config.setMaxTotal(configuration.getInt("max-redis-connections", 10));
|
||||
if (useSentinel) {
|
||||
JedisClientConfig masteClientConfig = DefaultJedisClientConfig.builder().password(finalRedisMasterPassword).ssl(useSSL).build();
|
||||
JedisClientConfig sentinelClientConfig = DefaultJedisClientConfig.builder().ssl(useSSLSentinels).password(finalRedisSentinelPassword).build();
|
||||
return new JedisSentinelPool(masterName, sentinels, config, masteClientConfig, sentinelClientConfig);
|
||||
}
|
||||
|
||||
return new JedisPool(config, redisServer, redisPort, 0, finalRedisPassword, useSSL);
|
||||
}
|
||||
});
|
||||
|
@ -4,15 +4,15 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.util.Pool;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RedisBungeeConfiguration {
|
||||
@Getter
|
||||
private final JedisPool pool;
|
||||
private final Pool<Jedis> pool;
|
||||
@Getter
|
||||
private final String serverId;
|
||||
@Getter
|
||||
@ -21,7 +21,7 @@ public class RedisBungeeConfiguration {
|
||||
private final List<InetAddress> exemptAddresses;
|
||||
|
||||
|
||||
public RedisBungeeConfiguration(JedisPool pool, Configuration configuration, String randomUUID) {
|
||||
public RedisBungeeConfiguration(Pool<Jedis> pool, Configuration configuration, String randomUUID) {
|
||||
this.pool = pool;
|
||||
if (configuration.getBoolean("use-random-id-string", false)) {
|
||||
this.serverId = configuration.getString("server-id") + "-" + randomUUID;
|
||||
|
@ -6,33 +6,49 @@
|
||||
redis-server: 127.0.0.1
|
||||
redis-port: 6379
|
||||
|
||||
#################################################################
|
||||
# If enabled redis-server and redis-port will be ignored.
|
||||
use-sentinel: false
|
||||
|
||||
sentinels:
|
||||
- "127.0.0.1:6379"
|
||||
- "127.0.0.1:6378"
|
||||
- "127.0.0.1:6377"
|
||||
|
||||
# Your master name
|
||||
master-name: mymaster
|
||||
|
||||
##################################################################
|
||||
|
||||
# OPTIONAL: If your Redis server or sentinel uses AUTH, set the password required.
|
||||
# OPTIONAL: If your Redis server or sentinel(s) uses AUTH, set the password required.
|
||||
# WARNING: Leaving your Redis server or sentinel exposed without a password is extremely unsafe
|
||||
# and could cause issues like data not being sync and etc.
|
||||
redis-password: ""
|
||||
|
||||
# since redis can support ssl by version 6 you can use ssl in redis bungee too!
|
||||
# its' recommended to use redis with ssl to encrypt the traffic.
|
||||
useSSL: false
|
||||
|
||||
#################################################################
|
||||
# REDIS SENTINEL
|
||||
# WARNING: THIS BETA AND NOT TESTED REPORT ANY ISSUES at issues pages in
|
||||
|
||||
# If enabled config options redis-server, redis-port and redis-password will be ignored.
|
||||
use-sentinel: false
|
||||
|
||||
# you can have many sentinels as you want as long its like this format
|
||||
# sentinels:
|
||||
# - "<ip-address>:<port>"
|
||||
# - .....
|
||||
#
|
||||
sentinels:
|
||||
- "127.0.0.1:26379"
|
||||
- "127.0.0.1:26378"
|
||||
- "127.0.0.1:26377"
|
||||
|
||||
# enables ssl for sentinels connections.
|
||||
use-SSL-sentinels: false
|
||||
# to enable ssl for master and salve just set useSSL: true
|
||||
|
||||
# Sentinel password
|
||||
sentinel-password: ""
|
||||
|
||||
# Your master name
|
||||
master-name: mymaster
|
||||
master-password: ""
|
||||
##################################################################
|
||||
|
||||
# Maximum connections that will be maintained to the Redis server.
|
||||
# The default is 10. This setting should be left as-is unless you have some wildly
|
||||
# inefficient plugins or a lot of players.
|
||||
max-redis-connections: 10
|
||||
|
||||
# since redis can support ssl by version 6 you can use ssl in redis bungee too!
|
||||
# its' recommended to use redis with ssl to encrypt the traffic.
|
||||
useSSL: false
|
||||
|
||||
# An identifier for this BungeeCord instance. Will randomly generate a UUID String if leaving it blank.
|
||||
server-id: "test1"
|
||||
|
Loading…
Reference in New Issue
Block a user