mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2025-04-20 01:27:07 +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 net.md_5.bungee.config.YamlConfiguration;
|
||||||
import redis.clients.jedis.*;
|
import redis.clients.jedis.*;
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
import redis.clients.jedis.util.Pool;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -51,7 +52,7 @@ public final class RedisBungee extends Plugin {
|
|||||||
private PubSubListener psl = null;
|
private PubSubListener psl = null;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private JedisPool pool;
|
private Pool<Jedis> pool;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private UUIDTranslator uuidTranslator;
|
private UUIDTranslator uuidTranslator;
|
||||||
@ -422,10 +423,23 @@ public final class RedisBungee extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
final Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||||
|
|
||||||
final String redisServer = configuration.getString("redis-server", "localhost");
|
final String redisServer = configuration.getString("redis-server", "localhost");
|
||||||
final int redisPort = configuration.getInt("redis-port", 6379);
|
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 redisPassword = configuration.getString("redis-password");
|
||||||
String serverId = configuration.getString("server-id");
|
String serverId = configuration.getString("server-id");
|
||||||
final String randomUUID = UUID.randomUUID().toString();
|
final String randomUUID = UUID.randomUUID().toString();
|
||||||
@ -433,6 +447,13 @@ public final class RedisBungee extends Plugin {
|
|||||||
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
||||||
redisPassword = null;
|
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.
|
// Configuration sanity checks.
|
||||||
if (serverId == null || serverId.isEmpty()) {
|
if (serverId == null || serverId.isEmpty()) {
|
||||||
@ -452,12 +473,20 @@ public final class RedisBungee extends Plugin {
|
|||||||
|
|
||||||
if (redisServer != null && !redisServer.isEmpty()) {
|
if (redisServer != null && !redisServer.isEmpty()) {
|
||||||
final String finalRedisPassword = redisPassword;
|
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
|
@Override
|
||||||
public JedisPool call() throws Exception {
|
public Pool<Jedis> call() throws Exception {
|
||||||
// Create the pool...
|
// Create the pool...
|
||||||
JedisPoolConfig config = new JedisPoolConfig();
|
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);
|
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 com.google.common.net.InetAddresses;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.md_5.bungee.config.Configuration;
|
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.net.InetAddress;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class RedisBungeeConfiguration {
|
public class RedisBungeeConfiguration {
|
||||||
@Getter
|
@Getter
|
||||||
private final JedisPool pool;
|
private final Pool<Jedis> pool;
|
||||||
@Getter
|
@Getter
|
||||||
private final String serverId;
|
private final String serverId;
|
||||||
@Getter
|
@Getter
|
||||||
@ -21,7 +21,7 @@ public class RedisBungeeConfiguration {
|
|||||||
private final List<InetAddress> exemptAddresses;
|
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;
|
this.pool = pool;
|
||||||
if (configuration.getBoolean("use-random-id-string", false)) {
|
if (configuration.getBoolean("use-random-id-string", false)) {
|
||||||
this.serverId = configuration.getString("server-id") + "-" + randomUUID;
|
this.serverId = configuration.getString("server-id") + "-" + randomUUID;
|
||||||
|
@ -6,33 +6,49 @@
|
|||||||
redis-server: 127.0.0.1
|
redis-server: 127.0.0.1
|
||||||
redis-port: 6379
|
redis-port: 6379
|
||||||
|
|
||||||
#################################################################
|
# OPTIONAL: If your Redis server or sentinel(s) uses AUTH, set the password required.
|
||||||
# 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.
|
|
||||||
# WARNING: Leaving your Redis server or sentinel exposed without a password is extremely unsafe
|
# 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.
|
# and could cause issues like data not being sync and etc.
|
||||||
redis-password: ""
|
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.
|
# 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
|
# The default is 10. This setting should be left as-is unless you have some wildly
|
||||||
# inefficient plugins or a lot of players.
|
# inefficient plugins or a lot of players.
|
||||||
max-redis-connections: 10
|
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.
|
# An identifier for this BungeeCord instance. Will randomly generate a UUID String if leaving it blank.
|
||||||
server-id: "test1"
|
server-id: "test1"
|
||||||
|
Loading…
Reference in New Issue
Block a user